adding smalltalk to the targetted share menu
This commit is contained in:
parent
2ca96f21d2
commit
33ee1825cf
|
@ -20,6 +20,11 @@
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.shortcuts"
|
||||||
|
android:resource="@xml/shortcuts" />
|
||||||
|
|
||||||
</activity-alias>
|
</activity-alias>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<share-target android:targetClass="app.dapk.st.share.ShareEntryActivity">
|
||||||
|
<data android:mimeType="image/*" />
|
||||||
|
<category android:name="android.shortcut.conversation" />
|
||||||
|
</share-target>
|
||||||
|
</shortcuts>
|
|
@ -2,6 +2,7 @@ package app.dapk.st.directory
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.ShortcutInfo
|
import android.content.pm.ShortcutInfo
|
||||||
|
import androidx.core.app.Person
|
||||||
import androidx.core.content.pm.ShortcutInfoCompat
|
import androidx.core.content.pm.ShortcutInfoCompat
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
import app.dapk.st.matrix.common.RoomId
|
import app.dapk.st.matrix.common.RoomId
|
||||||
|
@ -14,21 +15,26 @@ class ShortcutHandler(private val context: Context) {
|
||||||
|
|
||||||
fun onDirectoryUpdate(overviews: List<RoomOverview>) {
|
fun onDirectoryUpdate(overviews: List<RoomOverview>) {
|
||||||
val update = overviews.map { it.roomId }
|
val update = overviews.map { it.roomId }
|
||||||
|
|
||||||
if (cachedRoomIds != update) {
|
if (cachedRoomIds != update) {
|
||||||
cachedRoomIds.clear()
|
cachedRoomIds.clear()
|
||||||
cachedRoomIds.addAll(update)
|
cachedRoomIds.addAll(update)
|
||||||
|
|
||||||
val currentShortcuts = ShortcutManagerCompat.getShortcuts(context, ShortcutManagerCompat.FLAG_MATCH_DYNAMIC)
|
|
||||||
val maxShortcutCountPerActivity = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context)
|
val maxShortcutCountPerActivity = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context)
|
||||||
|
|
||||||
overviews
|
overviews
|
||||||
.take(maxShortcutCountPerActivity)
|
.take(maxShortcutCountPerActivity)
|
||||||
.filterNot { roomUpdate -> currentShortcuts.any { it.id == roomUpdate.roomId.value } }
|
|
||||||
.forEachIndexed { index, room ->
|
.forEachIndexed { index, room ->
|
||||||
val build = ShortcutInfoCompat.Builder(context, room.roomId.value)
|
val build = ShortcutInfoCompat.Builder(context, room.roomId.value)
|
||||||
.setShortLabel(room.roomName ?: "N/A")
|
.setShortLabel(room.roomName ?: "N/A")
|
||||||
|
.setLongLabel(room.roomName ?: "N/A")
|
||||||
.setRank(index)
|
.setRank(index)
|
||||||
|
.run {
|
||||||
|
this.setPerson(
|
||||||
|
Person.Builder()
|
||||||
|
.setName(room.roomName ?: "N/A")
|
||||||
|
.setKey(room.roomId.value)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
.setIntent(MessengerActivity.newShortcutInstance(context, room.roomId))
|
.setIntent(MessengerActivity.newShortcutInstance(context, room.roomId))
|
||||||
.setLongLived(true)
|
.setLongLived(true)
|
||||||
.setCategories(setOf(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION))
|
.setCategories(setOf(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION))
|
||||||
|
|
|
@ -54,4 +54,6 @@ data class MessagerActivityPayload(
|
||||||
val roomId: String
|
val roomId: String
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
|
|
||||||
fun <T : Parcelable> Activity.readPayload(): T = intent.getParcelableExtra("key")!!
|
fun <T : Parcelable> Activity.readPayload(): T = intent.getParcelableExtra("key") ?: intent.getStringExtra("shortcut_key")!!.let {
|
||||||
|
MessagerActivityPayload(it) as T
|
||||||
|
}
|
|
@ -19,6 +19,10 @@
|
||||||
<data android:mimeType="image/*" />
|
<data android:mimeType="image/*" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.service.chooser.chooser_target_service"
|
||||||
|
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
|
@ -12,21 +12,6 @@ class ShareEntryActivity : DapkActivity() {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val urisToShare = intent.readSendUrisOrNull() ?: throw IllegalArgumentException("")
|
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)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue