From 3bc4b86feae145f77ce5e77c226711ec44cd054f Mon Sep 17 00:00:00 2001 From: moezbhatti Date: Wed, 29 May 2019 17:25:12 -0400 Subject: [PATCH] Add UI for toggling Call Control --- .../java/com/moez/QKSMS/util/Preferences.kt | 1 + .../java/com/moez/QKSMS/common/Navigator.kt | 9 ++++++ .../QKSMS/feature/blocked/BlockedActivity.kt | 2 ++ .../QKSMS/feature/blocked/BlockedState.kt | 1 + .../moez/QKSMS/feature/blocked/BlockedView.kt | 1 + .../QKSMS/feature/blocked/BlockedViewModel.kt | 28 ++++++++++++++++--- .../src/main/res/layout/blocked_activity.xml | 11 ++++++++ presentation/src/main/res/values/strings.xml | 2 ++ 8 files changed, 51 insertions(+), 4 deletions(-) diff --git a/data/src/main/java/com/moez/QKSMS/util/Preferences.kt b/data/src/main/java/com/moez/QKSMS/util/Preferences.kt index 68a0d42d..aac8ca8b 100644 --- a/data/src/main/java/com/moez/QKSMS/util/Preferences.kt +++ b/data/src/main/java/com/moez/QKSMS/util/Preferences.kt @@ -76,6 +76,7 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences) val black = rxPrefs.getBoolean("black", false) val systemFont = rxPrefs.getBoolean("systemFont", false) val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL) + val callControl = rxPrefs.getBoolean("callControl", false) val sia = rxPrefs.getBoolean("sia", false) val notifAction1 = rxPrefs.getInteger("notifAction1", NOTIFICATION_ACTION_READ) val notifAction2 = rxPrefs.getInteger("notifAction2", NOTIFICATION_ACTION_REPLY) diff --git a/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt b/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt index 904fae2f..472a2c55 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt @@ -180,6 +180,15 @@ class Navigator @Inject constructor( } } + /** + * Launch the Play Store and display the Call Control listing + */ + fun showCallControl() { + val url = "https://play.google.com/store/apps/details?id=com.flexaspect.android.everycallcontrol" + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + startActivity(intent) + } + /** * Launch the Play Store and display the Should I Answer? listing */ diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt index df536113..1e75d0ae 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedActivity.kt @@ -37,6 +37,7 @@ class BlockedActivity : QkThemedActivity(), BlockedView { @Inject lateinit var blockedAdapter: BlockedAdapter @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + override val ccClickedIntent by lazy { callControl.clicks() } override val siaClickedIntent by lazy { shouldIAnswer.clicks() } override val unblockIntent by lazy { blockedAdapter.unblock } override val confirmUnblockIntent: Subject = PublishSubject.create() @@ -56,6 +57,7 @@ class BlockedActivity : QkThemedActivity(), BlockedView { } override fun render(state: BlockedState) { + callControl.checkbox.isChecked = state.ccEnabled shouldIAnswer.checkbox.isChecked = state.siaEnabled blockedAdapter.updateData(state.data) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedState.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedState.kt index 5a83fd4f..3456005b 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedState.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedState.kt @@ -22,6 +22,7 @@ import com.moez.QKSMS.model.Conversation import io.realm.RealmResults data class BlockedState( + val ccEnabled: Boolean = false, val siaEnabled: Boolean = false, val data: RealmResults? = null ) \ No newline at end of file diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedView.kt index 3b5d5216..49d38b77 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedView.kt @@ -23,6 +23,7 @@ import io.reactivex.Observable interface BlockedView : QkView { + val ccClickedIntent: Observable<*> val siaClickedIntent: Observable<*> val unblockIntent: Observable val confirmUnblockIntent: Observable diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt index 7cbc516f..ccb8aa77 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocked/BlockedViewModel.kt @@ -29,7 +29,6 @@ import com.moez.QKSMS.util.tryOrNull import com.uber.autodispose.android.lifecycle.scope import com.uber.autodispose.autoDisposable import io.reactivex.rxkotlin.plusAssign -import io.reactivex.rxkotlin.withLatestFrom import javax.inject.Inject class BlockedViewModel @Inject constructor( @@ -44,6 +43,9 @@ class BlockedViewModel @Inject constructor( init { newState { copy(data = conversationRepo.getBlockedConversations()) } + disposables += prefs.callControl.asObservable() + .subscribe { enabled -> newState { copy(ccEnabled = enabled) } } + disposables += prefs.sia.asObservable() .subscribe { enabled -> newState { copy(siaEnabled = enabled) } } } @@ -51,6 +53,20 @@ class BlockedViewModel @Inject constructor( override fun bindView(view: BlockedView) { super.bindView(view) + view.ccClickedIntent + .map { tryOrNull(false) { context.packageManager.getApplicationInfo("com.flexaspect.android.everycallcontrol", 0).enabled } ?: false } + .map { installed -> + if (!installed) { + navigator.showCallControl() + } + + val enabled = prefs.callControl.get() + analytics.track("Clicked Call Control", Pair("enable", !enabled), Pair("installed", installed)) + installed && !enabled + } + .autoDisposable(view.scope()) + .subscribe(prefs.callControl::set) + view.siaClickedIntent .map { tryOrNull(false) { context.packageManager.getApplicationInfo("org.mistergroup.shouldianswer", 0).enabled } @@ -58,13 +74,17 @@ class BlockedViewModel @Inject constructor( ?: tryOrNull(false) { context.packageManager.getApplicationInfo("org.mistergroup.muzutozvednout", 0).enabled } ?: false } - .doOnNext { installed -> if (!installed) navigator.showSia() } - .withLatestFrom(prefs.sia.asObservable()) { installed, enabled -> + .map { installed -> + if (!installed) { + navigator.showSia() + } + + val enabled = prefs.sia.get() analytics.track("Clicked SIA", Pair("enable", !enabled), Pair("installed", installed)) installed && !enabled } .autoDisposable(view.scope()) - .subscribe { shouldEnable -> prefs.sia.set(shouldEnable) } + .subscribe(prefs.sia::set) // Show confirm unblock conversation dialog view.unblockIntent diff --git a/presentation/src/main/res/layout/blocked_activity.xml b/presentation/src/main/res/layout/blocked_activity.xml index 8f3995ab..f3f79ef9 100644 --- a/presentation/src/main/res/layout/blocked_activity.xml +++ b/presentation/src/main/res/layout/blocked_activity.xml @@ -54,6 +54,17 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + Tap outside of the popup to close it Blocking + Call Control + Automatically filter your calls and messages in one convenient place! Community IQ™ allows you to prevent unwanted messages from community known spammers Should I Answer? Automatically filter messages from unsolicited numbers by using the \"Should I Answer\" app Delayed sending