mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-29 22:43:01 +00:00
AppVersionSelectorDialog and VancedThemeSelectorDialog migrate to view binding
This commit is contained in:
parent
a1d4cdbbe5
commit
a3767e4c9e
5 changed files with 139 additions and 110 deletions
|
@ -2,72 +2,91 @@ package com.vanced.manager.ui.dialogs
|
||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.databinding.DataBindingUtil
|
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
|
||||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.databinding.DialogBottomRadioButtonBinding
|
import com.vanced.manager.databinding.DialogBottomRadioButtonBinding
|
||||||
|
import com.vanced.manager.ui.core.BindingBottomSheetDialogFragment
|
||||||
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
|
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
|
||||||
import com.vanced.manager.utils.Extensions.getDefaultPrefs
|
import com.vanced.manager.utils.Extensions.getDefaultPrefs
|
||||||
import com.vanced.manager.utils.Extensions.show
|
import com.vanced.manager.utils.Extensions.show
|
||||||
|
|
||||||
class AppVersionSelectorDialog(
|
class AppVersionSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomRadioButtonBinding>() {
|
||||||
private val versions: List<String>?,
|
|
||||||
private val app: String
|
|
||||||
) : BottomSheetDialogFragment() {
|
|
||||||
|
|
||||||
private lateinit var binding: DialogBottomRadioButtonBinding
|
|
||||||
private val prefs by lazy { requireActivity().getDefaultPrefs() }
|
private val prefs by lazy { requireActivity().getDefaultPrefs() }
|
||||||
|
|
||||||
override fun onCreateView(
|
companion object {
|
||||||
|
|
||||||
|
private const val TAG_VERSIONS = "TAG_VERSIONS"
|
||||||
|
private const val TAG_APP = "TAG_APP"
|
||||||
|
|
||||||
|
fun newInstance(
|
||||||
|
versions: List<String>?,
|
||||||
|
app: String
|
||||||
|
): AppVersionSelectorDialog = AppVersionSelectorDialog().apply {
|
||||||
|
arguments = Bundle().apply {
|
||||||
|
val arrayList = arrayListOf<String>()
|
||||||
|
versions?.let { arrayList.addAll(it) }
|
||||||
|
putStringArrayList(TAG_VERSIONS, arrayList)
|
||||||
|
putString(TAG_APP, app)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun binding(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
) = DialogBottomRadioButtonBinding.inflate(inflater, container, false)
|
||||||
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_bottom_radio_button, container, false)
|
|
||||||
return binding.root
|
override fun otherSetups() {
|
||||||
|
bindData()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
private fun bindData() {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
with(binding) {
|
||||||
loadBoxes()
|
loadBoxes()?.forEach { mrb ->
|
||||||
val tag = view.findViewWithTag<MaterialRadioButton>(prefs.getString("${app}_version", "latest"))
|
dialogRadiogroup.addView(
|
||||||
|
mrb,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val tag = root.findViewWithTag<MaterialRadioButton>(
|
||||||
|
prefs.getString("${arguments?.getString(TAG_APP)}_version", "latest")
|
||||||
|
)
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
tag.isChecked = true
|
tag.isChecked = true
|
||||||
}
|
}
|
||||||
binding.dialogTitle.text = requireActivity().getString(R.string.version)
|
dialogTitle.text = getString(R.string.version)
|
||||||
binding.dialogSave.setOnClickListener {
|
dialogSave.setOnClickListener {
|
||||||
val checkedTag = binding.dialogRadiogroup.getCheckedButtonTag()
|
val checkedTag = dialogRadiogroup.getCheckedButtonTag()
|
||||||
if (checkedTag != null)
|
if (checkedTag != null) {
|
||||||
prefs.edit { putString("${app}_version", checkedTag) }
|
prefs.edit { putString("${arguments?.getString(TAG_APP)}_version", checkedTag) }
|
||||||
|
}
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadBoxes() {
|
private fun loadBoxes() =
|
||||||
requireActivity().runOnUiThread {
|
arguments?.getStringArrayList(TAG_VERSIONS)?.map { version ->
|
||||||
versions?.forEach { version ->
|
MaterialRadioButton(requireActivity()).apply {
|
||||||
val rb = MaterialRadioButton(requireActivity()).apply {
|
|
||||||
text = version
|
text = version
|
||||||
tag = version
|
tag = version
|
||||||
textSize = 18f
|
textSize = 18f
|
||||||
}
|
}
|
||||||
binding.dialogRadiogroup.addView(rb, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDismiss(dialog: DialogInterface) {
|
override fun onDismiss(dialog: DialogInterface) {
|
||||||
super.onDismiss(dialog)
|
super.onDismiss(dialog)
|
||||||
if (app == "vanced")
|
if (arguments?.getString(TAG_APP) == "vanced") {
|
||||||
VancedPreferencesDialog().show(requireActivity())
|
VancedPreferencesDialog().show(requireActivity())
|
||||||
else
|
} else {
|
||||||
MusicPreferencesDialog().show(requireActivity())
|
MusicPreferencesDialog().show(requireActivity())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -37,7 +37,10 @@ class MusicPreferencesDialog : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
binding.openVersionSelector.setOnClickListener {
|
binding.openVersionSelector.setOnClickListener {
|
||||||
dismiss()
|
dismiss()
|
||||||
AppVersionSelectorDialog(musicVersionsConv, "music").show(requireActivity())
|
AppVersionSelectorDialog.newInstance(
|
||||||
|
versions = musicVersionsConv,
|
||||||
|
app = "music"
|
||||||
|
).show(requireActivity())
|
||||||
}
|
}
|
||||||
binding.musicInstall.setOnClickListener {
|
binding.musicInstall.setOnClickListener {
|
||||||
dismiss()
|
dismiss()
|
||||||
|
|
|
@ -56,7 +56,10 @@ class VancedPreferencesDialog : BottomSheetDialogFragment() {
|
||||||
|
|
||||||
binding.openVersionSelector.setOnClickListener {
|
binding.openVersionSelector.setOnClickListener {
|
||||||
dismiss()
|
dismiss()
|
||||||
AppVersionSelectorDialog(vancedVersionsConv, "vanced").show(requireActivity())
|
AppVersionSelectorDialog.newInstance(
|
||||||
|
versions = vancedVersionsConv,
|
||||||
|
app = "vanced"
|
||||||
|
).show(requireActivity())
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.openLanguageSelector.setOnClickListener {
|
binding.openLanguageSelector.setOnClickListener {
|
||||||
|
|
|
@ -12,57 +12,67 @@ import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
import com.vanced.manager.databinding.DialogBottomRadioButtonBinding
|
import com.vanced.manager.databinding.DialogBottomRadioButtonBinding
|
||||||
|
import com.vanced.manager.ui.core.BindingBottomSheetDialogFragment
|
||||||
import com.vanced.manager.utils.Extensions.convertToAppTheme
|
import com.vanced.manager.utils.Extensions.convertToAppTheme
|
||||||
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
|
import com.vanced.manager.utils.Extensions.getCheckedButtonTag
|
||||||
import com.vanced.manager.utils.Extensions.show
|
import com.vanced.manager.utils.Extensions.show
|
||||||
import com.vanced.manager.utils.InternetTools.vanced
|
import com.vanced.manager.utils.InternetTools.vanced
|
||||||
|
|
||||||
class VancedThemeSelectorDialog : BottomSheetDialogFragment() {
|
class VancedThemeSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomRadioButtonBinding>() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun newInstance(): VancedThemeSelectorDialog = VancedThemeSelectorDialog().apply {
|
||||||
|
arguments = Bundle()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var binding: DialogBottomRadioButtonBinding
|
|
||||||
private val prefs by lazy { requireActivity().getSharedPreferences("installPrefs", Context.MODE_PRIVATE) }
|
private val prefs by lazy { requireActivity().getSharedPreferences("installPrefs", Context.MODE_PRIVATE) }
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun binding(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
) = DialogBottomRadioButtonBinding.inflate(inflater, container, false)
|
||||||
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_bottom_radio_button, container, false)
|
|
||||||
return binding.root
|
override fun otherSetups() {
|
||||||
|
bindData()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
private fun bindData() {
|
||||||
loadButtons()
|
with(binding) {
|
||||||
binding.dialogTitle.text = requireActivity().getString(R.string.theme)
|
loadButtons()?.forEach { mrb ->
|
||||||
val tag = view.findViewWithTag<MaterialRadioButton>(prefs.getString("theme", "dark"))
|
dialogRadiogroup.addView(
|
||||||
|
mrb,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
}
|
||||||
|
dialogTitle.text = requireActivity().getString(R.string.theme)
|
||||||
|
val tag = root.findViewWithTag<MaterialRadioButton>(prefs.getString("theme", "dark"))
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
tag.isChecked = true
|
tag.isChecked = true
|
||||||
}
|
}
|
||||||
binding.dialogSave.setOnClickListener {
|
dialogSave.setOnClickListener {
|
||||||
val checkedTag = binding.dialogRadiogroup.getCheckedButtonTag()
|
val checkedTag = binding.dialogRadiogroup.getCheckedButtonTag()
|
||||||
if (checkedTag != null)
|
if (checkedTag != null) {
|
||||||
prefs.edit { putString("theme", checkedTag) }
|
prefs.edit { putString("theme", checkedTag) }
|
||||||
|
}
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadButtons() {
|
private fun loadButtons() = vanced.get()?.array<String>("themes")?.value?.map {theme ->
|
||||||
requireActivity().runOnUiThread {
|
MaterialRadioButton(requireActivity()).apply {
|
||||||
vanced.get()?.array<String>("themes")?.value?.forEach { theme ->
|
|
||||||
val rb = MaterialRadioButton(requireActivity()).apply {
|
|
||||||
text = theme.convertToAppTheme(requireActivity())
|
text = theme.convertToAppTheme(requireActivity())
|
||||||
tag = theme
|
tag = theme
|
||||||
textSize = 18f
|
textSize = 18f
|
||||||
}
|
}
|
||||||
binding.dialogRadiogroup.addView(rb, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDismiss(dialog: DialogInterface) {
|
override fun onDismiss(dialog: DialogInterface) {
|
||||||
super.onDismiss(dialog)
|
super.onDismiss(dialog)
|
||||||
VancedPreferencesDialog().show(requireActivity())
|
VancedPreferencesDialog().show(requireActivity())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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">
|
style="@style/BottomDialogCard">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -23,16 +22,11 @@
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/dialog_save"
|
android:id="@+id/dialog_save"
|
||||||
style="@style/BottomDialogButtonStyle"
|
android:text="@string/save"
|
||||||
android:text="@string/save" />
|
style="@style/BottomDialogButtonStyle"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
|
|
||||||
</layout>
|
|
Loading…
Reference in a new issue