Fixes state resetting

parent dd67ed45
......@@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.widget.AppCompatSpinner
......@@ -76,16 +77,34 @@ class ChannelCreateFragment : ServiceBoundSettingsFragment() {
@Inject
lateinit var modelHelper: QuasselViewModelHelper
private var hasSelectedNetwork = false
private var networkId = NetworkId(0)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.add_create, container, false)
ButterKnife.bind(this, view)
val networkId = NetworkId(arguments?.getInt("network_id", 0) ?: 0)
networkId = NetworkId(
savedInstanceState?.getInt("network_id", 0)
?: arguments?.getInt("network_id", 0)
?: 0
)
val networkAdapter = NetworkAdapter()
network.adapter = networkAdapter
network.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
networkId = NetworkId(0)
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
networkId = networkAdapter.getItem(position).id
hasSelectedNetwork = true
}
}
var hasSetNetwork = false
modelHelper.networks.switchMap {
combineLatest(it.values.map(Network::liveNetworkInfo)).map {
......@@ -101,6 +120,7 @@ class ChannelCreateFragment : ServiceBoundSettingsFragment() {
val index = networkAdapter.indexOf(networkId)
if (index != null) {
network.setSelection(index)
hasSelectedNetwork = true
}
}
hasSetNetwork = true
......@@ -190,4 +210,11 @@ class ChannelCreateFragment : ServiceBoundSettingsFragment() {
return view
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (networkId.isValidId() && hasSelectedNetwork) {
outState.putInt("network_id", networkId.id)
}
}
}
......@@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.widget.AppCompatSpinner
......@@ -54,16 +55,34 @@ class ChannelJoinFragment : ServiceBoundFragment() {
@Inject
lateinit var modelHelper: QuasselViewModelHelper
private var hasSelectedNetwork = false
private var networkId = NetworkId(0)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.add_join, container, false)
ButterKnife.bind(this, view)
val networkId = NetworkId(arguments?.getInt("network_id", 0) ?: 0)
networkId = NetworkId(
savedInstanceState?.getInt("network_id", 0)
?: arguments?.getInt("network_id", 0)
?: 0
)
val networkAdapter = NetworkAdapter()
network.adapter = networkAdapter
network.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
networkId = NetworkId(0)
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
networkId = networkAdapter.getItem(position).id
hasSelectedNetwork = true
}
}
var hasSetNetwork = false
modelHelper.networks.switchMap {
combineLatest(it.values.map(Network::liveNetworkInfo)).map {
......@@ -79,6 +98,7 @@ class ChannelJoinFragment : ServiceBoundFragment() {
val index = networkAdapter.indexOf(networkId)
if (index != null) {
network.setSelection(index)
hasSelectedNetwork = true
}
}
hasSetNetwork = true
......@@ -106,4 +126,11 @@ class ChannelJoinFragment : ServiceBoundFragment() {
return view
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (networkId.isValidId() && hasSelectedNetwork) {
outState.putInt("network_id", networkId.id)
}
}
}
......@@ -97,23 +97,33 @@ class QueryCreateFragment : ServiceBoundFragment() {
@Inject
lateinit var modelHelper: QueryCreateViewModelHelper
private var hasSelectedNetwork = false
private var networkId = NetworkId(0)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.add_query, container, false)
ButterKnife.bind(this, view)
val networkId = NetworkId(arguments?.getInt("network_id", 0) ?: 0)
networkId = NetworkId(
savedInstanceState?.getInt("network_id", 0)
?: arguments?.getInt("network_id", 0)
?: 0
)
val networkAdapter = NetworkAdapter()
network.adapter = networkAdapter
network.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onNothingSelected(parent: AdapterView<*>?) {
modelHelper.queryCreate.networkId.onNext(NetworkId(0))
networkId = NetworkId(0)
modelHelper.queryCreate.networkId.onNext(networkId)
}
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
modelHelper.queryCreate.networkId.onNext(networkAdapter.getItem(position).id)
networkId = networkAdapter.getItem(position).id
hasSelectedNetwork = true
modelHelper.queryCreate.networkId.onNext(networkId)
}
}
......@@ -132,6 +142,7 @@ class QueryCreateFragment : ServiceBoundFragment() {
val index = networkAdapter.indexOf(networkId)
if (index != null) {
network.setSelection(index)
hasSelectedNetwork = true
}
}
hasSetNetwork = true
......@@ -318,4 +329,11 @@ class QueryCreateFragment : ServiceBoundFragment() {
)
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (networkId.isValidId() && hasSelectedNetwork) {
outState.putInt("network_id", networkId.id)
}
}
}
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