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

ManagerVariantDialog migrate to view binding

This commit is contained in:
HaliksaR 2020-11-16 00:24:19 +07:00
parent 874b5d6f90
commit 7e05a3846f
2 changed files with 70 additions and 69 deletions

View file

@ -2,48 +2,55 @@ 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.topjohnwu.superuser.Shell
import com.vanced.manager.R
import com.vanced.manager.databinding.DialogManagerVariantBinding
import com.vanced.manager.ui.core.BindingBottomSheetDialogFragment
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
class ManagerVariantDialog : BottomSheetDialogFragment() {
class ManagerVariantDialog : BindingBottomSheetDialogFragment<DialogManagerVariantBinding>() {
companion object {
fun newInstance(): ManagerVariantDialog = ManagerVariantDialog().apply {
arguments = Bundle()
}
}
private lateinit var binding: DialogManagerVariantBinding
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_variant, container, false)
return binding.root
) = DialogManagerVariantBinding.inflate(inflater, container, false)
override fun otherSetups() {
bindData()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val variant = prefs.getString("vanced_variant", "nonroot")
view.findViewWithTag<MaterialRadioButton>(variant).isChecked = true
binding.variantSave.setOnClickListener {
val newPref = binding.variantRadiogroup.getCheckedButtonTag()
if (variant != newPref) {
if (newPref == "root" && Shell.rootAccess())
prefs.edit { putString("vanced_variant", "root") }
else
prefs.edit { putString("vanced_variant", "nonroot") }
dismiss()
requireActivity().recreate()
} else {
dismiss()
private fun bindData() {
with(binding) {
val variant = prefs.getString("vanced_variant", "nonroot")
root.findViewWithTag<MaterialRadioButton>(variant).isChecked = true
variantSave.setOnClickListener {
val newPref = variantRadiogroup.getCheckedButtonTag()
if (variant != newPref) {
prefs.edit {
if (newPref == "root" && Shell.rootAccess()) {
putString("vanced_variant", "root")
} else {
putString("vanced_variant", "nonroot")
}
}
dismiss()
requireActivity().recreate()
} else {
dismiss()
}
}
}
}

View file

@ -1,53 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools">
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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/variant"
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/variant" />
<androidx.core.widget.NestedScrollView
<RadioGroup
android:id="@+id/variant_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
tools:ignore="HardcodedText">
<RadioGroup
android:id="@+id/variant_radiogroup"
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="HardcodedText">
android:tag="nonroot"
android:text="nonroot"
android:textSize="18sp"/>
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="nonroot"
android:text="nonroot"
android:textSize="18sp" />
<com.google.android.material.radiobutton.MaterialRadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:tag="root"
android:text="root"
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="root"
android:text="root"
android:textSize="18sp" />
</RadioGroup>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.button.MaterialButton
android:id="@+id/variant_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/variant_save"
android:text="@string/save"
style="@style/BottomDialogButtonStyle"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>