Fix shortcuts
This commit is contained in:
parent
ba830e8b67
commit
fc3dbb7fb7
3 changed files with 41 additions and 18 deletions
|
@ -13,10 +13,7 @@ import androidx.compose.animation.core.*
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.rotate
|
import androidx.compose.ui.draw.rotate
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
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
|
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 state by store.state.collectAsState()
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
LaunchedEffect(state.route) {
|
LaunchedEffect(state.route) {
|
||||||
|
@ -147,3 +155,18 @@ fun LoadingSpinner(animate: Boolean = false) {
|
||||||
fun LoadingSpinner_Preview() {
|
fun LoadingSpinner_Preview() {
|
||||||
LoadingSpinner()
|
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"
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
android:shortcutLongLabel="@string/action_disable_5_minutes"
|
android:shortcutLongLabel="@string/action_disable_5_minutes"
|
||||||
android:shortcutShortLabel="@string/action_disable_5_minutes_short">
|
android:shortcutShortLabel="@string/action_disable_5_minutes_short">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_DISABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.DISABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper">
|
android:targetPackage="com.wbrawner.pihelper">
|
||||||
<extra
|
<extra
|
||||||
android:name="com.wbrawner.pihelper.MainFragment.EXTRA_DURATION"
|
android:name="com.wbrawner.pihelper.MainActivityKt.DURATION"
|
||||||
android:value="300" />
|
android:value="300" />
|
||||||
</intent>
|
</intent>
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
@ -23,11 +23,11 @@
|
||||||
android:shortcutLongLabel="@string/action_disable_30_seconds"
|
android:shortcutLongLabel="@string/action_disable_30_seconds"
|
||||||
android:shortcutShortLabel="@string/action_disable_30_seconds_short">
|
android:shortcutShortLabel="@string/action_disable_30_seconds_short">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_DISABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.DISABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper">
|
android:targetPackage="com.wbrawner.pihelper">
|
||||||
<extra
|
<extra
|
||||||
android:name="com.wbrawner.pihelper.MainFragment.EXTRA_DURATION"
|
android:name="com.wbrawner.pihelper.MainActivityKt.DURATION"
|
||||||
android:value="30" />
|
android:value="30" />
|
||||||
</intent>
|
</intent>
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
@ -39,11 +39,11 @@
|
||||||
android:shortcutLongLabel="@string/action_disable_10_seconds"
|
android:shortcutLongLabel="@string/action_disable_10_seconds"
|
||||||
android:shortcutShortLabel="@string/action_disable_10_seconds_short">
|
android:shortcutShortLabel="@string/action_disable_10_seconds_short">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_DISABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.DISABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper">
|
android:targetPackage="com.wbrawner.pihelper">
|
||||||
<extra
|
<extra
|
||||||
android:name="com.wbrawner.pihelper.MainFragment.EXTRA_DURATION"
|
android:name="com.wbrawner.pihelper.MainActivityKt.DURATION"
|
||||||
android:value="10" />
|
android:value="10" />
|
||||||
</intent>
|
</intent>
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
android:shortcutLongLabel="@string/action_enable"
|
android:shortcutLongLabel="@string/action_enable"
|
||||||
android:shortcutShortLabel="@string/action_enable">
|
android:shortcutShortLabel="@string/action_enable">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_ENABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.ENABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper" />
|
android:targetPackage="com.wbrawner.pihelper" />
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:icon="@drawable/ic_shortcut_pause">
|
android:icon="@drawable/ic_shortcut_pause">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_DISABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.DISABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper">
|
android:targetPackage="com.wbrawner.pihelper">
|
||||||
<extra
|
<extra
|
||||||
android:name="com.wbrawner.pihelper.MainFragment.EXTRA_DURATION"
|
android:name="com.wbrawner.pihelper.MainActivityKt.DURATION"
|
||||||
android:value="300" />
|
android:value="300" />
|
||||||
</intent>
|
</intent>
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
@ -17,11 +17,11 @@
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:icon="@drawable/ic_shortcut_pause">
|
android:icon="@drawable/ic_shortcut_pause">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_DISABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.DISABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper">
|
android:targetPackage="com.wbrawner.pihelper">
|
||||||
<extra
|
<extra
|
||||||
android:name="com.wbrawner.pihelper.MainFragment.EXTRA_DURATION"
|
android:name="com.wbrawner.pihelper.MainActivityKt.DURATION"
|
||||||
android:value="30" />
|
android:value="30" />
|
||||||
</intent>
|
</intent>
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
@ -30,11 +30,11 @@
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:icon="@drawable/ic_shortcut_pause">
|
android:icon="@drawable/ic_shortcut_pause">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_DISABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.DISABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper">
|
android:targetPackage="com.wbrawner.pihelper">
|
||||||
<extra
|
<extra
|
||||||
android:name="com.wbrawner.pihelper.MainFragment.EXTRA_DURATION"
|
android:name="com.wbrawner.pihelper.MainActivityKt.DURATION"
|
||||||
android:value="10" />
|
android:value="10" />
|
||||||
</intent>
|
</intent>
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:icon="@drawable/ic_shortcut_enable">
|
android:icon="@drawable/ic_shortcut_enable">
|
||||||
<intent
|
<intent
|
||||||
android:action="com.wbrawner.pihelper.MainFragment.ACTION_ENABLE"
|
android:action="com.wbrawner.pihelper.ShortcutActions.ENABLE"
|
||||||
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
android:targetClass="com.wbrawner.pihelper.MainActivity"
|
||||||
android:targetPackage="com.wbrawner.pihelper" />
|
android:targetPackage="com.wbrawner.pihelper" />
|
||||||
</shortcut>
|
</shortcut>
|
||||||
|
|
Loading…
Reference in a new issue