@@ -18,7 +18,6 @@ import com.ramcosta.composedestinations.spec.Direction
18
18
import io.ktor.client.request.get
19
19
import io.ktor.client.statement.bodyAsText
20
20
import kotlinx.coroutines.Dispatchers
21
- import kotlinx.coroutines.delay
22
21
import kotlinx.coroutines.flow.MutableStateFlow
23
22
import kotlinx.coroutines.flow.update
24
23
import kotlinx.coroutines.launch
@@ -30,27 +29,17 @@ import li.songe.gkd.data.importData
30
29
import li.songe.gkd.db.DbSet
31
30
import li.songe.gkd.permission.AuthReason
32
31
import li.songe.gkd.permission.shizukuOkState
33
- import li.songe.gkd.service.ButtonTileService
34
- import li.songe.gkd.service.HttpTileService
35
- import li.songe.gkd.service.MatchTileService
36
- import li.songe.gkd.service.RecordTileService
37
- import li.songe.gkd.service.SnapshotTileService
38
32
import li.songe.gkd.shizuku.execCommandForResult
39
33
import li.songe.gkd.store.createTextFlow
40
34
import li.songe.gkd.ui.component.AlertDialogOptions
41
35
import li.songe.gkd.ui.component.InputSubsLinkOption
42
36
import li.songe.gkd.ui.component.RuleGroupState
43
37
import li.songe.gkd.ui.component.UploadOptions
44
38
import li.songe.gkd.ui.home.BottomNavItem
45
- import li.songe.gkd.ui.home.appListNav
46
- import li.songe.gkd.ui.home.controlNav
47
- import li.songe.gkd.ui.home.subsNav
48
39
import li.songe.gkd.util.LOCAL_SUBS_ID
49
40
import li.songe.gkd.util.UpdateStatus
50
41
import li.songe.gkd.util.clearCache
51
42
import li.songe.gkd.util.client
52
- import li.songe.gkd.util.componentName
53
- import li.songe.gkd.util.extraCptName
54
43
import li.songe.gkd.util.launchTry
55
44
import li.songe.gkd.util.openUri
56
45
import li.songe.gkd.util.openWeChatScaner
@@ -167,16 +156,16 @@ class MainViewModel : ViewModel() {
167
156
}
168
157
169
158
val appListKeyFlow = MutableStateFlow (0 )
170
- val tabFlow = MutableStateFlow (controlNav )
159
+ val tabFlow = MutableStateFlow (BottomNavItem . Control .key )
171
160
private var lastClickTabTime = 0L
172
161
fun updateTab (navItem : BottomNavItem ) {
173
- if (navItem == appListNav && navItem == tabFlow.value) {
162
+ if (navItem == BottomNavItem . AppList && navItem.key == tabFlow.value) {
174
163
// double click
175
164
if (System .currentTimeMillis() - lastClickTabTime < 500 ) {
176
165
appListKeyFlow.update { it + 1 }
177
166
}
178
167
}
179
- tabFlow.value = navItem
168
+ tabFlow.value = navItem.key
180
169
lastClickTabTime = System .currentTimeMillis()
181
170
}
182
171
@@ -205,7 +194,13 @@ class MainViewModel : ViewModel() {
205
194
val notFoundToast = { toast(" 未知URI\n ${uri} " ) }
206
195
when (uri.host) {
207
196
" page" -> when (uri.path) {
208
- " " -> {}
197
+ " " -> {
198
+ val tab = uri.getQueryParameter(" tab" )?.toIntOrNull()
199
+ if (tab != null && BottomNavItem .allSubObjects.any { it.key == tab }) {
200
+ tabFlow.value = tab
201
+ }
202
+ }
203
+
209
204
" /1" -> navigatePage(AdvancedPageDestination )
210
205
" /2" -> navigatePage(SnapshotPageDestination ())
211
206
else -> notFoundToast()
@@ -222,42 +217,14 @@ class MainViewModel : ViewModel() {
222
217
223
218
fun handleIntent (intent : Intent ) = viewModelScope.launchTry {
224
219
LogUtils .d(" handleIntent" , intent)
225
- val sourceName = intent.getStringExtra(activityNavSourceName)
226
220
val uri = intent.data?.normalizeScheme()
227
- when (sourceName) {
228
- OpenSchemeActivity ::class .jvmName -> {
229
- if (uri?.scheme == " gkd" ) {
230
- delay(200 )
231
- handleGkdUri(uri)
232
- }
233
- }
234
-
235
- OpenFileActivity ::class .jvmName -> {
236
- if (uri != null ) {
237
- toast(" 加载导入中..." )
238
- tabFlow.value = subsNav
239
- withContext(Dispatchers .IO ) { importData(uri) }
240
- }
241
- }
242
-
243
- OpenTileActivity ::class .jvmName -> {
244
- val qsTileCpt = intent.extraCptName
245
- when (qsTileCpt) {
246
- HttpTileService ::class .componentName, ButtonTileService ::class .componentName, RecordTileService ::class .componentName -> {
247
- delay(200 )
248
- navigatePage(AdvancedPageDestination )
249
- }
250
-
251
- SnapshotTileService ::class .componentName -> {
252
- delay(200 )
253
- navigatePage(SnapshotPageDestination )
254
- }
255
-
256
- MatchTileService ::class .componentName -> {
257
- tabFlow.value = subsNav
258
- }
259
- }
260
- }
221
+ val source = intent.getStringExtra(activityNavSourceName)
222
+ if (uri?.scheme == " gkd" ) {
223
+ handleGkdUri(uri)
224
+ } else if (source == OpenFileActivity ::class .jvmName && uri != null ) {
225
+ toast(" 加载导入中..." )
226
+ tabFlow.value = BottomNavItem .SubsManage .key
227
+ withContext(Dispatchers .IO ) { importData(uri) }
261
228
}
262
229
}
263
230
0 commit comments