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

Update lifecycle library

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