Update badge and shortcuts after pinning

This commit is contained in:
moezbhatti
2019-11-09 03:45:49 -05:00
parent 335c5757c4
commit 5d2b59e57a
3 changed files with 20 additions and 6 deletions
@@ -18,15 +18,22 @@
*/
package com.moez.QKSMS.interactor
import com.moez.QKSMS.manager.ShortcutManager
import com.moez.QKSMS.repository.ConversationRepository
import io.reactivex.Flowable
import javax.inject.Inject
class MarkPinned @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
class MarkPinned @Inject constructor(
private val conversationRepo: ConversationRepository,
private val updateBadge: UpdateBadge,
private val shortcutManager: ShortcutManager
) : Interactor<List<Long>>() {
override fun buildObservable(params: List<Long>): Flowable<*> {
return Flowable.just(params.toLongArray())
.doOnNext { threadIds -> conversationRepo.markPinned(*threadIds) }
.doOnNext { shortcutManager.updateShortcuts() } // Update shortcuts
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge and widget
}
}
}
@@ -18,15 +18,22 @@
*/
package com.moez.QKSMS.interactor
import com.moez.QKSMS.manager.ShortcutManager
import com.moez.QKSMS.repository.ConversationRepository
import io.reactivex.Flowable
import javax.inject.Inject
class MarkUnpinned @Inject constructor(private val conversationRepo: ConversationRepository) : Interactor<List<Long>>() {
class MarkUnpinned @Inject constructor(
private val conversationRepo: ConversationRepository,
private val updateBadge: UpdateBadge,
private val shortcutManager: ShortcutManager
) : Interactor<List<Long>>() {
override fun buildObservable(params: List<Long>): Flowable<*> {
return Flowable.just(params.toLongArray())
.doOnNext { threadIds -> conversationRepo.markUnpinned(*threadIds) }
.doOnNext { shortcutManager.updateShortcuts() } // Update shortcuts
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge and widget
}
}
}
@@ -91,7 +91,7 @@ class ReceiveSms @Inject constructor(
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
.doOnNext { shortcutManager.updateShortcuts() } // Update shortcuts
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge and widget
}
}
}