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,37 +2,41 @@ 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)
private fun bindData() {
with(binding) {
val theme = prefs.getString("manager_theme", "System Default")
view.findViewWithTag<MaterialRadioButton>(theme).isChecked = true
binding.themeSave.setOnClickListener {
val newPref = binding.themeRadiogroup.getCheckedButtonTag()
root.findViewWithTag<MaterialRadioButton>(theme).isChecked = true
themeSave.setOnClickListener {
val newPref = themeRadiogroup.getCheckedButtonTag()
if (theme != newPref) {
prefs.edit { putString("manager_theme", newPref) }
dismiss()
@ -43,3 +47,4 @@ class ManagerThemeDialog : BottomSheetDialogFragment() {
}
}
}
}

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/BottomDialogCard">
<LinearLayout
@ -10,8 +9,8 @@
android:orientation="vertical">
<TextView
style="@style/BottomDialogCardTitle"
android:text="@string/theme" />
android:text="@string/theme"
style="@style/BottomDialogCardTitle"/>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
@ -42,18 +41,12 @@
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" />
android:text="@string/save"
style="@style/BottomDialogButtonStyle"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</layout>