Crash fixes

parent 8162a25c
Pipeline #475 canceled with stages
in 18 seconds
......@@ -33,7 +33,7 @@ class ClientSettingsActivity : SettingsActivity(ClientSettingsFragment()),
when (pref) {
is ListPreference -> {
val f = ListPreferenceDialogFragmentCompat.newInstance(pref.getKey())
f.setTargetFragment(fragment, 0)
f.setTargetFragment(actualFragment, 0)
f.show(supportFragmentManager, DIALOG_FRAGMENT_TAG)
true
}
......
......@@ -35,6 +35,7 @@ abstract class ServiceBoundSettingsActivity(private val fragment: Fragment? = nu
protected open fun fragment(): Fragment? = null
private var changeable: Changeable? = null
protected var actualFragment: Fragment? = null
@BindView(R.id.toolbar)
lateinit var toolbar: Toolbar
......@@ -48,19 +49,30 @@ abstract class ServiceBoundSettingsActivity(private val fragment: Fragment? = nu
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
val fragment = supportFragmentManager.findFragmentById(R.id.fragment_container)
?: this.fragment
?: this.fragment()
if (fragment != null) {
val transaction = supportFragmentManager.beginTransaction()
fragment.arguments = arguments
transaction.replace(R.id.fragment_container, fragment)
transaction.commit()
val existingFragment = savedInstanceState?.let {
supportFragmentManager.getFragment(it, "settings_content")
}
actualFragment = existingFragment ?: this.fragment ?: this.fragment()
if (existingFragment == null) {
actualFragment?.let {
val transaction = supportFragmentManager.beginTransaction()
it.arguments = arguments
transaction.replace(R.id.fragment_container, it)
transaction.commit()
}
}
this.changeable = fragment as? Changeable
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
actualFragment?.let {
supportFragmentManager.putFragment(outState, "settings_content", it)
}
}
private fun shouldNavigateAway(callback: () -> Unit) {
val changeable = this.changeable
if (changeable?.hasChanged() == true) {
......
......@@ -34,6 +34,7 @@ abstract class SettingsActivity(protected val fragment: Fragment? = null) : Them
protected open fun fragment(): Fragment? = null
private var changeable: Changeable? = null
protected var actualFragment: Fragment? = null
@BindView(R.id.toolbar)
lateinit var toolbar: Toolbar
......@@ -47,19 +48,30 @@ abstract class SettingsActivity(protected val fragment: Fragment? = null) : Them
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
val fragment = supportFragmentManager.findFragmentById(R.id.fragment_container)
?: this.fragment
?: this.fragment()
if (fragment != null) {
val transaction = supportFragmentManager.beginTransaction()
fragment.arguments = arguments
transaction.replace(R.id.fragment_container, fragment)
transaction.commit()
val existingFragment = savedInstanceState?.let {
supportFragmentManager.getFragment(it, "settings_content")
}
actualFragment = existingFragment ?: this.fragment ?: this.fragment()
if (existingFragment == null) {
actualFragment?.let {
val transaction = supportFragmentManager.beginTransaction()
it.arguments = arguments
transaction.replace(R.id.fragment_container, it)
transaction.commit()
}
}
this.changeable = fragment as? Changeable
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
actualFragment?.let {
supportFragmentManager.putFragment(outState, "settings_content", it)
}
}
private fun shouldNavigateAway(callback: () -> Unit) {
val changeable = this.changeable
if (changeable?.hasChanged() == true) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment