DroidFS/app/src/main/java/sushi/hardcore/droidfs/SettingsActivity.kt

54 lines
2.0 KiB
Kotlin
Raw Normal View History

2020-07-17 16:35:39 +02:00
package sushi.hardcore.droidfs
import android.os.Bundle
2020-08-29 21:20:15 +02:00
import android.view.MenuItem
2021-11-09 11:12:09 +01:00
import androidx.preference.ListPreference
2020-07-17 16:35:39 +02:00
import androidx.preference.PreferenceFragmentCompat
2021-06-11 20:23:54 +02:00
import sushi.hardcore.droidfs.databinding.ActivitySettingsBinding
2020-07-17 16:35:39 +02:00
2021-06-07 16:34:50 +02:00
class SettingsActivity : BaseActivity() {
2020-07-17 16:35:39 +02:00
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
2021-06-11 20:23:54 +02:00
val binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.toolbar.toolbar)
2020-07-17 16:35:39 +02:00
supportActionBar?.setDisplayHomeAsUpEnabled(true)
val screen = intent.extras?.getString("screen") ?: "main"
2020-08-29 21:20:15 +02:00
val fragment = if (screen == "UnsafeFeaturesSettingsFragment") {
2020-07-17 16:35:39 +02:00
UnsafeFeaturesSettingsFragment()
} else {
2020-08-29 21:20:15 +02:00
MainSettingsFragment()
2020-07-17 16:35:39 +02:00
}
supportFragmentManager
.beginTransaction()
.replace(R.id.settings, fragment)
.commit()
}
2020-08-29 21:20:15 +02:00
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId){
android.R.id.home -> {
onBackPressed() //return to the previous fragment rather than the activity
true
}
else -> super.onOptionsItemSelected(item)
}
}
class MainSettingsFragment : PreferenceFragmentCompat() {
2020-07-17 16:35:39 +02:00
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.root_preferences, rootKey)
2021-11-09 11:12:09 +01:00
findPreference<ListPreference>("theme")?.setOnPreferenceChangeListener { _, newValue ->
(activity as BaseActivity).onThemeChanged(newValue as String)
true
2020-08-07 22:40:13 +02:00
}
2020-07-17 16:35:39 +02:00
}
}
class UnsafeFeaturesSettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.unsafe_features_preferences, rootKey)
}
}
}