Skip to content
Snippets Groups Projects
Verified Commit 00410a83 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Properly keep state in irc:// setup activity

parent dd7c4093
No related branches found
No related tags found
No related merge requests found
......@@ -248,8 +248,10 @@ abstract class ServiceBoundSetupActivity :
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
super.onRestoreInstanceState(savedInstanceState)
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(resultKey))
if (savedInstanceState.containsKey(resultKey)) {
adapter.result.putAll(savedInstanceState.getBundle(resultKey))
adapter.allChanged()
}
if (savedInstanceState.containsKey(lastValidItemKey))
adapter.lastValidItem = savedInstanceState.getInt(lastValidItemKey)
if (savedInstanceState.containsKey(currentItemKey))
......
......@@ -209,8 +209,10 @@ abstract class SetupActivity : DaggerAppCompatActivity() {
override fun onRestoreInstanceState(savedInstanceState: Bundle?) {
super.onRestoreInstanceState(savedInstanceState)
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(resultKey))
if (savedInstanceState.containsKey(resultKey)) {
adapter.result.putAll(savedInstanceState.getBundle(resultKey))
adapter.allChanged()
}
if (savedInstanceState.containsKey(lastValidItemKey))
adapter.lastValidItem = savedInstanceState.getInt(lastValidItemKey)
if (savedInstanceState.containsKey(currentItemKey))
......
......@@ -49,7 +49,7 @@ class SlidePagerAdapter(private val fragmentManager: FragmentManager) :
return retainedFragments.get(position) ?: list[position]
}
override fun getCount() = Math.min(list.size, lastValidItem + 2)
override fun getCount() = minOf(list.size, lastValidItem + 2)
val totalCount get() = list.size
fun addFragment(fragment: SlideFragment) {
list.add(fragment)
......@@ -90,9 +90,15 @@ class SlidePagerAdapter(private val fragmentManager: FragmentManager) :
retainedFragments.put(index, fragment)
}
fun allChanged() {
for (index in 0 until totalCount) {
hasChanged(index, getItem(index))
}
}
fun hasChanged(index: Int, fragment: SlideFragment) {
fragment.getData(result)
if (index > -1 && index < totalCount) {
if (index > -1 && (index + 1) < totalCount) {
getItem(index + 1).setData(result)
}
}
......
......@@ -123,6 +123,7 @@ class NetworkSetupNetworkSlide : ServiceBoundSlideFragment() {
)
)
)
data.putInt("network_id", -1)
}
}
......@@ -225,16 +226,21 @@ class NetworkSetupNetworkSlide : ServiceBoundSlideFragment() {
networkAdapter.submitList(listOf(null) + networks)
val linkNetwork = data.getSerializable("network") as? LinkNetwork
val existingNetwork = networks.firstOrNull {
it.serverList.any {
it.host == linkNetwork?.server?.host
val selectedNetworkId = if (data.containsKey("network_id")) {
data.getInt("network_id")
} else {
val existingNetwork = networks.firstOrNull {
it.serverList.any {
it.host == linkNetwork?.server?.host
}
}
existingNetwork?.networkId
}
val selectedNetworkPosition = networkAdapter.indexOf(selectedNetworkId ?: -1) ?: -1
if (!hasSetNetwork) {
val networkPosition = networkAdapter.indexOf(existingNetwork?.networkId ?: -1) ?: -1
if (networkPosition != -1) {
network.setSelection(networkPosition)
if (selectedNetworkPosition != -1 || selectedNetworkId == -1) {
network.setSelection(selectedNetworkPosition)
hasSetNetwork = true
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment