From 33ee1825cf6bf76aab9cd5c1cc94e3dfcb9a594e Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 29 May 2022 21:52:54 +0100 Subject: [PATCH] adding smalltalk to the targetted share menu --- app/src/main/AndroidManifest.xml | 5 +++++ app/src/main/res/xml/shortcuts.xml | 7 +++++++ .../app/dapk/st/directory/ShortcutHandler.kt | 14 ++++++++++---- .../app/dapk/st/messenger/MessengerActivity.kt | 4 +++- .../share-entry/src/main/AndroidManifest.xml | 4 ++++ .../app/dapk/st/share/ShareEntryActivity.kt | 17 +---------------- 6 files changed, 30 insertions(+), 21 deletions(-) create mode 100644 app/src/main/res/xml/shortcuts.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fe65c3e..6e493a2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,11 @@ + + + diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml new file mode 100644 index 0000000..e727fee --- /dev/null +++ b/app/src/main/res/xml/shortcuts.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/features/directory/src/main/kotlin/app/dapk/st/directory/ShortcutHandler.kt b/features/directory/src/main/kotlin/app/dapk/st/directory/ShortcutHandler.kt index c5dd83d..87b4980 100644 --- a/features/directory/src/main/kotlin/app/dapk/st/directory/ShortcutHandler.kt +++ b/features/directory/src/main/kotlin/app/dapk/st/directory/ShortcutHandler.kt @@ -2,6 +2,7 @@ package app.dapk.st.directory import android.content.Context import android.content.pm.ShortcutInfo +import androidx.core.app.Person import androidx.core.content.pm.ShortcutInfoCompat import androidx.core.content.pm.ShortcutManagerCompat import app.dapk.st.matrix.common.RoomId @@ -14,21 +15,26 @@ class ShortcutHandler(private val context: Context) { fun onDirectoryUpdate(overviews: List) { val update = overviews.map { it.roomId } - if (cachedRoomIds != update) { cachedRoomIds.clear() cachedRoomIds.addAll(update) - val currentShortcuts = ShortcutManagerCompat.getShortcuts(context, ShortcutManagerCompat.FLAG_MATCH_DYNAMIC) val maxShortcutCountPerActivity = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context) - overviews .take(maxShortcutCountPerActivity) - .filterNot { roomUpdate -> currentShortcuts.any { it.id == roomUpdate.roomId.value } } .forEachIndexed { index, room -> val build = ShortcutInfoCompat.Builder(context, room.roomId.value) .setShortLabel(room.roomName ?: "N/A") + .setLongLabel(room.roomName ?: "N/A") .setRank(index) + .run { + this.setPerson( + Person.Builder() + .setName(room.roomName ?: "N/A") + .setKey(room.roomId.value) + .build() + ) + } .setIntent(MessengerActivity.newShortcutInstance(context, room.roomId)) .setLongLived(true) .setCategories(setOf(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)) diff --git a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerActivity.kt b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerActivity.kt index 52fbff7..712842f 100644 --- a/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerActivity.kt +++ b/features/messenger/src/main/kotlin/app/dapk/st/messenger/MessengerActivity.kt @@ -54,4 +54,6 @@ data class MessagerActivityPayload( val roomId: String ) : Parcelable -fun Activity.readPayload(): T = intent.getParcelableExtra("key")!! \ No newline at end of file +fun Activity.readPayload(): T = intent.getParcelableExtra("key") ?: intent.getStringExtra("shortcut_key")!!.let { + MessagerActivityPayload(it) as T +} \ No newline at end of file diff --git a/features/share-entry/src/main/AndroidManifest.xml b/features/share-entry/src/main/AndroidManifest.xml index 5f09028..2a83f28 100644 --- a/features/share-entry/src/main/AndroidManifest.xml +++ b/features/share-entry/src/main/AndroidManifest.xml @@ -19,6 +19,10 @@ + + diff --git a/features/share-entry/src/main/kotlin/app/dapk/st/share/ShareEntryActivity.kt b/features/share-entry/src/main/kotlin/app/dapk/st/share/ShareEntryActivity.kt index 20de044..672188e 100644 --- a/features/share-entry/src/main/kotlin/app/dapk/st/share/ShareEntryActivity.kt +++ b/features/share-entry/src/main/kotlin/app/dapk/st/share/ShareEntryActivity.kt @@ -11,22 +11,7 @@ class ShareEntryActivity : DapkActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val urisToShare = intent.readSendUrisOrNull() ?: throw IllegalArgumentException("") - - // display list of rooms/converations - -// homeViewModel.events.onEach { -// when (it) { -// HomeEvent.Relaunch -> recreate() -// } -// }.launchIn(lifecycleScope) -// -// setContent { -// if (homeViewModel.hasVersionChanged()) { -// BetaUpgradeDialog() -// } else { -// HomeScreen(homeViewModel) -// } -// } + } }