Stop using deprecated launchWhenX

This commit is contained in:
Mygod
2023-03-02 22:00:18 -05:00
parent b123aa8b43
commit 94fd4cc45b
7 changed files with 65 additions and 37 deletions

View File

@@ -10,12 +10,14 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.core.os.bundleOf
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.withStarted
import androidx.preference.EditTextPreferenceDialogFragmentCompat
import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.util.Services
import be.mygod.vpnhotspot.util.allInterfaceNames
import be.mygod.vpnhotspot.util.globalNetworkRequestBuilder
import be.mygod.vpnhotspot.widget.AlwaysAutoCompleteEditText
import kotlinx.coroutines.launch
class AutoCompleteNetworkPreferenceDialogFragment : EditTextPreferenceDialogFragmentCompat() {
fun setArguments(key: String) {
@@ -33,12 +35,16 @@ class AutoCompleteNetworkPreferenceDialogFragment : EditTextPreferenceDialogFrag
private val callback = object : ConnectivityManager.NetworkCallback() {
override fun onLinkPropertiesChanged(network: Network, properties: LinkProperties) {
interfaceNames[network] = properties.allInterfaceNames
lifecycleScope.launchWhenStarted { updateAdapter() }
lifecycleScope.launch {
withStarted { updateAdapter() }
}
}
override fun onLost(network: Network) {
interfaceNames.remove(network)
lifecycleScope.launchWhenStarted { updateAdapter() }
lifecycleScope.launch {
withStarted { updateAdapter() }
}
}
}

View File

@@ -8,7 +8,6 @@ import android.text.style.StyleSpan
import android.util.AttributeSet
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import be.mygod.vpnhotspot.R
import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor
@@ -67,7 +66,7 @@ class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(co
FallbackUpstreamMonitor.unregisterCallback(fallback)
}
private fun onUpdate() = (context as LifecycleOwner).lifecycleScope.launchWhenStarted {
private fun onUpdate() {
summary = context.getText(R.string.settings_service_upstream_monitor_summary).format(
context.resources.configuration.locales[0], primary.charSequence, fallback.charSequence)
}