diff --git a/app/src/main/java/com/wbrawner/pihelper/MainActivity.kt b/app/src/main/java/com/wbrawner/pihelper/MainActivity.kt index bd619a0..b8c191c 100644 --- a/app/src/main/java/com/wbrawner/pihelper/MainActivity.kt +++ b/app/src/main/java/com/wbrawner/pihelper/MainActivity.kt @@ -13,10 +13,7 @@ import androidx.compose.animation.core.* import androidx.compose.foundation.Image import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.draw.rotate import androidx.compose.ui.graphics.ColorFilter @@ -62,6 +59,17 @@ class MainActivity : AppCompatActivity() { View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR } } + val launchIntent = remember { intent } + LaunchedEffect(launchIntent) { + ShortcutActions.fromIntentAction(launchIntent.action)?.let { action -> + if (action == ShortcutActions.DISABLE) { + val duration = launchIntent.getIntExtra(DURATION, 0) + store.dispatch(Action.Disable(duration.toLong())) + } else { + store.dispatch(Action.Enable) + } + } + } val state by store.state.collectAsState() val navController = rememberNavController() LaunchedEffect(state.route) { @@ -147,3 +155,18 @@ fun LoadingSpinner(animate: Boolean = false) { fun LoadingSpinner_Preview() { LoadingSpinner() } + +enum class ShortcutActions(val fullName: String) { + ENABLE("com.wbrawner.pihelper.ShortcutActions.ENABLE"), + DISABLE("com.wbrawner.pihelper.ShortcutActions.DISABLE"); + + companion object { + fun fromIntentAction(action: String?): ShortcutActions? = when (action) { + ENABLE.fullName -> ENABLE + DISABLE.fullName -> DISABLE + else -> null + } + } +} + +const val DURATION: String = "com.wbrawner.pihelper.MainActivityKt.DURATION" diff --git a/app/src/main/res/xml-v25/shortcuts.xml b/app/src/main/res/xml-v25/shortcuts.xml index cd59e46..3885cdd 100644 --- a/app/src/main/res/xml-v25/shortcuts.xml +++ b/app/src/main/res/xml-v25/shortcuts.xml @@ -7,11 +7,11 @@ android:shortcutLongLabel="@string/action_disable_5_minutes" android:shortcutShortLabel="@string/action_disable_5_minutes_short"> @@ -23,11 +23,11 @@ android:shortcutLongLabel="@string/action_disable_30_seconds" android:shortcutShortLabel="@string/action_disable_30_seconds_short"> @@ -39,11 +39,11 @@ android:shortcutLongLabel="@string/action_disable_10_seconds" android:shortcutShortLabel="@string/action_disable_10_seconds_short"> @@ -55,7 +55,7 @@ android:shortcutLongLabel="@string/action_enable" android:shortcutShortLabel="@string/action_enable"> diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml index 9b7a7c4..034714d 100644 --- a/app/src/main/res/xml/shortcuts.xml +++ b/app/src/main/res/xml/shortcuts.xml @@ -4,11 +4,11 @@ android:enabled="true" android:icon="@drawable/ic_shortcut_pause"> @@ -17,11 +17,11 @@ android:enabled="true" android:icon="@drawable/ic_shortcut_pause"> @@ -30,11 +30,11 @@ android:enabled="true" android:icon="@drawable/ic_shortcut_pause"> @@ -43,7 +43,7 @@ android:enabled="true" android:icon="@drawable/ic_shortcut_enable">