Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 67559ee

Browse files
committed
add variable to disable start button when application is being killed
1 parent 96e778d commit 67559ee

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

sampleapp/src/main/java/io/matthewnelson/sampleapp/App.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class App: Application() {
8787

8888
companion object {
8989
const val PREFS_NAME = "TOPL-Android_SampleApp"
90+
lateinit var stopTorDelaySettingAtAppStartup: String
91+
private set
9092

9193
/**
9294
* See [io.matthewnelson.sampleapp.topl_android.CodeSamples.generateTorServiceNotificationBuilder]
@@ -190,13 +192,15 @@ class App: Application() {
190192
LibraryPrefs.getNotificationShowSetting(prefs)
191193
)
192194

195+
stopTorDelaySettingAtAppStartup = LibraryPrefs.getControllerStopDelaySetting(prefs).toString()
196+
193197
try {
194198
setupTorServices(
195199
this,
196200
serviceNotificationBuilder,
197201
generateBackgroundManagerPolicy(prefs),
198202
LibraryPrefs.getControllerRestartDelaySetting(prefs),
199-
LibraryPrefs.getControllerStopDelaySetting(prefs),
203+
stopTorDelaySettingAtAppStartup.toLong(),
200204
LibraryPrefs.getControllerDisableStopServiceOnTaskRemovedSetting(prefs),
201205
LibraryPrefs.getControllerBuildConfigDebugSetting(prefs)
202206
)

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/dashboard/DashboardFragment.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import io.matthewnelson.sampleapp.App
2424
import io.matthewnelson.sampleapp.R
2525
import io.matthewnelson.sampleapp.topl_android.MyEventBroadcaster
2626
import io.matthewnelson.sampleapp.ui.MainActivity
27+
import io.matthewnelson.sampleapp.ui.fragments.home.HomeFragment
2728
import io.matthewnelson.sampleapp.ui.fragments.settings.library.LibraryPrefs
2829
import io.matthewnelson.topl_core_base.BaseConsts.TorState
2930
import io.matthewnelson.topl_service.TorServiceController
@@ -125,9 +126,9 @@ class DashboardFragment : Fragment() {
125126
private fun initButtons(context: Context, owner: LifecycleOwner) {
126127
buttonAppRestart.setOnClickListener {
127128
buttonAppRestart.visibility = View.GONE
129+
HomeFragment.appIsBeingKilled()
128130

129131
Toast.makeText(context, "Killing Application", Toast.LENGTH_LONG).show()
130-
val prefs = Prefs.createUnencrypted(App.PREFS_NAME, context)
131132

132133
TorServiceController.appEventBroadcaster?.let {
133134
(it as MyEventBroadcaster).liveTorState.observe(owner, Observer { data ->
@@ -144,7 +145,7 @@ class DashboardFragment : Fragment() {
144145
killAppJob?.cancel()
145146

146147
killAppJob = CoroutineScope(Dispatchers.Main).launch {
147-
delay(1000L + LibraryPrefs.getControllerStopDelaySetting(prefs))
148+
delay(500L + App.stopTorDelaySettingAtAppStartup.toLong())
148149
killApplication(context)
149150
}
150151
}

sampleapp/src/main/java/io/matthewnelson/sampleapp/ui/fragments/home/HomeFragment.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ import io.matthewnelson.topl_service.util.ServiceConsts
8181

8282
class HomeFragment : Fragment() {
8383

84-
private companion object {
85-
var hasDebugLogs = false
84+
companion object {
85+
private var hasDebugLogs = false
86+
private var appIsBeingKilled = false
87+
fun appIsBeingKilled() {
88+
appIsBeingKilled = true
89+
}
8690
}
8791

8892
private lateinit var buttonDebug: Button
@@ -146,6 +150,7 @@ class HomeFragment : Fragment() {
146150
)
147151
}
148152
buttonStart.setOnClickListener {
153+
if (appIsBeingKilled) return@setOnClickListener
149154
try {
150155
TorServiceController.startTor()
151156
} catch (e: RuntimeException) {

0 commit comments

Comments
 (0)