0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-26 05:05:15 +00:00

VancedPreferencesDialog migrate to view binding

This commit is contained in:
HaliksaR 2020-11-16 00:39:37 +07:00
parent 94d339732f
commit 707ed94878
2 changed files with 85 additions and 96 deletions

View file

@ -3,12 +3,10 @@ package com.vanced.manager.ui.dialogs
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.vanced.manager.R
import com.vanced.manager.databinding.DialogVancedPreferencesBinding
import com.vanced.manager.ui.core.BindingBottomSheetDialogFragment
import com.vanced.manager.utils.Extensions.convertToAppTheme
import com.vanced.manager.utils.Extensions.convertToAppVersions
import com.vanced.manager.utils.Extensions.getDefaultPrefs
@ -17,61 +15,61 @@ import com.vanced.manager.utils.InternetTools.vancedVersions
import com.vanced.manager.utils.LanguageHelper.getDefaultVancedLanguages
import java.util.*
class VancedPreferencesDialog : BottomSheetDialogFragment() {
class VancedPreferencesDialog : BindingBottomSheetDialogFragment<DialogVancedPreferencesBinding>() {
companion object {
fun newInstance(): VancedPreferencesDialog = VancedPreferencesDialog().apply {
arguments = Bundle()
}
}
private lateinit var binding: DialogVancedPreferencesBinding
private val defPrefs by lazy { requireActivity().getDefaultPrefs() }
private val installPrefs by lazy { requireActivity().getSharedPreferences("installPrefs", Context.MODE_PRIVATE) }
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
override fun binding(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.dialog_vanced_preferences, container, false)
return binding.root
) = DialogVancedPreferencesBinding.inflate(inflater, container, false)
override fun otherSetups() {
bindData()
}
@ExperimentalStdlibApi
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val showLang = mutableListOf<String>()
installPrefs.getString("lang", getDefaultVancedLanguages())?.split(", ")?.toTypedArray()?.forEach { lang ->
val loc = Locale(lang)
showLang.add(loc.getDisplayLanguage(loc).capitalize(Locale.ROOT))
}
val vancedVersionsConv = vancedVersions.get()?.value?.reversed()?.convertToAppVersions()
binding.vancedInstallTitle.text = requireActivity().getString(R.string.app_installation_preferences, requireActivity().getString(R.string.vanced))
binding.vancedTheme.text = requireActivity().getString(R.string.chosen_theme, installPrefs.getString("theme", "dark")?.convertToAppTheme(requireActivity()))
binding.vancedVersion.text = requireActivity().getString(R.string.chosen_version, defPrefs.getString("vanced_version", "latest"))
binding.vancedLang.text = requireActivity().getString(R.string.chosen_lang, showLang)
binding.openThemeSelector.setOnClickListener {
dismiss()
VancedThemeSelectorDialog().show(requireActivity())
}
binding.openVersionSelector.setOnClickListener {
dismiss()
AppVersionSelectorDialog.newInstance(
versions = vancedVersionsConv,
app = "vanced"
).show(requireActivity())
}
binding.openLanguageSelector.setOnClickListener {
dismiss()
VancedLanguageSelectionDialog().show(requireActivity())
}
binding.vancedInstall.setOnClickListener {
dismiss()
AppDownloadDialog.newInstance(
app = getString(R.string.vanced)
).show(requireActivity())
private fun bindData() {
with(binding) {
val showLang = mutableListOf<String>()
installPrefs.getString("lang", getDefaultVancedLanguages())?.split(", ")?.toTypedArray()?.forEach { lang ->
val loc = Locale(lang)
showLang.add(loc.getDisplayLanguage(loc).capitalize(Locale.ROOT))
}
val vancedVersionsConv = vancedVersions.get()?.value?.reversed()?.convertToAppVersions()
vancedInstallTitle.text = getString(R.string.app_installation_preferences, getString(R.string.vanced))
vancedTheme.text = getString(R.string.chosen_theme, installPrefs.getString("theme", "dark")?.convertToAppTheme(requireActivity()))
vancedVersion.text = getString(R.string.chosen_version, defPrefs.getString("vanced_version", "latest"))
vancedLang.text = getString(R.string.chosen_lang, showLang)
openThemeSelector.setOnClickListener {
dismiss()
VancedThemeSelectorDialog().show(requireActivity())
}
openVersionSelector.setOnClickListener {
dismiss()
AppVersionSelectorDialog.newInstance(
versions = vancedVersionsConv,
app = "vanced"
).show(requireActivity())
}
openLanguageSelector.setOnClickListener {
dismiss()
VancedLanguageSelectionDialog().show(requireActivity())
}
vancedInstall.setOnClickListener {
dismiss()
AppDownloadDialog.newInstance(
app = getString(R.string.vanced)
).show(requireActivity())
}
}
}
}

View file

@ -1,44 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
app:contentPaddingBottom="4dp"
style="@style/BottomDialogCard">
<com.google.android.material.card.MaterialCardView
style="@style/BottomDialogCard"
app:contentPaddingBottom="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
<TextView
android:id="@+id/vanced_install_title"
style="@style/BottomDialogCardTitle"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="wrap_content"
android:layout_marginTop="12dp">
<TextView
android:id="@+id/vanced_install_title"
style="@style/BottomDialogCardTitle" />
android:id="@+id/vanced_theme"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/open_theme_selector"
style="@style/BottomDialogCardTextItem"/>
<RelativeLayout
android:layout_width="match_parent"
<ImageButton
android:id="@+id/open_theme_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp">
<TextView
android:id="@+id/vanced_theme"
style="@style/BottomDialogCardTextItem"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/open_theme_selector" />
<ImageButton
android:id="@+id/open_theme_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@android:color/transparent"
android:maxWidth="24dp"
android:maxHeight="24dp"
android:src="@drawable/ic_baseline_navigate_next_36" />
</RelativeLayout>
android:layout_alignParentEnd="true"
android:background="@android:color/transparent"
android:maxWidth="24dp"
android:maxHeight="24dp"
android:src="@drawable/ic_baseline_navigate_next_36"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
@ -61,7 +58,6 @@
android:maxWidth="24dp"
android:maxHeight="24dp"
android:src="@drawable/ic_baseline_navigate_next_36" />
</RelativeLayout>
<RelativeLayout
@ -84,17 +80,12 @@
android:background="@android:color/transparent"
android:maxWidth="24dp"
android:maxHeight="24dp"
android:src="@drawable/ic_baseline_navigate_next_36" />
android:src="@drawable/ic_baseline_navigate_next_36"/>
</RelativeLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/vanced_install"
style="@style/BottomDialogButtonStyle"
android:text="@string/install" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</layout>
<com.google.android.material.button.MaterialButton
android:id="@+id/vanced_install"
android:text="@string/install"
style="@style/BottomDialogButtonStyle"/>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>