added getters and setters for preferences
This commit is contained in:
parent
fcdc910293
commit
dde6901dbe
|
@ -8,6 +8,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.ViewAppCheckboxBinding
|
||||
import com.vanced.manager.model.SelectAppModel
|
||||
import com.vanced.manager.utils.enableMusic
|
||||
import com.vanced.manager.utils.enableVanced
|
||||
|
||||
class SelectAppsAdapter(private val context: Context) :
|
||||
RecyclerView.Adapter<SelectAppsAdapter.SelectAppsViewHolder>() {
|
||||
|
@ -18,14 +20,14 @@ class SelectAppsAdapter(private val context: Context) :
|
|||
context.getString(R.string.vanced),
|
||||
context.getString(R.string.select_apps_vanced),
|
||||
"vanced",
|
||||
prefs.getBoolean("enable_vanced", true)
|
||||
prefs.enableVanced
|
||||
)
|
||||
|
||||
private val music = SelectAppModel(
|
||||
context.getString(R.string.music),
|
||||
context.getString(R.string.select_apps_music),
|
||||
"music",
|
||||
prefs.getBoolean("enable_music", true)
|
||||
prefs.enableMusic
|
||||
)
|
||||
|
||||
val apps = arrayOf(vanced, music)
|
||||
|
|
|
@ -2,12 +2,10 @@ package com.vanced.manager.core.downloader
|
|||
|
||||
import android.content.Context
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.*
|
||||
import com.vanced.manager.utils.DownloadHelper.download
|
||||
import com.vanced.manager.utils.DownloadHelper.downloadProgress
|
||||
import com.vanced.manager.utils.PackageHelper.install
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.getInstallUrl
|
||||
import com.vanced.manager.utils.microg
|
||||
|
||||
object MicrogDownloader {
|
||||
|
||||
|
@ -16,7 +14,7 @@ object MicrogDownloader {
|
|||
|
||||
fun downloadMicrog(context: Context) {
|
||||
val url = microg.value?.string("url") ?: ""
|
||||
context.getDefaultPrefs().getInstallUrl()?.let {
|
||||
context.defPrefs.installUrl?.let {
|
||||
download(url, "$it/", folderName, fileName, context, onDownloadComplete = {
|
||||
startMicrogInstall(context)
|
||||
}, onError = {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.vanced.manager.core.downloader
|
||||
|
||||
import android.content.Context
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.*
|
||||
import com.vanced.manager.utils.AppUtils.musicRootPkg
|
||||
|
@ -23,11 +22,11 @@ object MusicDownloader {
|
|||
private var hashUrl: String? = null
|
||||
|
||||
fun downloadMusic(context: Context) {
|
||||
val prefs = getDefaultSharedPreferences(context)
|
||||
version = prefs.getString("music_version", "latest")?.getLatestAppVersion(musicVersions.value?.value ?: listOf(""))
|
||||
val prefs = context.defPrefs
|
||||
version = prefs.musicVersion?.getLatestAppVersion(musicVersions.value?.value ?: listOf(""))
|
||||
versionCode = music.value?.int("versionCode")
|
||||
variant = prefs.getString("vanced_variant", "nonroot")
|
||||
baseurl = "${prefs.getInstallUrl()}/music/v$version"
|
||||
variant = prefs.managerVariant
|
||||
baseurl = "${prefs.installUrl}/music/v$version"
|
||||
folderName = "music/$variant"
|
||||
downloadPath = context.getExternalFilesDir(folderName)?.path
|
||||
hashUrl = "$baseurl/hash.json"
|
||||
|
@ -37,7 +36,7 @@ object MusicDownloader {
|
|||
|
||||
private fun downloadApk(context: Context, apk: String = "music") {
|
||||
val url = if (apk == "stock") "$baseurl/stock/${getArch()}.apk" else "$baseurl/$variant.apk"
|
||||
download(url, baseurl + "/", folderName!!, getFileNameFromUrl(url), context, onDownloadComplete = {
|
||||
download(url, "$baseurl/", folderName!!, getFileNameFromUrl(url), context, onDownloadComplete = {
|
||||
if (variant == "root" && apk != "stock") {
|
||||
downloadApk(context, "stock")
|
||||
return@download
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.vanced.manager.core.downloader
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
import com.google.firebase.analytics.ktx.logEvent
|
||||
import com.vanced.manager.R
|
||||
|
@ -41,21 +40,20 @@ object VancedDownloader {
|
|||
private var folderName: String? = null
|
||||
|
||||
fun downloadVanced(context: Context) {
|
||||
defPrefs = getDefaultSharedPreferences(context)
|
||||
prefs = context.getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
variant = defPrefs.getString("vanced_variant", "nonroot")
|
||||
defPrefs = context.defPrefs
|
||||
prefs = context.installPrefs
|
||||
variant = defPrefs.managerVariant
|
||||
folderName = "vanced/$variant"
|
||||
downloadPath = context.getExternalFilesDir(folderName)?.path
|
||||
File(downloadPath.toString()).deleteRecursively()
|
||||
installUrl = defPrefs.getInstallUrl()
|
||||
prefs.getString("lang", getDefaultVancedLanguages())?.let {
|
||||
installUrl = defPrefs.installUrl
|
||||
prefs.lang?.let {
|
||||
lang = it.split(", ").toMutableList()
|
||||
}
|
||||
theme = prefs.getString("theme", "dark")
|
||||
vancedVersion = defPrefs.getString("vanced_version", "latest")?.getLatestAppVersion(vancedVersions.value?.value ?: listOf(""))
|
||||
theme = prefs.theme
|
||||
vancedVersion = defPrefs.vancedVersion?.getLatestAppVersion(vancedVersions.value?.value ?: listOf(""))
|
||||
themePath = "$installUrl/apks/v$vancedVersion/$variant/Theme"
|
||||
hashUrl = "apks/v$vancedVersion/$variant/Theme/hash.json"
|
||||
//newInstaller = defPrefs.getBoolean("new_installer", false)
|
||||
arch = getArch()
|
||||
count = 0
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import android.view.LayoutInflater
|
|||
import android.widget.CompoundButton
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.ViewPreferenceSwitchBinding
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
|
||||
class PreferenceSwitch @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -21,7 +21,7 @@ class PreferenceSwitch @JvmOverloads constructor(
|
|||
fun onChecked(buttonView: CompoundButton, isChecked: Boolean)
|
||||
}
|
||||
|
||||
private val prefs by lazy { getDefaultSharedPreferences(context) }
|
||||
private val prefs by lazy { context.defPrefs }
|
||||
|
||||
var prefKey: String = ""
|
||||
private set
|
||||
|
|
|
@ -7,9 +7,9 @@ import androidx.core.graphics.ColorUtils
|
|||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedMaterialButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -18,7 +18,7 @@ class ThemedMaterialButton @JvmOverloads constructor(
|
|||
) : MaterialButton(context, attributeSet, defStyleAttr) {
|
||||
|
||||
init {
|
||||
setBgColor(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
setBgColor(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
setBgColor(color.toInt())
|
||||
|
|
|
@ -5,14 +5,14 @@ import android.content.res.ColorStateList
|
|||
import android.util.AttributeSet
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedMaterialCheckbox @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attributeSet: AttributeSet? = null,
|
||||
) : MaterialCheckBox(context, attributeSet, R.attr.checkboxStyle) {
|
||||
init {
|
||||
buttonTintList = ColorStateList.valueOf(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
buttonTintList = ColorStateList.valueOf(context.defPrefs.managerAccent)
|
||||
}
|
||||
}
|
|
@ -5,14 +5,14 @@ import android.content.res.ColorStateList
|
|||
import android.util.AttributeSet
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedMaterialRadioButton @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attributeSet: AttributeSet? = null,
|
||||
) : MaterialRadioButton(context, attributeSet, R.attr.radioButtonStyle) {
|
||||
init {
|
||||
buttonTintList = ColorStateList.valueOf(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
buttonTintList = ColorStateList.valueOf(context.defPrefs.managerAccent)
|
||||
}
|
||||
}
|
|
@ -4,8 +4,8 @@ import android.content.Context
|
|||
import android.content.res.ColorStateList
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.slider.Slider
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedMaterialSlider@JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -14,7 +14,7 @@ class ThemedMaterialSlider@JvmOverloads constructor(
|
|||
) : Slider(context, attributeSet, defStyleAttr) {
|
||||
|
||||
init {
|
||||
thumbStrokeColor = ColorStateList.valueOf(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
thumbStrokeColor = ColorStateList.valueOf(context.defPrefs.managerAccent)
|
||||
}
|
||||
|
||||
}
|
|
@ -6,9 +6,9 @@ import android.util.AttributeSet
|
|||
import androidx.core.graphics.ColorUtils
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
|
||||
class ThemedOutlinedMaterialButton @JvmOverloads constructor(
|
||||
|
@ -17,7 +17,7 @@ class ThemedOutlinedMaterialButton @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : MaterialButton(context, attributeSet, defStyleAttr) {
|
||||
init {
|
||||
applyAccent(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
applyAccent(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
applyAccent(color.toInt())
|
||||
|
|
|
@ -4,15 +4,15 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedSwipeRefreshlayout @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attributeSet: AttributeSet? = null
|
||||
) : SwipeRefreshLayout(context, attributeSet) {
|
||||
init {
|
||||
setColorSchemeColors(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
setColorSchemeColors(context.defPrefs.managerAccent)
|
||||
initAttrs(context, attributeSet)
|
||||
}
|
||||
private fun initAttrs(context: Context, attributeSet: AttributeSet?) {
|
||||
|
|
|
@ -9,9 +9,9 @@ import androidx.core.graphics.ColorUtils
|
|||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedSwitchCompat @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -21,7 +21,7 @@ class ThemedSwitchCompat @JvmOverloads constructor(
|
|||
private val states = arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked))
|
||||
|
||||
init {
|
||||
setSwitchColors(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
setSwitchColors(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
setSwitchColors(color.toInt())
|
||||
|
|
|
@ -4,9 +4,9 @@ import android.content.Context
|
|||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.lifecycleOwner
|
||||
import com.vanced.manager.utils.managerAccent
|
||||
|
||||
class ThemedTextView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
|
@ -14,7 +14,7 @@ class ThemedTextView @JvmOverloads constructor(
|
|||
defStyleAttr: Int = 0
|
||||
) : AppCompatTextView(context, attributeSet, defStyleAttr) {
|
||||
init {
|
||||
setTextColor(context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor))
|
||||
setTextColor(context.defPrefs.managerAccent)
|
||||
context.lifecycleOwner()?.let { owner ->
|
||||
accentColor.observe(owner) { color ->
|
||||
setTextColor(color.toInt())
|
||||
|
|
|
@ -11,12 +11,12 @@ import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
|
|||
import com.vanced.manager.core.ui.ext.showDialog
|
||||
import com.vanced.manager.databinding.DialogBottomRadioButtonBinding
|
||||
import com.vanced.manager.ui.core.ThemedMaterialRadioButton
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.getCheckedButtonTag
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
|
||||
class AppVersionSelectorDialog : BindingBottomSheetDialogFragment<DialogBottomRadioButtonBinding>() {
|
||||
|
||||
private val prefs by lazy { requireActivity().getDefaultPrefs() }
|
||||
private val prefs by lazy { requireActivity().defPrefs }
|
||||
|
||||
companion object {
|
||||
|
||||
|
|
|
@ -10,16 +10,12 @@ import android.view.LayoutInflater
|
|||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.madrapps.pikolo.listeners.OnColorSelectionListener
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.core.ui.base.BindingDialogFragment
|
||||
import com.vanced.manager.databinding.DialogManagerAccentColorBinding
|
||||
import com.vanced.manager.utils.accentColor
|
||||
import com.vanced.manager.utils.defAccentColor
|
||||
import com.vanced.manager.utils.mutableAccentColor
|
||||
import com.vanced.manager.utils.toHex
|
||||
import com.vanced.manager.utils.*
|
||||
|
||||
class ManagerAccentColorDialog : BindingDialogFragment<DialogManagerAccentColorBinding>() {
|
||||
|
||||
|
@ -95,7 +91,7 @@ class ManagerAccentColorDialog : BindingDialogFragment<DialogManagerAccentColorB
|
|||
try {
|
||||
val colorFromEditText = Color.parseColor(hexEdittext.text.toString())
|
||||
mutableAccentColor.value = colorFromEditText
|
||||
prefs.edit { putInt("manager_accent_color", colorFromEditText) }
|
||||
prefs.managerAccent = colorFromEditText
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.d("VMTheme", getString(R.string.failed_accent))
|
||||
Toast.makeText(requireActivity(), getString(R.string.failed_accent), Toast.LENGTH_SHORT).show()
|
||||
|
@ -105,7 +101,7 @@ class ManagerAccentColorDialog : BindingDialogFragment<DialogManagerAccentColorB
|
|||
dismiss()
|
||||
}
|
||||
accentReset.setOnClickListener {
|
||||
prefs.edit { putInt("manager_accent_color", defAccentColor) }
|
||||
prefs.managerAccent = defAccentColor
|
||||
mutableAccentColor.value = defAccentColor
|
||||
dismiss()
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.view.LayoutInflater
|
|||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.vanced.manager.BuildConfig.MANAGER_LANGUAGES
|
||||
import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
|
||||
|
@ -13,6 +12,7 @@ import com.vanced.manager.databinding.DialogManagerLanguageBinding
|
|||
import com.vanced.manager.ui.core.ThemedMaterialRadioButton
|
||||
import com.vanced.manager.utils.getCheckedButtonTag
|
||||
import com.vanced.manager.utils.getLanguageFormat
|
||||
import com.vanced.manager.utils.managerLang
|
||||
|
||||
class ManagerLanguageDialog : BindingBottomSheetDialogFragment<DialogManagerLanguageBinding>() {
|
||||
|
||||
|
@ -40,12 +40,12 @@ class ManagerLanguageDialog : BindingBottomSheetDialogFragment<DialogManagerLang
|
|||
addRadioButtons().forEach { mrb ->
|
||||
languageRadiogroup.addView(mrb, MATCH_PARENT, WRAP_CONTENT)
|
||||
}
|
||||
val language = prefs.getString("manager_lang", "System Default")
|
||||
val language = prefs.managerLang
|
||||
root.findViewWithTag<ThemedMaterialRadioButton>(language)?.isChecked = true
|
||||
languageSave.setOnClickListener {
|
||||
val newPref = binding.languageRadiogroup.getCheckedButtonTag()
|
||||
if (language != newPref) {
|
||||
prefs.edit { putString("manager_lang", newPref) }
|
||||
prefs.managerLang = newPref
|
||||
dismiss()
|
||||
requireActivity().recreate()
|
||||
} else {
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.google.android.material.radiobutton.MaterialRadioButton
|
|||
import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
|
||||
import com.vanced.manager.databinding.DialogManagerThemeBinding
|
||||
import com.vanced.manager.utils.getCheckedButtonTag
|
||||
import com.vanced.manager.utils.managerTheme
|
||||
|
||||
class ManagerThemeDialog : BindingBottomSheetDialogFragment<DialogManagerThemeBinding>() {
|
||||
|
||||
|
@ -33,12 +34,12 @@ class ManagerThemeDialog : BindingBottomSheetDialogFragment<DialogManagerThemeBi
|
|||
|
||||
private fun bindData() {
|
||||
with(binding) {
|
||||
val theme = prefs.getString("manager_theme", "System Default")
|
||||
val theme = prefs.managerTheme
|
||||
root.findViewWithTag<MaterialRadioButton>(theme).isChecked = true
|
||||
themeSave.setOnClickListener {
|
||||
val newPref = themeRadiogroup.getCheckedButtonTag()
|
||||
if (theme != newPref) {
|
||||
prefs.edit { putString("manager_theme", newPref) }
|
||||
prefs.managerTheme = newPref
|
||||
dismiss()
|
||||
requireActivity().recreate()
|
||||
} else {
|
||||
|
|
|
@ -3,13 +3,13 @@ package com.vanced.manager.ui.dialogs
|
|||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
|
||||
import com.vanced.manager.databinding.DialogManagerVariantBinding
|
||||
import com.vanced.manager.utils.getCheckedButtonTag
|
||||
import com.vanced.manager.utils.managerVariant
|
||||
|
||||
class ManagerVariantDialog : BindingBottomSheetDialogFragment<DialogManagerVariantBinding>() {
|
||||
|
||||
|
@ -34,16 +34,16 @@ class ManagerVariantDialog : BindingBottomSheetDialogFragment<DialogManagerVaria
|
|||
|
||||
private fun bindData() {
|
||||
with(binding) {
|
||||
val variant = prefs.getString("vanced_variant", "nonroot")
|
||||
val variant = prefs.managerVariant
|
||||
root.findViewWithTag<MaterialRadioButton>(variant).isChecked = true
|
||||
variantSave.setOnClickListener {
|
||||
val newPref = variantRadiogroup.getCheckedButtonTag()
|
||||
if (variant != newPref) {
|
||||
prefs.edit {
|
||||
with (prefs.managerVariant) {
|
||||
if (newPref == "root" && Shell.rootAccess()) {
|
||||
putString("vanced_variant", "root")
|
||||
this == "root"
|
||||
} else {
|
||||
putString("vanced_variant", "nonroot")
|
||||
this == "nonroot"
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.vanced.manager.core.ui.base.BindingBottomSheetDialogFragment
|
|||
import com.vanced.manager.core.ui.ext.showDialog
|
||||
import com.vanced.manager.databinding.DialogMusicPreferencesBinding
|
||||
import com.vanced.manager.utils.convertToAppVersions
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.musicVersions
|
||||
|
||||
class MusicPreferencesDialog : BindingBottomSheetDialogFragment<DialogMusicPreferencesBinding>() {
|
||||
|
@ -20,7 +20,7 @@ class MusicPreferencesDialog : BindingBottomSheetDialogFragment<DialogMusicPrefe
|
|||
}
|
||||
}
|
||||
|
||||
private val prefs by lazy { requireActivity().getDefaultPrefs() }
|
||||
private val prefs by lazy { requireActivity().defPrefs }
|
||||
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
|
|
|
@ -12,14 +12,14 @@ import com.vanced.manager.utils.PackageHelper
|
|||
import com.vanced.manager.utils.PackageHelper.getPackageDir
|
||||
import com.vanced.manager.utils.PackageHelper.getPkgNameRoot
|
||||
import com.vanced.manager.utils.PackageHelper.scriptExists
|
||||
import com.vanced.manager.utils.getDefaultPrefs
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.writeServiceDScript
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
class ServiceDTimerDialog : BindingDialogFragment<DialogServicedTimerBinding>() {
|
||||
|
||||
private val prefs by lazy { requireActivity().getDefaultPrefs() }
|
||||
private val prefs by lazy { requireActivity().defPrefs }
|
||||
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
|
|
|
@ -6,17 +6,19 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.vanced.manager.core.ui.base.BindingDialogFragment
|
||||
import com.vanced.manager.databinding.DialogCustomUrlBinding
|
||||
import com.vanced.manager.utils.baseUrl
|
||||
import com.vanced.manager.utils.defPrefs
|
||||
import com.vanced.manager.utils.installUrl
|
||||
import com.vanced.manager.utils.loadJson
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class URLChangeDialog : BindingDialogFragment<DialogCustomUrlBinding>() {
|
||||
|
||||
private val prefs by lazy { requireActivity().defPrefs }
|
||||
|
||||
companion object {
|
||||
|
||||
fun newInstance(): URLChangeDialog = URLChangeDialog().apply {
|
||||
|
@ -41,7 +43,7 @@ class URLChangeDialog : BindingDialogFragment<DialogCustomUrlBinding>() {
|
|||
if (arguments != null) {
|
||||
arguments?.getString("url")
|
||||
} else {
|
||||
getDefaultSharedPreferences(requireActivity()).getString("install_url", baseUrl)
|
||||
prefs.installUrl
|
||||
},
|
||||
TextView.BufferType.EDITABLE
|
||||
)
|
||||
|
@ -59,7 +61,7 @@ class URLChangeDialog : BindingDialogFragment<DialogCustomUrlBinding>() {
|
|||
|
||||
private fun saveUrl(url: String) {
|
||||
lifecycleScope.launch {
|
||||
getDefaultSharedPreferences(requireActivity()).edit { putString("install_url", url) }
|
||||
prefs.installUrl = url
|
||||
loadJson(requireActivity())
|
||||
dismiss()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.vanced.manager.ui.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
|
@ -21,8 +20,8 @@ class VancedPreferencesDialog : BindingBottomSheetDialogFragment<DialogVancedPre
|
|||
}
|
||||
}
|
||||
|
||||
private val defPrefs by lazy { requireActivity().getDefaultPrefs() }
|
||||
private val installPrefs by lazy { requireActivity().getSharedPreferences("installPrefs", Context.MODE_PRIVATE) }
|
||||
private val defPrefs by lazy { requireActivity().defPrefs }
|
||||
private val installPrefs by lazy { requireActivity().installPrefs }
|
||||
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
|
|
|
@ -3,14 +3,12 @@ package com.vanced.manager.utils
|
|||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.content.DialogInterface
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import android.widget.RadioGroup
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.radiobutton.MaterialRadioButton
|
||||
|
@ -32,8 +30,6 @@ fun DialogFragment.show(activity: FragmentActivity) {
|
|||
|
||||
}
|
||||
|
||||
fun Context.getDefaultPrefs(): SharedPreferences = getDefaultSharedPreferences(this)
|
||||
|
||||
//Not sure how much this can affect performance
|
||||
//but if anyone can improve this even slightly,
|
||||
//feel free to open a PR
|
||||
|
@ -49,11 +45,7 @@ fun String.convertToAppTheme(context: Context): String {
|
|||
return context.getString(R.string.light_plus_other, this.capitalize(Locale.ROOT))
|
||||
}
|
||||
|
||||
fun String.getLatestAppVersion(versions: List<String>): String {
|
||||
return if (this == "latest") versions.reversed()[0] else this
|
||||
}
|
||||
|
||||
fun SharedPreferences.getInstallUrl() = getString("install_url", baseUrl)
|
||||
fun String.getLatestAppVersion(versions: List<String>): String = if (this == "latest") versions.reversed()[0] else this
|
||||
|
||||
fun Context.lifecycleOwner(): LifecycleOwner? {
|
||||
var curContext = this
|
||||
|
@ -73,14 +65,14 @@ fun Int.toHex(): String = java.lang.String.format("#%06X", 0xFFFFFF and this)
|
|||
//Material team decided to keep their LinearProgressIndicator final
|
||||
//At least extension methods exist
|
||||
fun LinearProgressIndicator.applyAccent() {
|
||||
with(accentColor.value ?: context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor)) {
|
||||
with(accentColor.value ?: context.defPrefs.managerAccent) {
|
||||
setIndicatorColor(this)
|
||||
trackColor = ColorUtils.setAlphaComponent(this, 70)
|
||||
}
|
||||
}
|
||||
|
||||
fun MaterialAlertDialogBuilder.applyAccent() {
|
||||
with(accentColor.value ?: context.getDefaultPrefs().getInt("manager_accent_color", defAccentColor)) {
|
||||
with(accentColor.value ?: context.defPrefs.managerAccent) {
|
||||
show().apply {
|
||||
getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(this@with)
|
||||
getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(this@with)
|
||||
|
@ -92,6 +84,6 @@ fun MaterialAlertDialogBuilder.applyAccent() {
|
|||
fun Context.writeServiceDScript(apkFPath: String, path: String, app: String) {
|
||||
val shellFileZ = SuFile.open("/data/adb/service.d/$app.sh")
|
||||
shellFileZ.createNewFile()
|
||||
val code = """#!/system/bin/sh${"\n"}while [ "`getprop sys.boot_completed | tr -d '\r' `" != "1" ]; do sleep ${getDefaultPrefs().getInt("serviced_sleep_timer", 1)}; done${"\n"}chcon u:object_r:apk_data_file:s0 $apkFPath${"\n"}mount -o bind $apkFPath $path"""
|
||||
val code = """#!/system/bin/sh${"\n"}while [ "`getprop sys.boot_completed | tr -d '\r' `" != "1" ]; do sleep ${defPrefs.serviceDSleepTimer}; done${"\n"}chcon u:object_r:apk_data_file:s0 $apkFPath${"\n"}mount -o bind $apkFPath $path"""
|
||||
SuFileOutputStream(shellFileZ).use { out -> out.write(code.toByteArray())}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.vanced.manager.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
|
||||
val Context.installPrefs: SharedPreferences get() = getSharedPreferences("installPrefs", Context.MODE_PRIVATE)
|
||||
|
||||
var SharedPreferences.lang
|
||||
get() = getString("lang", getDefaultVancedLanguages())
|
||||
set(value) = edit { putString("lang", value) }
|
||||
|
||||
|
||||
var SharedPreferences.theme
|
||||
get() = getString("theme", "dark")
|
||||
set(value) = edit { putString("theme", value) }
|
|
@ -56,7 +56,7 @@ fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/') + 1, ur
|
|||
|
||||
suspend fun loadJson(context: Context) = withContext(Dispatchers.IO) {
|
||||
isFetching.postValue(true)
|
||||
val installUrl = context.getDefaultPrefs().getString("install_url", baseUrl)
|
||||
val installUrl = context.defPrefs.installUrl
|
||||
val calendar = Calendar.getInstance()
|
||||
val hour = calendar.get(Calendar.HOUR_OF_DAY)
|
||||
val minute = calendar.get(Calendar.MINUTE)
|
||||
|
@ -79,7 +79,7 @@ suspend fun loadJson(context: Context) = withContext(Dispatchers.IO) {
|
|||
}
|
||||
|
||||
private suspend fun getJsonString(file: String, obj: String, context: Context): String {
|
||||
val installUrl = context.getDefaultPrefs().getString("install_url", baseUrl)
|
||||
val installUrl = context.defPrefs.installUrl
|
||||
return try {
|
||||
getJson("$installUrl/$file")?.string(obj) ?: context.getString(R.string.unavailable)
|
||||
} catch (e: Exception) {
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.vanced.manager.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
|
||||
val Context.defPrefs: SharedPreferences get() = getDefaultSharedPreferences(this)
|
||||
|
||||
var SharedPreferences.managerTheme
|
||||
get() = getString("manager_theme", "System Default")
|
||||
set(value) = edit { putString("manager_theme", value) }
|
||||
|
||||
var SharedPreferences.managerAccent
|
||||
get() = getInt("manager_accent_color", defAccentColor)
|
||||
set(value) = edit { putInt("manager_accent_color", value) }
|
||||
|
||||
var SharedPreferences.managerVariant
|
||||
get() = getString("vanced_variant", "nonroot")
|
||||
set(value) = edit { putString("vanced_variant", value) }
|
||||
|
||||
var SharedPreferences.managerLang
|
||||
get() = getString("manager_lang", "System Default")
|
||||
set(value) = edit { putString("manager_lang", value) }
|
||||
|
||||
var SharedPreferences.installUrl
|
||||
get() = getString("install_url", baseUrl)
|
||||
set(value) = edit { putString("install_url", value) }
|
||||
|
||||
var SharedPreferences.vancedVersion
|
||||
get() = getString("vanced_version", "latest")
|
||||
set(value) = edit { putString("vanced_version", value) }
|
||||
|
||||
var SharedPreferences.musicVersion
|
||||
get() = getString("music_version", "latest")
|
||||
set(value) = edit { putString("music_version", value) }
|
||||
|
||||
var SharedPreferences.serviceDSleepTimer
|
||||
get() = getInt("serviced_sleep_timer", 1)
|
||||
set(value) = edit { putInt("serviced_sleep_timer", value) }
|
||||
|
||||
var SharedPreferences.enableVanced
|
||||
get() = getBoolean("enable_vanced", true)
|
||||
set(value) = edit { putBoolean("enable_vanced", value) }
|
||||
|
||||
var SharedPreferences.enableMusic
|
||||
get() = getBoolean("enable_music", true)
|
||||
set(value) = edit { putBoolean("enable_music", value) }
|
||||
|
|
@ -12,7 +12,7 @@ val mutableAccentColor = MutableLiveData<Int>()
|
|||
val accentColor: LiveData<Int> = mutableAccentColor
|
||||
|
||||
fun Activity.setFinalTheme() {
|
||||
when (getDefaultPrefs().getString("manager_theme", "System Default")) {
|
||||
when (defPrefs.managerTheme) {
|
||||
"Light" -> setTheme(R.style.LightTheme)
|
||||
"Dark" -> setTheme(R.style.DarkTheme)
|
||||
"System Default" -> {
|
||||
|
|
Loading…
Reference in New Issue