2020-04-09 17:31:13 +00:00
|
|
|
package com.vanced.manager.ui.fragments
|
2020-03-19 19:55:00 +00:00
|
|
|
|
2020-04-10 12:45:09 +00:00
|
|
|
import android.content.res.Configuration
|
2020-03-19 19:55:00 +00:00
|
|
|
import android.os.Bundle
|
2020-04-19 17:21:40 +00:00
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuInflater
|
|
|
|
import android.view.MenuItem
|
|
|
|
import androidx.navigation.findNavController
|
2020-04-03 16:40:54 +00:00
|
|
|
import androidx.preference.ListPreference
|
2020-04-12 12:00:14 +00:00
|
|
|
import androidx.preference.Preference
|
2020-03-28 13:29:48 +00:00
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
2020-04-09 17:31:13 +00:00
|
|
|
import com.vanced.manager.R
|
2020-03-19 19:55:00 +00:00
|
|
|
|
2020-03-28 13:29:48 +00:00
|
|
|
class SettingsFragment : PreferenceFragmentCompat() {
|
2020-03-19 19:55:00 +00:00
|
|
|
|
2020-04-14 20:54:42 +00:00
|
|
|
override fun onStart() {
|
|
|
|
super.onStart()
|
|
|
|
activity?.title = getString(R.string.title_settings)
|
2020-04-19 17:21:40 +00:00
|
|
|
setHasOptionsMenu(true)
|
2020-04-14 20:54:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 13:29:48 +00:00
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
|
|
setPreferencesFromResource(R.xml.preferences, rootKey)
|
2020-04-03 16:40:54 +00:00
|
|
|
|
2020-04-12 12:00:14 +00:00
|
|
|
val updateCheck: Preference? = findPreference("update_check")
|
|
|
|
|
2020-04-09 17:31:13 +00:00
|
|
|
val themeSwitch: ListPreference? = findPreference("theme_mode")
|
2020-04-03 16:40:54 +00:00
|
|
|
themeSwitch?.setOnPreferenceChangeListener { _, _ ->
|
2020-04-07 12:48:13 +00:00
|
|
|
|
|
|
|
when (themeSwitch.value){
|
|
|
|
"LIGHT" -> {
|
|
|
|
activity?.setTheme(R.style.LightTheme_Blue)
|
|
|
|
activity?.recreate()
|
2020-04-03 16:40:54 +00:00
|
|
|
}
|
2020-04-07 12:48:13 +00:00
|
|
|
"DARK" -> {
|
|
|
|
activity?.setTheme(R.style.DarkTheme_Blue)
|
|
|
|
activity?.recreate()
|
|
|
|
}
|
2020-04-12 12:00:14 +00:00
|
|
|
"FOLLOW" -> {
|
|
|
|
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
|
|
|
Configuration.UI_MODE_NIGHT_YES ->{
|
|
|
|
activity?.setTheme(R.style.DarkTheme_Blue)
|
|
|
|
activity?.recreate()
|
|
|
|
}
|
|
|
|
Configuration.UI_MODE_NIGHT_NO -> {
|
|
|
|
activity?.setTheme(R.style.LightTheme_Blue)
|
|
|
|
activity?.recreate()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 12:45:09 +00:00
|
|
|
else -> {
|
|
|
|
activity?.setTheme(R.style.LightTheme_Blue)
|
|
|
|
activity?.recreate()
|
|
|
|
}
|
2020-04-03 16:40:54 +00:00
|
|
|
}
|
|
|
|
true
|
2020-04-12 12:00:14 +00:00
|
|
|
}
|
2020-04-03 16:40:54 +00:00
|
|
|
|
2020-03-19 19:55:00 +00:00
|
|
|
}
|
2020-04-19 17:21:40 +00:00
|
|
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
|
|
|
inflater.inflate(R.menu.secret_settings_menu, menu)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
|
|
|
R.id.secret_settings -> view?.findNavController()?.navigate(R.id.toSecretSettingsFragment)
|
|
|
|
else -> null
|
|
|
|
}?.let { true } ?: super.onOptionsItemSelected(item)
|
|
|
|
|
2020-03-28 13:29:48 +00:00
|
|
|
}
|