forked from upstream-mirrors/quik
refactor(utils): Simplify shortcut generation logic
This commit is contained in:
@@ -69,14 +69,11 @@ class ShortcutManagerImpl @Inject constructor(
|
|||||||
override fun getOrCreateShortcut(threadId: Long): ShortcutInfoCompat? {
|
override fun getOrCreateShortcut(threadId: Long): ShortcutInfoCompat? {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||||
var sc = getShortcuts().find { it.id == threadId.toString() }
|
var sc = getShortcuts().find { it.id == threadId.toString() }
|
||||||
if (sc != null)
|
sc = if (sc != null) {
|
||||||
sc = updateShortcut(sc)
|
updateShortcut(sc)
|
||||||
if (sc == null) {
|
} else {
|
||||||
val conv = conversationRepo.getConversation(threadId)
|
val conv = conversationRepo.getConversation(threadId) ?: return null
|
||||||
if (conv == null)
|
createShortcutForConversation(conv)
|
||||||
return null
|
|
||||||
else
|
|
||||||
sc = createShortcutForConversation(conv)
|
|
||||||
}
|
}
|
||||||
return sc
|
return sc
|
||||||
} else {
|
} else {
|
||||||
@@ -141,14 +138,12 @@ class ShortcutManagerImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateShortcut(shortcut: ShortcutInfoCompat): ShortcutInfoCompat {
|
private fun updateShortcut(shortcut: ShortcutInfoCompat): ShortcutInfoCompat {
|
||||||
val conversation = conversationRepo.getConversation(shortcut.id.toLong())
|
val conversation = conversationRepo.getConversation(
|
||||||
if (conversation == null)
|
shortcut.id.toLong()
|
||||||
return shortcut
|
) ?: return shortcut
|
||||||
else {
|
val sc = createShortcutForConversation(conversation)
|
||||||
val sc = createShortcutForConversation(conversation)
|
ShortcutManagerCompat.pushDynamicShortcut(context, sc)
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(context, sc)
|
return sc
|
||||||
return sc
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getShortcuts() : List<ShortcutInfoCompat> {
|
private fun getShortcuts() : List<ShortcutInfoCompat> {
|
||||||
|
|||||||
Reference in New Issue
Block a user