Skip to content
Draft
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/copilot.*
/docs/plans
/docs/android
.DS_Store
/build
/captures
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
<data android:host="*" />
<data android:mimeType="application/vnd.apple.pkpass" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import de.pawcode.cardstore.utils.calculateCardScore
import de.pawcode.cardstore.utils.isLightColor
import kotlinx.coroutines.flow.first

private const val MAX_SHORTCUTS = 3
internal const val SHORTCUT_ACTION = "de.pawcode.cardstore.ACTION_VIEW_CARD"

internal fun cardShortcutId(cardId: String) = "card_shortcut_$cardId"
Expand All @@ -39,9 +38,10 @@ suspend fun updateShortcuts(context: Context) {
SortAttribute.MOST_USED -> allCards.sortedByDescending { it.useCount }
}

val topCards = sortedCards.take(MAX_SHORTCUTS)

val maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context)
val topCards = sortedCards.take(maxShortcuts)
val newShortcutIds = topCards.map { cardShortcutId(it.cardId) }.toSet()

val existingShortcuts = ShortcutManagerCompat.getDynamicShortcuts(context)
val staleIds = existingShortcuts.filter { it.id !in newShortcutIds }.map { it.id }
if (staleIds.isNotEmpty()) ShortcutManagerCompat.removeDynamicShortcuts(context, staleIds)
Expand All @@ -62,6 +62,11 @@ suspend fun updateShortcuts(context: Context) {
.setLongLabel(card.storeName)
.setIcon(icon)
.setIntent(intent)
.addCapabilityBinding(
"actions.intent.OPEN_APP_FEATURE",
"feature.name",
listOf(card.storeName),
)
.build()

ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/xml/shortcuts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<capability android:name="actions.intent.OPEN_APP_FEATURE">
<shortcut-fulfillment>
<parameter android:name="feature.name" />
</shortcut-fulfillment>
<intent
android:action="de.pawcode.cardstore.ACTION_VIEW_CARD"
android:targetClass="de.pawcode.cardstore.CardOverlayActivity" />
</capability>
</shortcuts>
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION_CODE=67
VERSION_CODE=68
VERSION_NAME=1.5.1-staging.3