2020-10-31 19:45:39 +00:00
|
|
|
package com.vanced.manager.ui.dialogs
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewGroup
|
2020-11-05 16:35:49 +00:00
|
|
|
import androidx.core.content.edit
|
2020-11-23 16:00:41 +00:00
|
|
|
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
2020-10-31 19:45:39 +00:00
|
|
|
import com.google.android.material.radiobutton.MaterialRadioButton
|
2020-11-26 15:37:03 +00:00
|
|
|
import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
|
2020-10-31 19:45:39 +00:00
|
|
|
import com.vanced.manager.databinding.DialogManagerThemeBinding
|
2021-01-16 17:00:38 +00:00
|
|
|
import com.vanced.manager.utils.getCheckedButtonTag
|
2020-10-31 19:45:39 +00:00
|
|
|
|
2020-11-15 17:21:34 +00:00
|
|
|
class ManagerThemeDialog : BindingBottomSheetDialogFragment<DialogManagerThemeBinding>() {
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
fun newInstance(): ManagerThemeDialog = ManagerThemeDialog().apply {
|
|
|
|
arguments = Bundle()
|
|
|
|
}
|
|
|
|
}
|
2020-10-31 19:45:39 +00:00
|
|
|
|
|
|
|
private val prefs by lazy { getDefaultSharedPreferences(requireActivity()) }
|
|
|
|
|
2020-11-15 17:21:34 +00:00
|
|
|
override fun binding(
|
2020-10-31 19:45:39 +00:00
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
2020-11-15 17:21:34 +00:00
|
|
|
) = DialogManagerThemeBinding.inflate(inflater, container, false)
|
|
|
|
|
|
|
|
override fun otherSetups() {
|
|
|
|
bindData()
|
2020-10-31 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 17:21:34 +00:00
|
|
|
private fun bindData() {
|
|
|
|
with(binding) {
|
|
|
|
val theme = prefs.getString("manager_theme", "System Default")
|
|
|
|
root.findViewWithTag<MaterialRadioButton>(theme).isChecked = true
|
|
|
|
themeSave.setOnClickListener {
|
|
|
|
val newPref = themeRadiogroup.getCheckedButtonTag()
|
|
|
|
if (theme != newPref) {
|
|
|
|
prefs.edit { putString("manager_theme", newPref) }
|
|
|
|
dismiss()
|
|
|
|
requireActivity().recreate()
|
|
|
|
} else {
|
|
|
|
dismiss()
|
|
|
|
}
|
2020-10-31 19:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|