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
|
2020-04-28 21:26:27 +00:00
|
|
|
import androidx.fragment.app.FragmentManager
|
|
|
|
import androidx.preference.DialogPreference
|
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-03-28 13:29:48 +00:00
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
|
|
setPreferencesFromResource(R.xml.preferences, rootKey)
|
2020-04-28 21:26:27 +00:00
|
|
|
activity?.title = getString(R.string.title_settings)
|
|
|
|
setHasOptionsMenu(true)
|
2020-04-03 16:40:54 +00:00
|
|
|
|
2020-04-12 12:00:14 +00:00
|
|
|
val updateCheck: Preference? = findPreference("update_check")
|
2020-04-28 21:26:27 +00:00
|
|
|
updateCheck?.setOnPreferenceClickListener {
|
|
|
|
val fm = childFragmentManager.beginTransaction()
|
|
|
|
val updateDialog = UpdateCheckFragment()
|
|
|
|
updateDialog.show(fm, "Update Center")
|
|
|
|
true
|
|
|
|
}
|
2020-04-12 12:00:14 +00:00
|
|
|
|
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" -> {
|
2020-05-02 14:39:47 +00:00
|
|
|
activity?.setTheme(R.style.LightTheme)
|
2020-05-02 13:05:19 +00:00
|
|
|
activity?.recreate()
|
2020-04-03 16:40:54 +00:00
|
|
|
}
|
2020-04-07 12:48:13 +00:00
|
|
|
"DARK" -> {
|
2020-05-02 14:39:47 +00:00
|
|
|
activity?.setTheme(R.style.DarkTheme)
|
2020-05-02 13:05:19 +00:00
|
|
|
activity?.recreate()
|
2020-04-07 12:48:13 +00:00
|
|
|
}
|
2020-04-12 12:00:14 +00:00
|
|
|
"FOLLOW" -> {
|
|
|
|
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
|
|
|
|
Configuration.UI_MODE_NIGHT_YES ->{
|
2020-05-02 14:39:47 +00:00
|
|
|
activity?.setTheme(R.style.DarkTheme)
|
2020-05-02 13:05:19 +00:00
|
|
|
activity?.recreate()
|
2020-04-12 12:00:14 +00:00
|
|
|
}
|
|
|
|
Configuration.UI_MODE_NIGHT_NO -> {
|
2020-05-02 14:39:47 +00:00
|
|
|
activity?.setTheme(R.style.LightTheme)
|
2020-05-02 13:05:19 +00:00
|
|
|
activity?.recreate()
|
2020-04-12 12:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 12:45:09 +00:00
|
|
|
else -> {
|
2020-05-02 14:39:47 +00:00
|
|
|
activity?.setTheme(R.style.LightTheme)
|
2020-05-02 13:05:19 +00:00
|
|
|
activity?.recreate()
|
2020-04-10 12:45:09 +00:00
|
|
|
}
|
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)
|
2020-04-22 09:41:18 +00:00
|
|
|
super .onCreateOptionsMenu(menu, inflater)
|
2020-04-19 17:21:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 13:29:48 +00:00
|
|
|
}
|