#848 - App shortcuts support

This commit is contained in:
Moez Bhatti
2018-09-03 20:03:03 -04:00
parent 14399e057d
commit d27575240c
17 changed files with 200 additions and 12 deletions
@@ -22,6 +22,7 @@ import android.telephony.SmsMessage
import com.moez.QKSMS.extensions.mapNotNull
import com.moez.QKSMS.manager.ExternalBlockingManager
import com.moez.QKSMS.manager.NotificationManager
import com.moez.QKSMS.manager.ShortcutManager
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.repository.MessageRepository
import io.reactivex.Flowable
@@ -33,7 +34,8 @@ class ReceiveSms @Inject constructor(
private val externalBlockingManager: ExternalBlockingManager,
private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager,
private val updateBadge: UpdateBadge
private val updateBadge: UpdateBadge,
private val shortcutManager: ShortcutManager
) : Interactor<ReceiveSms.Params>() {
class Params(val subId: Int, val messages: Array<SmsMessage>)
@@ -63,6 +65,7 @@ class ReceiveSms @Inject constructor(
.map { conversation -> conversation.id } // Map to the id because [delay] will put us on the wrong thread
.delay(1, TimeUnit.SECONDS) // Wait one second before trying to notify, in case the foreground app marks it as read first
.doOnNext { threadId -> notificationManager.update(threadId) } // Update the notification
.doOnNext { shortcutManager.updateShortcuts() } // Update shortcuts
.flatMap { updateBadge.buildObservable(Unit) } // Update the badge
}
@@ -18,21 +18,20 @@
*/
package com.moez.QKSMS.interactor
import com.moez.QKSMS.manager.ShortcutManager
import com.moez.QKSMS.manager.WidgetManager
import com.moez.QKSMS.repository.MessageRepository
import io.reactivex.Flowable
import javax.inject.Inject
class UpdateBadge @Inject constructor(
private val messageRepo: MessageRepository,
private val shortcutManager: ShortcutManager,
private val widgetManager: WidgetManager
) : Interactor<Unit>() {
override fun buildObservable(params: Unit): Flowable<*> {
return Flowable.just(params)
.map { messageRepo.getUnreadCount() }
.map { count -> count.toInt() }
.doOnNext { count -> widgetManager.updateUnreadCount(count) }
.doOnNext { shortcutManager.updateBadge() }
.doOnNext { widgetManager.updateUnreadCount() }
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.manager
interface ShortcutManager {
fun updateBadge()
fun updateShortcuts()
}
@@ -24,6 +24,6 @@ interface WidgetManager {
const val ACTION_NOTIFY_DATASET_CHANGED = "com.moez.QKSMS.intent.action.ACTION_NOTIFY_DATASET_CHANGED"
}
fun updateUnreadCount(count: Int)
fun updateUnreadCount()
}
@@ -28,6 +28,11 @@ interface ConversationRepository {
fun getConversationsSnapshot(): List<Conversation>
/**
* Returns the top conversations that were active in the last week
*/
fun getTopConversations(): List<Conversation>
fun setConversationName(id: Long, name: String)
fun searchConversations(query: String): List<SearchResult>