ui: set selected tunnel after creating fragments
I'm not sure why that comment (Samuel's) was there saying it was necessary. Given it's been async for a long while, this wasn't guaranteed anyway. So let's get rid of it and see what happens. Screen rotation seems fine thus far. Cc: Samuel Holland <samuel@sholland.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
f3107e349c
commit
763d9a9f17
@ -7,9 +7,7 @@ package com.wireguard.android.activity
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.databinding.CallbackRegistry
|
import androidx.databinding.CallbackRegistry
|
||||||
import androidx.databinding.CallbackRegistry.NotifierCallback
|
import androidx.databinding.CallbackRegistry.NotifierCallback
|
||||||
import androidx.lifecycle.Lifecycle
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
|
||||||
import com.wireguard.android.Application
|
import com.wireguard.android.Application
|
||||||
import com.wireguard.android.model.ObservableTunnel
|
import com.wireguard.android.model.ObservableTunnel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -33,6 +31,8 @@ abstract class BaseActivity : ThemeChangeAwareActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
// Restore the saved tunnel if there is one; otherwise grab it from the arguments.
|
// Restore the saved tunnel if there is one; otherwise grab it from the arguments.
|
||||||
val savedTunnelName = when {
|
val savedTunnelName = when {
|
||||||
savedInstanceState != null -> savedInstanceState.getString(KEY_SELECTED_TUNNEL)
|
savedInstanceState != null -> savedInstanceState.getString(KEY_SELECTED_TUNNEL)
|
||||||
@ -41,15 +41,10 @@ abstract class BaseActivity : ThemeChangeAwareActivity() {
|
|||||||
}
|
}
|
||||||
if (savedTunnelName != null)
|
if (savedTunnelName != null)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
||||||
selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName]
|
selectedTunnel = Application.getTunnelManager().getTunnels()[savedTunnelName]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The selected tunnel must be set before the superclass method recreates fragments.
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
if (selectedTunnel != null) outState.putString(KEY_SELECTED_TUNNEL, selectedTunnel!!.name)
|
if (selectedTunnel != null) outState.putString(KEY_SELECTED_TUNNEL, selectedTunnel!!.name)
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
|
Loading…
Reference in New Issue
Block a user