Skip to content

Commit

Permalink
feat: add qsTile intent (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Dec 16, 2024
1 parent a0654ee commit a0b280d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
</intent-filter>
</activity>

<activity
Expand Down
38 changes: 29 additions & 9 deletions app/src/main/kotlin/li/songe/gkd/ui/home/HomePage.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package li.songe.gkd.ui.home

import android.content.ComponentName
import android.content.Intent
import android.os.Build
import android.service.quicksettings.TileService
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
Expand All @@ -25,8 +29,12 @@ import kotlinx.coroutines.delay
import li.songe.gkd.MainActivity
import li.songe.gkd.OpenFileActivity
import li.songe.gkd.data.importData
import li.songe.gkd.debug.FloatingTileService
import li.songe.gkd.debug.HttpTileService
import li.songe.gkd.debug.SnapshotTileService
import li.songe.gkd.util.LocalNavController
import li.songe.gkd.util.ProfileTransitions
import li.songe.gkd.util.componentName
import li.songe.gkd.util.launchTry
import li.songe.gkd.util.toast

Expand Down Expand Up @@ -56,15 +64,8 @@ fun HomePage() {
val intent = context.intent ?: return@LaunchedEffect
context.intent = null
LogUtils.d(intent)
val uri = intent.data?.normalizeScheme() ?: return@LaunchedEffect
val source = intent.getStringExtra("source")
if (source == OpenFileActivity::class.qualifiedName) {
vm.viewModelScope.launchTry(Dispatchers.IO) {
toast("加载导入...")
vm.tabFlow.value = subsPage.navItem
importData(uri)
}
} else if (uri.scheme == "gkd" && uri.host == "page") {
val uri = intent.data?.normalizeScheme()
if (uri != null && uri.scheme == "gkd" && uri.host == "page") {
delay(200)
when (uri.path) {
"/1" -> {
Expand All @@ -75,6 +76,25 @@ fun HomePage() {
navController.toDestinationsNavigator().navigate(SnapshotPageDestination)
}
}
} else if (uri != null && intent.getStringExtra("source") == OpenFileActivity::class.qualifiedName) {
vm.viewModelScope.launchTry(Dispatchers.IO) {
toast("加载导入...")
vm.tabFlow.value = subsPage.navItem
importData(uri)
}
} else if (intent.action == TileService.ACTION_QS_TILE_PREFERENCES) {
val qsTileCpt = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME, ComponentName::class.java)
} else {
@Suppress("DEPRECATION")
intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME) as ComponentName?
} ?: return@LaunchedEffect
delay(200)
if (qsTileCpt == HttpTileService::class.componentName || qsTileCpt == FloatingTileService::class.componentName) {
navController.toDestinationsNavigator().navigate(AdvancedPageDestination)
} else if (qsTileCpt == SnapshotTileService::class.componentName) {
navController.toDestinationsNavigator().navigate(SnapshotPageDestination)
}
}
})

Expand Down

0 comments on commit a0b280d

Please sign in to comment.