mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-25 20:55:12 +00:00
ManagerAccentColorDialog migrate to view binding
This commit is contained in:
parent
00d3003498
commit
a7545071a1
2 changed files with 86 additions and 85 deletions
|
@ -10,37 +10,45 @@ import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
|||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.DialogInstallationFilesDetectedBinding
|
||||
import com.vanced.manager.databinding.DialogManagerAccentColorBinding
|
||||
import com.vanced.manager.ui.core.BindingBottomSheetDialogFragment
|
||||
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
|
||||
|
||||
class ManagerAccentColorDialog : BottomSheetDialogFragment() {
|
||||
class ManagerAccentColorDialog : BindingBottomSheetDialogFragment<DialogManagerAccentColorBinding>() {
|
||||
|
||||
private lateinit var binding: DialogManagerAccentColorBinding
|
||||
private val prefs by lazy { getDefaultSharedPreferences(requireActivity()) }
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_manager_accent_color, container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val accent = prefs.getString("manager_accent", "Blue")
|
||||
view.findViewWithTag<MaterialRadioButton>(accent).isChecked = true
|
||||
binding.accentSave.setOnClickListener {
|
||||
val newPref = binding.accentRadiogroup.getCheckedButtonTag()
|
||||
if (accent != newPref) {
|
||||
prefs.edit { putString("manager_accent", newPref) }
|
||||
dismiss()
|
||||
requireActivity().recreate()
|
||||
} else {
|
||||
dismiss()
|
||||
}
|
||||
companion object {
|
||||
fun newInstance(): ManagerAccentColorDialog = ManagerAccentColorDialog().apply {
|
||||
arguments = Bundle()
|
||||
}
|
||||
}
|
||||
|
||||
private val prefs by lazy { getDefaultSharedPreferences(requireActivity()) }
|
||||
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
) = DialogManagerAccentColorBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun otherSetups() {
|
||||
bindData()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +1,66 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/BottomDialogCard">
|
||||
|
||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/BottomDialogCard">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<TextView
|
||||
android:text="@string/accent_color"
|
||||
style="@style/BottomDialogCardTitle"/>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
style="@style/BottomDialogCardTitle"
|
||||
android:text="@string/accent_color" />
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<RadioGroup
|
||||
android:id="@+id/accent_radiogroup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/accent_radiogroup"
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Blue"
|
||||
android:text="@string/accent_blue"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Blue"
|
||||
android:text="@string/accent_blue"
|
||||
android:textSize="18sp" />
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Red"
|
||||
android:text="@string/accent_red"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Red"
|
||||
android:text="@string/accent_red"
|
||||
android:textSize="18sp" />
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Green"
|
||||
android:text="@string/accent_green"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Green"
|
||||
android:text="@string/accent_green"
|
||||
android:textSize="18sp" />
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Yellow"
|
||||
android:text="@string/accent_yellow"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Yellow"
|
||||
android:text="@string/accent_yellow"
|
||||
android:textSize="18sp" />
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Purple"
|
||||
android:text="@string/accent_purple"
|
||||
android:textSize="18sp"/>
|
||||
</RadioGroup>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<com.google.android.material.radiobutton.MaterialRadioButton
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:tag="Purple"
|
||||
android:text="@string/accent_purple"
|
||||
android:textSize="18sp" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/accent_save"
|
||||
style="@style/BottomDialogButtonStyle"
|
||||
android:text="@string/save" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</layout>
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/accent_save"
|
||||
android:text="@string/save"
|
||||
style="@style/BottomDialogButtonStyle"/>
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
Loading…
Reference in a new issue