Commit 82c3654f authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Update lifecycle library

parent f1696852
......@@ -128,6 +128,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
implementation 'com.frostnerd.utilskt:lifecycle:1.2.0'
implementation 'com.frostnerd.utilskt:preferences:1.5.29' // https://git.frostnerd.com/AndroidUtils/preferenceskt
implementation 'com.frostnerd.utilskt:navigationdraweractivity:1.4.0' // https://git.frostnerd.com/AndroidUtils/navigationdraweractivity
implementation 'com.frostnerd.utilskt:encrypteddnstunnelproxy:1.6.5' // https://git.frostnerd.com/AndroidUtils/encrypteddnstunnelproxy
......
......@@ -92,7 +92,7 @@ class MainActivity : NavigationDrawerActivity() {
setCardView { viewParent, suggestedHeight ->
val view = layoutInflater.inflate(R.layout.menu_cardview, viewParent, false)
val update = {
launchWithLifecycle(false) {
launchWithLifecycle {
val server = getPreferences().dnsServerConfig
val primaryAddress = server.servers.first().address.addressCreator.resolveOrGetResultOrNull(
retryIfError = true,
......
......@@ -16,6 +16,7 @@ import com.frostnerd.encrypteddnstunnelproxy.tls.AbstractTLSDnsHandle
import com.frostnerd.lifecyclemanagement.BaseActivity
import com.frostnerd.lifecyclemanagement.BaseViewHolder
import com.frostnerd.lifecyclemanagement.launchWithLifecycle
import com.frostnerd.lifecyclemanagement.launchWithLifecycleUi
import com.frostnerd.smokescreen.*
import com.frostnerd.smokescreen.util.LanguageContextWrapper
import com.frostnerd.smokescreen.util.SpaceItemDecorator
......@@ -110,7 +111,7 @@ class SpeedTestActivity : BaseActivity() {
}
private fun prepareList() {
prepareListJob = launchWithLifecycle(true) {
prepareListJob = launchWithLifecycleUi {
val hiddenDotServers = getPreferences().removedDefaultDoTServers
val hiddenDohServers = getPreferences().removedDefaultDoHServers
val hasIpv4 = hasDeviceIpv4Address()
......@@ -169,7 +170,7 @@ class SpeedTestActivity : BaseActivity() {
private fun startTest() {
if(wasStartedBefore) prepareList()
testJob = launchWithLifecycle(false) {
testJob = launchWithLifecycle {
prepareListJob?.join()
testRunning = true
wasStartedBefore = true
......
......@@ -97,7 +97,7 @@ class DnsRuleFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
userRulesJob = launchWithLifecycle(false) {
userRulesJob = launchWithLifecycle {
userDnsRules = getDatabase().dnsRuleDao().getAllUserRules().toMutableList()
userRulesJob = null
launch {
......@@ -308,7 +308,7 @@ class DnsRuleFragment : Fragment() {
}
}
if(userRulesJob == null) changeVisibility()
else launchWithLifecycle(false) {
else launchWithLifecycle {
userRulesJob?.join()
changeVisibility()
}
......@@ -422,7 +422,7 @@ class DnsRuleFragment : Fragment() {
}
})
}
data.enabled -> launchWithLifecycle(false) {
data.enabled -> launchWithLifecycle {
val prev = sourceRuleCount[data]
sourceRuleCount[data] = getDatabase().dnsRuleDao().getCountForHostSource(data.id)
if(prev != sourceRuleCount[data]) runOnUiThread {
......@@ -491,12 +491,12 @@ class DnsRuleFragment : Fragment() {
refreshProgress.hide()
refreshProgressShown = false
launchWithLifecycle(false) {
launchWithLifecycle {
sourceRuleCount.keys.forEach {
val index = sourceAdapterList.indexOf(it)
if(index >= 0 && (sourceAdapterList[index].enabled || sourceRuleCount[it] != null)) {
sourceRuleCount[it] = null
launchWithLifecycle(true) {
launchUi {
sourceAdapter.notifyItemChanged(index)
}
} else sourceRuleCount[it] = null
......
......@@ -270,9 +270,9 @@ class MainFragment : Fragment() {
private fun updatePrivacyPolicyLink(serverInfo: DnsServerInformation<*>) {
activity?.let { activity ->
if (!serverInfo.specification.privacyPolicyURL.isNullOrBlank()) {
LifecycleCoroutineScope(activity, ui = false).launch {
launchWithLifecycle {
val url = URL(serverInfo.specification.privacyPolicyURL)
launchWithLifecycle(true) {
launchUi {
val text = view?.findViewById<TextView>(R.id.privacyStatementText)
text?.text =
getString(
......@@ -284,7 +284,7 @@ class MainFragment : Fragment() {
}
}
} else {
LifecycleCoroutineScope(activity, ui = true).launch {
launchWithLifecycleUi {
val text = view?.findViewById<TextView>(R.id.privacyStatementText)
text?.visibility = View.GONE
}
......
......@@ -21,6 +21,7 @@ import com.frostnerd.general.isInt
import com.frostnerd.general.service.isServiceRunning
import com.frostnerd.lifecyclemanagement.LifecycleCoroutineScope
import com.frostnerd.lifecyclemanagement.launchWithLifecycle
import com.frostnerd.lifecyclemanagement.launchWithLifecycleUi
import com.frostnerd.smokescreen.*
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.activity.MainActivity
......@@ -282,10 +283,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
if(context != null) {
val dialog = LoadingDialog(context, R.string.title_check_iptables, R.string.dialog_doh_detect_type_message)
dialog.show()
launchWithLifecycle(false) {
launchWithLifecycle {
val supported = processSuCommand("iptables -t nat -L OUTPUT", context.logger)
val ipv6Supported = processSuCommand("ip6tables -t nat -L PREROUTING", context.logger)
launchWithLifecycle(true) {
launchWithLifecycleUi {
dialog.dismiss()
val text = if(supported) {
if(ipv6Supported) R.string.iptables_supported
......@@ -632,7 +633,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
fun Context.showLogExportDialog(onDismiss: (() -> Unit)? = null) {
log("Trying to send logs..")
val scope = if (this is LifecycleOwner) LifecycleCoroutineScope(this, ui = false)
val scope = if (this is LifecycleOwner) LifecycleCoroutineScope(this)
else GlobalScope
val loadingDialog = LoadingDialog(this, R.string.dialog_logexport_loading_title).also {
......
......@@ -13,6 +13,7 @@ import com.frostnerd.cacheadapter.DefaultViewHolder
import com.frostnerd.cacheadapter.ModelAdapterBuilder
import com.frostnerd.dnstunnelproxy.QueryListener
import com.frostnerd.lifecyclemanagement.launchWithLifecycle
import com.frostnerd.lifecyclemanagement.launchWithLifecycleUi
import com.frostnerd.smokescreen.BackpressFragment
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.database.entities.DnsQuery
......@@ -62,11 +63,11 @@ class QueryLogListFragment: Fragment(), SearchView.OnQueryTextListener, Backpres
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
launchWithLifecycle(false) {
launchWithLifecycle {
val live = requireContext().getDatabase().dnsQueryDao().getAllLive()
unfilteredAdapter = createAdapter(LiveDataSource(this@QueryLogListFragment, live, true))
launchWithLifecycle(true) {
launchWithLifecycleUi {
list.layoutManager = LinearLayoutManager(requireContext())
list.adapter = unfilteredAdapter
progress.visibility = View.GONE
......@@ -135,11 +136,11 @@ class QueryLogListFragment: Fragment(), SearchView.OnQueryTextListener, Backpres
}
private fun updateAdapter() {
launchWithLifecycle(true) {
launchWithLifecycleUi {
view?.progress?.visibility = View.VISIBLE
launchWithLifecycle(ui = false) {
launchWithLifecycle {
val updatedAdapter = createUpdatedAdapter()
launchWithLifecycle(true) {
launchWithLifecycleUi {
view?.progress?.visibility = View.GONE
list.adapter = updatedAdapter
}
......
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