0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-25 20:55:12 +00:00

ManagerThemeDialog migrate to view binding

This commit is contained in:
HaliksaR 2020-11-16 00:21:34 +07:00
parent d929092888
commit 874b5d6f90
2 changed files with 68 additions and 70 deletions

View file

@ -2,43 +2,48 @@ package com.vanced.manager.ui.dialogs
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.edit
import androidx.databinding.DataBindingUtil
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import androidx.preference.PreferenceManager.*
import com.google.android.material.radiobutton.MaterialRadioButton
import com.vanced.manager.R
import com.vanced.manager.databinding.DialogManagerThemeBinding
import com.vanced.manager.ui.core.BindingBottomSheetDialogFragment
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
class ManagerThemeDialog : BottomSheetDialogFragment() {
class ManagerThemeDialog : BindingBottomSheetDialogFragment<DialogManagerThemeBinding>() {
companion object {
fun newInstance(): ManagerThemeDialog = ManagerThemeDialog().apply {
arguments = Bundle()
}
}
private lateinit var binding: DialogManagerThemeBinding
private val prefs by lazy { getDefaultSharedPreferences(requireActivity()) }
override fun onCreateView(
override fun binding(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_manager_theme, container, false)
return binding.root
) = DialogManagerThemeBinding.inflate(inflater, container, false)
override fun otherSetups() {
bindData()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val theme = prefs.getString("manager_theme", "System Default")
view.findViewWithTag<MaterialRadioButton>(theme).isChecked = true
binding.themeSave.setOnClickListener {
val newPref = binding.themeRadiogroup.getCheckedButtonTag()
if (theme != newPref) {
prefs.edit { putString("manager_theme", newPref) }
dismiss()
requireActivity().recreate()
} else {
dismiss()
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()
}
}
}
}

View file

@ -1,59 +1,52 @@
<?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/theme"
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/theme" />
<androidx.core.widget.NestedScrollView
<RadioGroup
android:id="@+id/theme_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioGroup
android:id="@+id/theme_radiogroup"
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:tag="System Default"
android:text="@string/system_default"
android:textSize="18sp"/>
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="System Default"
android:text="@string/system_default"
android:textSize="18sp" />
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="Light"
android:text="@string/theme_light"
android:textSize="18sp"/>
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="Light"
android:text="@string/theme_light"
android:textSize="18sp" />
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="Dark"
android:text="@string/theme_dark"
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="Dark"
android:text="@string/theme_dark"
android:textSize="18sp" />
</RadioGroup>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.button.MaterialButton
android:id="@+id/theme_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/theme_save"
android:text="@string/save"
style="@style/BottomDialogButtonStyle"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>