Add support for Call Blocker

This commit is contained in:
Moez Bhatti
2021-02-09 23:09:05 -05:00
parent 3d84ccceea
commit 178cccd93f
10 changed files with 138 additions and 0 deletions
@@ -44,6 +44,9 @@ class BlockingManagerController : QkController<BlockingManagerView, BlockingMana
override fun render(state: BlockingManagerState) {
qksms.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_QKSMS
callBlocker.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_CB
callBlocker.install.isVisible = !state.callBlockerInstalled
callControl.radioButton.isChecked = state.blockingManager == Preferences.BLOCKING_MANAGER_CC
callControl.install.isVisible = !state.callControlInstalled
@@ -53,6 +56,7 @@ class BlockingManagerController : QkController<BlockingManagerView, BlockingMana
override fun activityResumed(): Observable<*> = activityResumedSubject
override fun qksmsClicked(): Observable<*> = qksms.clicks()
override fun callBlockerClicked(): Observable<*> = callBlocker.clicks()
override fun callControlClicked(): Observable<*> = callControl.clicks()
override fun siaClicked(): Observable<*> = shouldIAnswer.clicks()
@@ -3,6 +3,7 @@ package com.moez.QKSMS.feature.blocking.manager
import android.content.Context
import com.moez.QKSMS.R
import com.moez.QKSMS.blocking.BlockingClient
import com.moez.QKSMS.blocking.CallBlockerBlockingClient
import com.moez.QKSMS.blocking.CallControlBlockingClient
import com.moez.QKSMS.blocking.QksmsBlockingClient
import com.moez.QKSMS.blocking.ShouldIAnswerBlockingClient
@@ -21,6 +22,7 @@ import javax.inject.Inject
class BlockingManagerPresenter @Inject constructor(
private val analytics: AnalyticsManager,
private val callBlocker: CallBlockerBlockingClient,
private val callControl: CallControlBlockingClient,
private val context: Context,
private val conversationRepo: ConversationRepository,
@@ -30,6 +32,7 @@ class BlockingManagerPresenter @Inject constructor(
private val shouldIAnswer: ShouldIAnswerBlockingClient
) : QkPresenter<BlockingManagerView, BlockingManagerState>(BlockingManagerState(
blockingManager = prefs.blockingManager.get(),
callBlockerInstalled = callBlocker.isAvailable(),
callControlInstalled = callControl.isAvailable(),
siaInstalled = shouldIAnswer.isAvailable()
)) {
@@ -42,6 +45,12 @@ class BlockingManagerPresenter @Inject constructor(
override fun bindIntents(view: BlockingManagerView) {
super.bindIntents(view)
view.activityResumed()
.map { callBlocker.isAvailable() }
.distinctUntilChanged()
.autoDisposable(view.scope())
.subscribe { available -> newState { copy(callBlockerInstalled = available) } }
view.activityResumed()
.map { callControl.isAvailable() }
.distinctUntilChanged()
@@ -64,6 +73,23 @@ class BlockingManagerPresenter @Inject constructor(
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_QKSMS)
}
view.callBlockerClicked()
.filter {
val installed = callBlocker.isAvailable()
if (!installed) {
analytics.track("Install Call Blocker")
navigator.installCallBlocker()
}
val enabled = prefs.blockingManager.get() == Preferences.BLOCKING_MANAGER_CB
installed && !enabled
}
.autoDisposable(view.scope())
.subscribe {
analytics.setUserProperty("Blocking Manager", "Call Blocker")
prefs.blockingManager.set(Preferences.BLOCKING_MANAGER_CB)
}
view.callControlClicked()
.filter {
val installed = callControl.isAvailable()
@@ -2,6 +2,7 @@ package com.moez.QKSMS.feature.blocking.manager
data class BlockingManagerState(
val blockingManager: Int = 0,
val callBlockerInstalled: Boolean = false,
val callControlInstalled: Boolean = false,
val siaInstalled: Boolean = false
)
@@ -8,6 +8,7 @@ interface BlockingManagerView : QkViewContract<BlockingManagerState> {
fun activityResumed(): Observable<*>
fun qksmsClicked(): Observable<*>
fun callBlockerClicked(): Observable<*>
fun callControlClicked(): Observable<*>
fun siaClicked(): Observable<*>