forked from hardcoresushi/DroidFS
Settings fragments navigation fix
This commit is contained in:
parent
06efdb61c3
commit
9c31576b97
@ -1,9 +1,8 @@
|
|||||||
package sushi.hardcore.droidfs
|
package sushi.hardcore.droidfs
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.MenuItem
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import com.jaredrummler.android.colorpicker.ColorPreferenceCompat
|
import com.jaredrummler.android.colorpicker.ColorPreferenceCompat
|
||||||
@ -11,7 +10,6 @@ import kotlinx.android.synthetic.main.toolbar.*
|
|||||||
import sushi.hardcore.droidfs.widgets.SimpleActionPreference
|
import sushi.hardcore.droidfs.widgets.SimpleActionPreference
|
||||||
import sushi.hardcore.droidfs.widgets.ThemeColor
|
import sushi.hardcore.droidfs.widgets.ThemeColor
|
||||||
|
|
||||||
|
|
||||||
class SettingsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
|
class SettingsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@ -20,11 +18,10 @@ class SettingsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceSt
|
|||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
val screen = intent.extras?.getString("screen") ?: "main"
|
val screen = intent.extras?.getString("screen") ?: "main"
|
||||||
val fragment: Fragment
|
val fragment = if (screen == "UnsafeFeaturesSettingsFragment") {
|
||||||
fragment = if (screen == "UnsafeFeaturesSettingsFragment") {
|
|
||||||
UnsafeFeaturesSettingsFragment()
|
UnsafeFeaturesSettingsFragment()
|
||||||
} else {
|
} else {
|
||||||
SettingsFragment()
|
MainSettingsFragment()
|
||||||
}
|
}
|
||||||
supportFragmentManager
|
supportFragmentManager
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
@ -32,7 +29,17 @@ class SettingsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceSt
|
|||||||
.commit()
|
.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
class SettingsFragment : PreferenceFragmentCompat() {
|
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() {
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||||
ThemeColor.tintPreferenceIcons(preferenceScreen, ThemeColor.getThemeColor(requireContext()))
|
ThemeColor.tintPreferenceIcons(preferenceScreen, ThemeColor.getThemeColor(requireContext()))
|
||||||
|
Loading…
Reference in New Issue
Block a user