0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2025-01-05 15:01:01 +00:00

property access syntax goes brrrrr

This commit is contained in:
X1nto 2021-02-28 15:02:01 +04:00
parent 1f600430ea
commit 3525ef88c1
6 changed files with 13 additions and 17 deletions

View file

@ -13,7 +13,7 @@ import com.vanced.manager.databinding.DialogBottomRadioButtonBinding
import com.vanced.manager.ui.core.ThemedMaterialRadioButton import com.vanced.manager.ui.core.ThemedMaterialRadioButton
import com.vanced.manager.utils.defPrefs import com.vanced.manager.utils.defPrefs
import com.vanced.manager.utils.formatVersion import com.vanced.manager.utils.formatVersion
import com.vanced.manager.utils.getCheckedButtonTag import com.vanced.manager.utils.checkedButtonTag
class AppVersionSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomRadioButtonBinding>() { class AppVersionSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomRadioButtonBinding>() {
@ -64,7 +64,7 @@ class AppVersionSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomRa
} }
dialogTitle.text = getString(R.string.version) dialogTitle.text = getString(R.string.version)
dialogSave.setOnClickListener { dialogSave.setOnClickListener {
val checkedTag = dialogRadiogroup.getCheckedButtonTag() val checkedTag = dialogRadiogroup.checkedButtonTag
if (checkedTag != null) { if (checkedTag != null) {
prefs.edit { putString("${arguments?.getString(TAG_APP)}_version", checkedTag) } prefs.edit { putString("${arguments?.getString(TAG_APP)}_version", checkedTag) }
} }

View file

@ -10,7 +10,7 @@ import com.vanced.manager.BuildConfig.MANAGER_LANGUAGES
import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
import com.vanced.manager.databinding.DialogManagerLanguageBinding import com.vanced.manager.databinding.DialogManagerLanguageBinding
import com.vanced.manager.ui.core.ThemedMaterialRadioButton import com.vanced.manager.ui.core.ThemedMaterialRadioButton
import com.vanced.manager.utils.getCheckedButtonTag import com.vanced.manager.utils.checkedButtonTag
import com.vanced.manager.utils.getLanguageFormat import com.vanced.manager.utils.getLanguageFormat
import com.vanced.manager.utils.managerLang import com.vanced.manager.utils.managerLang
@ -43,7 +43,7 @@ class ManagerLanguageDialog : BindingBottomSheetDialogFragment<DialogManagerLang
val language = prefs.managerLang val language = prefs.managerLang
root.findViewWithTag<ThemedMaterialRadioButton>(language)?.isChecked = true root.findViewWithTag<ThemedMaterialRadioButton>(language)?.isChecked = true
languageSave.setOnClickListener { languageSave.setOnClickListener {
val newPref = binding.languageRadiogroup.getCheckedButtonTag() val newPref = binding.languageRadiogroup.checkedButtonTag
if (language != newPref) { if (language != newPref) {
prefs.managerLang = newPref prefs.managerLang = newPref
dismiss() dismiss()

View file

@ -7,7 +7,7 @@ import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.google.android.material.radiobutton.MaterialRadioButton import com.google.android.material.radiobutton.MaterialRadioButton
import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
import com.vanced.manager.databinding.DialogManagerThemeBinding import com.vanced.manager.databinding.DialogManagerThemeBinding
import com.vanced.manager.utils.getCheckedButtonTag import com.vanced.manager.utils.checkedButtonTag
import com.vanced.manager.utils.managerTheme import com.vanced.manager.utils.managerTheme
class ManagerThemeDialog : BindingBottomSheetDialogFragment<DialogManagerThemeBinding>() { class ManagerThemeDialog : BindingBottomSheetDialogFragment<DialogManagerThemeBinding>() {
@ -36,7 +36,7 @@ class ManagerThemeDialog : BindingBottomSheetDialogFragment<DialogManagerThemeBi
val theme = prefs.managerTheme val theme = prefs.managerTheme
root.findViewWithTag<MaterialRadioButton>(theme).isChecked = true root.findViewWithTag<MaterialRadioButton>(theme).isChecked = true
themeSave.setOnClickListener { themeSave.setOnClickListener {
val newPref = themeRadiogroup.getCheckedButtonTag() val newPref = themeRadiogroup.checkedButtonTag
if (theme != newPref) { if (theme != newPref) {
prefs.managerTheme = newPref prefs.managerTheme = newPref
dismiss() dismiss()

View file

@ -8,7 +8,7 @@ import com.google.android.material.radiobutton.MaterialRadioButton
import com.topjohnwu.superuser.Shell import com.topjohnwu.superuser.Shell
import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
import com.vanced.manager.databinding.DialogManagerVariantBinding import com.vanced.manager.databinding.DialogManagerVariantBinding
import com.vanced.manager.utils.getCheckedButtonTag import com.vanced.manager.utils.checkedButtonTag
import com.vanced.manager.utils.managerVariant import com.vanced.manager.utils.managerVariant
class ManagerVariantDialog : BindingBottomSheetDialogFragment<DialogManagerVariantBinding>() { class ManagerVariantDialog : BindingBottomSheetDialogFragment<DialogManagerVariantBinding>() {
@ -37,7 +37,7 @@ class ManagerVariantDialog : BindingBottomSheetDialogFragment<DialogManagerVaria
val variant = prefs.managerVariant val variant = prefs.managerVariant
root.findViewWithTag<MaterialRadioButton>(variant).isChecked = true root.findViewWithTag<MaterialRadioButton>(variant).isChecked = true
variantSave.setOnClickListener { variantSave.setOnClickListener {
val newPref = variantRadiogroup.getCheckedButtonTag() val newPref = variantRadiogroup.checkedButtonTag
if (variant != newPref) { if (variant != newPref) {
prefs.managerVariant = prefs.managerVariant =
if (newPref == "root" && Shell.rootAccess()) { if (newPref == "root" && Shell.rootAccess()) {

View file

@ -11,7 +11,7 @@ import com.vanced.manager.core.ui.ext.showDialog
import com.vanced.manager.databinding.DialogBottomRadioButtonBinding import com.vanced.manager.databinding.DialogBottomRadioButtonBinding
import com.vanced.manager.ui.core.ThemedMaterialRadioButton import com.vanced.manager.ui.core.ThemedMaterialRadioButton
import com.vanced.manager.utils.convertToAppTheme import com.vanced.manager.utils.convertToAppTheme
import com.vanced.manager.utils.getCheckedButtonTag import com.vanced.manager.utils.checkedButtonTag
import com.vanced.manager.utils.theme import com.vanced.manager.utils.theme
import com.vanced.manager.utils.vanced import com.vanced.manager.utils.vanced
@ -51,7 +51,7 @@ class VancedThemeSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomR
tag.isChecked = true tag.isChecked = true
} }
dialogSave.setOnClickListener { dialogSave.setOnClickListener {
val checkedTag = binding.dialogRadiogroup.getCheckedButtonTag() val checkedTag = binding.dialogRadiogroup.checkedButtonTag
if (checkedTag != null) { if (checkedTag != null) {
prefs.theme = checkedTag prefs.theme = checkedTag
} }

View file

@ -17,9 +17,7 @@ import com.vanced.manager.R
import com.vanced.manager.utils.AppUtils.log import com.vanced.manager.utils.AppUtils.log
import java.util.* import java.util.*
fun RadioGroup.getCheckedButtonTag(): String? { val RadioGroup.checkedButtonTag: String? get() = findViewById<MaterialRadioButton>(checkedRadioButtonId)?.tag?.toString()
return findViewById<MaterialRadioButton>(checkedRadioButtonId)?.tag?.toString()
}
fun DialogFragment.show(activity: FragmentActivity) { fun DialogFragment.show(activity: FragmentActivity) {
try { try {
@ -34,10 +32,8 @@ fun List<String>.convertToAppVersions(): List<String> = listOf("latest") + rever
fun String.formatVersion(context: Context): String = if (this == "latest") context.getString(R.string.install_latest) else this fun String.formatVersion(context: Context): String = if (this == "latest") context.getString(R.string.install_latest) else this
fun String.convertToAppTheme(context: Context): String { fun String.convertToAppTheme(context: Context): String = with(context) {
return with(context) { getString(R.string.light_plus_other, if (this@convertToAppTheme == "dark") getString(R.string.vanced_dark) else getString(R.string.vanced_black))
getString(R.string.light_plus_other, if (this@convertToAppTheme == "dark") getString(R.string.vanced_dark) else getString(R.string.vanced_black))
}
} }
fun String.getLatestAppVersion(versions: List<String>): String = if (this == "latest") versions.reversed()[0] else this fun String.getLatestAppVersion(versions: List<String>): String = if (this == "latest") versions.reversed()[0] else this