Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions android/app/src/main/kotlin/com/follow/clash/plugins/AppPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
}

"initShortcuts" -> {
initShortcuts(call.arguments as String)
val labels = call.arguments
if (labels is Map<*, *>) {
@Suppress("UNCHECKED_CAST")
initShortcuts(labels as Map<String, String>)
}
result.success(true)
}

Expand Down Expand Up @@ -190,21 +194,51 @@ class AppPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware
}
}

private fun initShortcuts(label: String) {
val shortcut = with(ShortcutInfoCompat.Builder(GlobalState.application, "toggle")) {
setShortLabel(label)
setIcon(
private fun initShortcuts(labels: Map<String, String>) {
val startLabel = labels["start"] ?: "Start"
val stopLabel = labels["stop"] ?: "Stop"
val toggleLabel = labels["toggle"] ?: return
val shortcuts = listOf(
buildShortcut(
id = "start",
label = startLabel,
action = QuickAction.START,
iconRes = R.drawable.ic_shortcut_start,
),
buildShortcut(
id = "stop",
label = stopLabel,
action = QuickAction.STOP,
iconRes = R.drawable.ic_shortcut_stop,
),
buildShortcut(
id = "toggle",
label = toggleLabel,
action = QuickAction.TOGGLE,
iconRes = R.mipmap.ic_launcher_round,
),
)
ShortcutManagerCompat.setDynamicShortcuts(
GlobalState.application, shortcuts
)
}

private fun buildShortcut(
id: String,
label: String,
action: QuickAction,
iconRes: Int,
): ShortcutInfoCompat {
return ShortcutInfoCompat.Builder(GlobalState.application, id)
.setShortLabel(label)
.setIcon(
IconCompat.createWithResource(
GlobalState.application,
R.mipmap.ic_launcher_round,
iconRes,
)
)
setIntent(QuickAction.TOGGLE.quickIntent)
build()
}
ShortcutManagerCompat.setDynamicShortcuts(
GlobalState.application, listOf(shortcut)
)
.setIntent(action.quickIntent)
.build()
}

private fun tip(message: String?) {
Expand Down
16 changes: 16 additions & 0 deletions android/app/src/main/res/drawable/ic_shortcut_start.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<!-- Background matches the toggle/app adaptive icon (ic_launcher_background)
so Start/Stop shortcuts share the same backdrop as the toggle shortcut. -->
<path
android:pathData="M0,0 L48,0 L48,48 L0,48 Z"
android:fillColor="#FAFAFA"/>
<!-- Brand-blue play triangle glyph, centered like the adaptive-icon logomark -->
<path
android:pathData="M18.5,14 L18.5,34 L36,24 Z"
android:fillColor="#6666FB"/>
</vector>
16 changes: 16 additions & 0 deletions android/app/src/main/res/drawable/ic_shortcut_stop.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<!-- Background matches the toggle/app adaptive icon (ic_launcher_background)
so Start/Stop shortcuts share the same backdrop as the toggle shortcut. -->
<path
android:pathData="M0,0 L48,0 L48,48 L0,48 Z"
android:fillColor="#FAFAFA"/>
<!-- Deep-blue stop square glyph, centered like the adaptive-icon logomark -->
<path
android:pathData="M15,15 L33,15 L33,33 L15,33 Z"
android:fillColor="#336AB6"/>
</vector>
6 changes: 5 additions & 1 deletion lib/plugins/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ class App {
Future<bool?> initShortcuts() async {
return methodChannel.invokeMethod<bool>(
'initShortcuts',
currentAppLocalizations.toggle,
{
'start': currentAppLocalizations.start,
'stop': currentAppLocalizations.stop,
'toggle': currentAppLocalizations.toggle,
},
);
}

Expand Down