@@ -4,8 +4,10 @@ package com.aliucord.manager.ui.screens.install
4
4
5
5
import android.annotation.SuppressLint
6
6
import android.app.Application
7
+ import android.content.Intent
7
8
import android.os.Build
8
9
import android.util.Log
10
+ import androidx.annotation.StringRes
9
11
import androidx.compose.runtime.*
10
12
import cafe.adriel.voyager.core.model.StateScreenModel
11
13
import cafe.adriel.voyager.core.model.screenModelScope
@@ -25,6 +27,7 @@ import kotlinx.coroutines.*
25
27
import kotlinx.coroutines.flow.*
26
28
import java.text.SimpleDateFormat
27
29
import java.util.Date
30
+ import kotlin.time.Duration.Companion.seconds
28
31
29
32
class InstallModel (
30
33
private val application : Application ,
@@ -35,16 +38,35 @@ class InstallModel(
35
38
private var installJob: Job ? = null
36
39
private var stepRunner: StepRunner ? = null
37
40
38
- private var autocloseCancelled: Boolean = false
39
-
40
41
var installSteps by mutableStateOf<ImmutableMap <StepGroup , ImmutableList <Step >>? > (null )
41
42
private set
42
43
43
44
var showGppWarning by mutableStateOf(false )
44
45
private set
45
46
47
+ @get:StringRes
48
+ var funFact by mutableIntStateOf(0 )
49
+ private set
50
+
46
51
init {
47
52
restart()
53
+
54
+ // Rotate fun facts every 20s
55
+ screenModelScope.launch {
56
+ while (true ) {
57
+ funFact = FUN_FACTS .random()
58
+ delay(20 .seconds)
59
+ }
60
+ }
61
+ }
62
+
63
+ fun launchApp () {
64
+ if (state.value !is InstallScreenState .Success )
65
+ return
66
+
67
+ Intent (options.packageName)
68
+ .addFlags(Intent .FLAG_ACTIVITY_NEW_TASK )
69
+ .also (application::startActivity)
48
70
}
49
71
50
72
fun copyDebugToClipboard () {
@@ -68,17 +90,10 @@ class InstallModel(
68
90
}
69
91
70
92
fun clearCache () {
71
- paths.clearCache()
93
+ screenModelScope.launch { paths.clearCache() }
72
94
application.showToast(R .string.action_cleared_cache)
73
95
}
74
96
75
- /* *
76
- * Cancel the screen auto-close once installation was completed
77
- */
78
- fun cancelAutoclose () {
79
- autocloseCancelled = true
80
- }
81
-
82
97
/* *
83
98
* Hide the 'Google Play Protect is enabled on your device' warning dialog
84
99
*/
@@ -130,13 +145,6 @@ class InstallModel(
130
145
// At this point, the installation has successfully completed
131
146
else {
132
147
mutableState.value = InstallScreenState .Success
133
- autocloseCancelled = false
134
-
135
- // Wait 5s before returning to Home if screen hasn't been clicked
136
- delay(5000 )
137
- if (! autocloseCancelled) {
138
- mutableState.value = InstallScreenState .CloseScreen
139
- }
140
148
}
141
149
}
142
150
@@ -188,6 +196,25 @@ class InstallModel(
188
196
SOC: $soc
189
197
""" .trimIndent()
190
198
191
- return header + " \n\n " + Log .getStackTraceString(stacktrace)
199
+ return header + " \n\n " + Log .getStackTraceString(stacktrace).trimEnd()
200
+ }
201
+
202
+ private companion object {
203
+ /* *
204
+ * Random fun facts to show on the installation screen.
205
+ */
206
+ val FUN_FACTS = arrayOf(
207
+ R .string.fun_fact_1,
208
+ R .string.fun_fact_2,
209
+ R .string.fun_fact_3,
210
+ R .string.fun_fact_4,
211
+ R .string.fun_fact_5,
212
+ R .string.fun_fact_6,
213
+ R .string.fun_fact_7,
214
+ R .string.fun_fact_8,
215
+ R .string.fun_fact_9,
216
+ R .string.fun_fact_10,
217
+ R .string.fun_fact_11,
218
+ )
192
219
}
193
220
}
0 commit comments