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-10-31 19:45:39 +00:00
|
|
|
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
|
|
|
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.DialogManagerAccentColorBinding
|
|
|
|
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
|
|
|
|
|
2020-11-15 17:13:32 +00:00
|
|
|
class ManagerAccentColorDialog : BindingBottomSheetDialogFragment<DialogManagerAccentColorBinding>() {
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
fun newInstance(): ManagerAccentColorDialog = ManagerAccentColorDialog().apply {
|
|
|
|
arguments = Bundle()
|
|
|
|
}
|
|
|
|
}
|
2020-10-31 19:45:39 +00:00
|
|
|
|
|
|
|
private val prefs by lazy { getDefaultSharedPreferences(requireActivity()) }
|
|
|
|
|
2020-11-15 17:13:32 +00:00
|
|
|
override fun binding(
|
2020-10-31 19:45:39 +00:00
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?
|
2020-11-15 17:13:32 +00:00
|
|
|
) = DialogManagerAccentColorBinding.inflate(inflater, container, false)
|
|
|
|
|
|
|
|
override fun otherSetups() {
|
|
|
|
bindData()
|
2020-10-31 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 17:13:32 +00:00
|
|
|
private fun bindData() {
|
|
|
|
with(binding) {
|
|
|
|
val accent = prefs.getString("manager_accent", "Blue")
|
|
|
|
root.findViewWithTag<MaterialRadioButton>(accent).isChecked = true
|
|
|
|
accentSave.setOnClickListener {
|
|
|
|
val newPref = binding.accentRadiogroup.getCheckedButtonTag()
|
|
|
|
if (accent != newPref) {
|
|
|
|
prefs.edit { putString("manager_accent", newPref) }
|
|
|
|
dismiss()
|
|
|
|
requireActivity().recreate()
|
|
|
|
} else {
|
|
|
|
dismiss()
|
|
|
|
}
|
2020-10-31 19:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|