Skip to content

Commit 72e75ed

Browse files
committed
fix: address review feedback for shortcuts and deep links
- Align "Add to home screen" menu icon and text padding with other bottom dialog items (use standard_dialog_padding consistently) - Disable shortcuts when a conversation is deleted so pinned shortcuts show "conversation no longer exists" instead of broken navigation - Use nextcloudtalk:// deep link URIs in shortcuts instead of bundle extras to fix multi-account navigation bug where switching accounts via shortcut would show conversation list instead of the conversation Signed-off-by: angrymuesli <github.visibly626@slmails.com>
1 parent cfcbd1f commit 72e75ed

File tree

6 files changed

+55
-30
lines changed

6 files changed

+55
-30
lines changed

app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,14 @@ class ConversationsListActivity : BaseActivity() {
11111111
if (workInfo != null) {
11121112
when (workInfo.state) {
11131113
WorkInfo.State.SUCCEEDED -> {
1114+
currentUser?.id?.let { userId ->
1115+
ShortcutManagerHelper.disableConversationShortcut(
1116+
context,
1117+
conversation.token,
1118+
userId,
1119+
context.resources.getString(R.string.nc_shortcut_conversation_deleted)
1120+
)
1121+
}
11141122
showSnackbar(
11151123
String.format(
11161124
context.resources.getString(R.string.deleted_conversation),

app/src/main/java/com/nextcloud/talk/ui/dialog/ConversationsListBottomDialog.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ class ConversationsListBottomDialog(
424424
if (workInfo != null) {
425425
when (workInfo.state) {
426426
WorkInfo.State.SUCCEEDED -> {
427+
currentUser.id?.let { userId ->
428+
ShortcutManagerHelper.disableConversationShortcut(
429+
context,
430+
conversation.token,
431+
userId,
432+
context.resources.getString(R.string.nc_shortcut_conversation_deleted)
433+
)
434+
}
427435
activity.showSnackbar(
428436
String.format(
429437
context.resources.getString(R.string.left_conversation),

app/src/main/java/com/nextcloud/talk/utils/DeepLinkHandler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ object DeepLinkHandler {
2424

2525
private const val SCHEME_NEXTCLOUD_TALK = "nextcloudtalk"
2626
private const val PATH_CALL = "call"
27-
private const val PATH_INDEX_PHP = "index.php"
2827

2928
// Token validation: alphanumeric characters, reasonable length
3029
private val TOKEN_PATTERN = Regex("^[a-zA-Z0-9]{4,32}$")

app/src/main/java/com/nextcloud/talk/utils/ShortcutManagerHelper.kt

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package com.nextcloud.talk.utils
88

99
import android.content.Context
1010
import android.content.Intent
11-
import android.os.Bundle
11+
import android.net.Uri
1212
import android.util.Log
1313
import androidx.core.content.pm.ShortcutInfoCompat
1414
import androidx.core.content.pm.ShortcutManagerCompat
@@ -17,7 +17,6 @@ import com.nextcloud.talk.R
1717
import com.nextcloud.talk.activities.MainActivity
1818
import com.nextcloud.talk.data.user.model.User
1919
import com.nextcloud.talk.models.domain.ConversationModel
20-
import com.nextcloud.talk.utils.bundle.BundleKeys
2120

2221
/**
2322
* Helper class for managing Android shortcuts for conversations.
@@ -32,39 +31,33 @@ object ShortcutManagerHelper {
3231
private const val CONVERSATION_SHORTCUT_PREFIX = "conversation_"
3332

3433
/**
35-
* Creates a shortcut for a conversation using bundle extras.
36-
* This matches the existing Note To Self shortcut pattern.
34+
* Creates a shortcut for a conversation using a nextcloudtalk:// deep link URI.
35+
* This ensures proper multi-account user resolution when the shortcut is opened.
3736
*
3837
* @param context Application context
3938
* @param conversation The conversation to create a shortcut for
4039
* @param user The user account associated with the conversation
4140
* @return ShortcutInfoCompat ready to be added, or null if user ID is invalid
4241
*/
4342
fun createConversationShortcut(context: Context, conversation: ConversationModel, user: User): ShortcutInfoCompat? {
44-
val userId = user.id ?: run {
45-
Log.w(TAG, "Cannot create shortcut: user ID is null")
46-
return null
43+
val userId = user.id
44+
val baseUrl = user.baseUrl
45+
val uri = baseUrl?.let {
46+
DeepLinkHandler.createConversationUri(conversation.token, it, user.username)
47+
.takeIf { built -> built != Uri.EMPTY }
4748
}
49+
if (userId == null || uri == null) return null
4850

49-
val shortcutId = getShortcutId(conversation.token, userId)
5051
val displayName = conversation.displayName.ifBlank { conversation.name }
51-
52-
val bundle = Bundle().apply {
53-
putString(BundleKeys.KEY_ROOM_TOKEN, conversation.token)
54-
putLong(BundleKeys.KEY_INTERNAL_USER_ID, userId)
55-
}
56-
5752
val intent = Intent(context, MainActivity::class.java).apply {
5853
action = Intent.ACTION_VIEW
59-
putExtras(bundle)
54+
data = uri
6055
}
6156

62-
val icon = IconCompat.createWithResource(context, R.drawable.baseline_chat_bubble_outline_24)
63-
64-
return ShortcutInfoCompat.Builder(context, shortcutId)
57+
return ShortcutInfoCompat.Builder(context, getShortcutId(conversation.token, userId))
6558
.setShortLabel(displayName)
6659
.setLongLabel(displayName)
67-
.setIcon(icon)
60+
.setIcon(IconCompat.createWithResource(context, R.drawable.baseline_chat_bubble_outline_24))
6861
.setIntent(intent)
6962
.build()
7063
}
@@ -135,21 +128,22 @@ object ShortcutManagerHelper {
135128
*/
136129
@Suppress("DEPRECATION")
137130
private fun createLegacyShortcut(context: Context, conversation: ConversationModel, user: User): Boolean {
138-
val userId = user.id ?: run {
139-
Log.w(TAG, "Cannot create legacy shortcut: user ID is null")
131+
if (user.id == null || user.baseUrl == null) {
132+
Log.w(TAG, "Cannot create legacy shortcut: user ID or base URL is null")
140133
return false
141134
}
142135

143136
val displayName = conversation.displayName.ifBlank { conversation.name }
144137

145-
val bundle = Bundle().apply {
146-
putString(BundleKeys.KEY_ROOM_TOKEN, conversation.token)
147-
putLong(BundleKeys.KEY_INTERNAL_USER_ID, userId)
148-
}
138+
val uri = DeepLinkHandler.createConversationUri(
139+
roomToken = conversation.token,
140+
serverUrl = user.baseUrl!!,
141+
username = user.username
142+
)
149143

150144
val launchIntent = Intent(context, MainActivity::class.java).apply {
151145
action = Intent.ACTION_VIEW
152-
putExtras(bundle)
146+
data = uri
153147
}
154148

155149
val shortcutIntent = Intent("com.android.launcher.action.INSTALL_SHORTCUT").apply {
@@ -197,6 +191,21 @@ object ShortcutManagerHelper {
197191
ShortcutManagerCompat.removeDynamicShortcuts(context, listOf(shortcutId))
198192
}
199193

194+
/**
195+
* Disables all shortcuts (dynamic and pinned) for a deleted conversation.
196+
* Dynamic shortcuts are removed; pinned shortcuts are disabled with a message.
197+
*
198+
* @param context Application context
199+
* @param roomToken The conversation token
200+
* @param userId The user ID
201+
* @param disabledMessage Message shown when a disabled pinned shortcut is tapped
202+
*/
203+
fun disableConversationShortcut(context: Context, roomToken: String, userId: Long, disabledMessage: String) {
204+
val shortcutId = getShortcutId(roomToken, userId)
205+
ShortcutManagerCompat.removeDynamicShortcuts(context, listOf(shortcutId))
206+
ShortcutManagerCompat.disableShortcuts(context, listOf(shortcutId), disabledMessage)
207+
}
208+
200209
/**
201210
* Generates a unique shortcut ID for a conversation.
202211
*/

app/src/main/res/layout/dialog_conversation_operations.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@
203203
android:background="?android:attr/selectableItemBackground"
204204
android:gravity="center_vertical"
205205
android:orientation="horizontal"
206-
android:paddingStart="@dimen/standard_padding"
207-
android:paddingEnd="@dimen/standard_padding"
206+
android:paddingStart="@dimen/standard_dialog_padding"
207+
android:paddingEnd="@dimen/standard_dialog_padding"
208208
tools:ignore="UseCompoundDrawables">
209209

210210
<ImageView
@@ -218,7 +218,7 @@
218218
android:layout_width="match_parent"
219219
android:layout_height="wrap_content"
220220
android:layout_gravity="start|center_vertical"
221-
android:paddingStart="40dp"
221+
android:paddingStart="@dimen/standard_dialog_padding"
222222
android:paddingEnd="@dimen/zero"
223223
android:text="@string/nc_add_to_home_screen"
224224
android:textAlignment="viewStart"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ How to translate with transifex:
4242
<!-- Shortcuts and Deep Links -->
4343
<string name="nc_add_to_home_screen">Add to home screen</string>
4444
<string name="nc_shortcut_created">Shortcut created</string>
45+
<string name="nc_shortcut_conversation_deleted">This conversation no longer exists</string>
4546
<string name="nc_no_account_for_server">No account found for this server</string>
4647

4748
<!-- Bottom Navigation -->

0 commit comments

Comments
 (0)