Added dynamic shortcut to epoch converter

This commit is contained in:
Sad Ellie 2023-02-01 19:08:47 +04:00
parent 790457cb6f
commit df3794cad4
2 changed files with 31 additions and 1 deletions

View File

@ -17,6 +17,12 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="@string/epoch_converter">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="app" android:host="com.sadellie.unitto" />
</intent-filter>
</activity>
</application>

View File

@ -18,21 +18,45 @@
package com.sadellie.unitto.feature.epoch.navigation
import android.content.Intent
import android.net.Uri
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.navDeepLink
import com.sadellie.unitto.feature.epoch.EpochRoute
import com.sadellie.unitto.feature.epoch.R
private const val epochRoute = "epoch_route"
fun NavController.navigateToEpoch() {
val shortcut = ShortcutInfoCompat
.Builder(context, epochRoute)
.setLongLabel(context.getString(R.string.epoch_converter))
.setLongLabel(context.getString(R.string.epoch_converter))
.setIntent(
Intent(
Intent.ACTION_VIEW,
Uri.parse("app://com.sadellie.unitto/$epochRoute")
)
)
.build()
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
navigate(epochRoute)
}
fun NavGraphBuilder.epochScreen(
navigateUpAction: () -> Unit
) {
composable(epochRoute) {
composable(
route = epochRoute,
deepLinks = listOf(
navDeepLink { uriPattern = "app://com.sadellie.unitto/$epochRoute" }
)
) {
EpochRoute(
navigateUpAction = navigateUpAction
)