mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Add support for Call Blocker
This commit is contained in:
@@ -12,6 +12,7 @@ import javax.inject.Singleton
|
||||
@Singleton
|
||||
class BlockingManager @Inject constructor(
|
||||
private val prefs: Preferences,
|
||||
private val callBlockerBlockingClient: CallBlockerBlockingClient,
|
||||
private val callControlBlockingClient: CallControlBlockingClient,
|
||||
private val qksmsBlockingClient: QksmsBlockingClient,
|
||||
private val shouldIAnswerBlockingClient: ShouldIAnswerBlockingClient
|
||||
@@ -19,6 +20,7 @@ class BlockingManager @Inject constructor(
|
||||
|
||||
private val client: BlockingClient
|
||||
get() = when (prefs.blockingManager.get()) {
|
||||
Preferences.BLOCKING_MANAGER_CB -> callBlockerBlockingClient
|
||||
Preferences.BLOCKING_MANAGER_SIA -> shouldIAnswerBlockingClient
|
||||
Preferences.BLOCKING_MANAGER_CC -> callControlBlockingClient
|
||||
else -> qksmsBlockingClient
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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.blocking
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.database.Cursor
|
||||
import android.net.Uri
|
||||
import androidx.core.database.getStringOrNull
|
||||
import com.moez.QKSMS.common.util.extensions.isInstalled
|
||||
import com.moez.QKSMS.extensions.map
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
import java.util.ArrayList
|
||||
import javax.inject.Inject
|
||||
|
||||
class CallBlockerBlockingClient @Inject constructor(
|
||||
private val context: Context
|
||||
) : BlockingClient {
|
||||
|
||||
class LookupResult(cursor: Cursor) {
|
||||
val blockReason: String? = cursor.getStringOrNull(0)
|
||||
}
|
||||
|
||||
override fun isAvailable(): Boolean = context.isInstalled("com.cuiet.blockCalls")
|
||||
|
||||
override fun getClientCapability() = BlockingClient.Capability.BLOCK_WITH_PERMISSION
|
||||
|
||||
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
|
||||
val uri = Uri.parse("content://com.cuiet.blockCalls.ContProvBlockCalls/lookup/is.blocked.lookup")
|
||||
val blockReason = tryOrNull {
|
||||
context.contentResolver.query(uri, arrayOf("result"), "incomingNumber",
|
||||
arrayOf(address), null)
|
||||
?.use { cursor -> cursor.map(::LookupResult) }
|
||||
?.find { result -> result.blockReason != null }
|
||||
}?.blockReason
|
||||
|
||||
when (blockReason) {
|
||||
"true" -> BlockingClient.Action.Block()
|
||||
else -> BlockingClient.Action.Unblock
|
||||
}
|
||||
}
|
||||
|
||||
override fun block(addresses: List<String>): Completable = Completable.fromCallable {
|
||||
val arrayList = ArrayList<String>()
|
||||
arrayList.addAll(addresses)
|
||||
val intent = Intent("com.cuiet.blockCalls.ADD_NUMBERS")
|
||||
intent.putStringArrayListExtra("addresses", arrayList)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun unblock(addresses: List<String>): Completable = Completable.fromCallable {
|
||||
val arrayList = ArrayList<String>()
|
||||
arrayList.addAll(addresses)
|
||||
val intent = Intent("com.cuiet.blockCalls.REMOVE_NUMBERS")
|
||||
intent.putStringArrayListExtra("addresses", arrayList)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun openSettings() {
|
||||
val intent = Intent("com.cuiet.blockCalls.OPEN_SETTINGS")
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,7 @@ class Preferences @Inject constructor(
|
||||
const val BLOCKING_MANAGER_QKSMS = 0
|
||||
const val BLOCKING_MANAGER_CC = 1
|
||||
const val BLOCKING_MANAGER_SIA = 2
|
||||
const val BLOCKING_MANAGER_CB = 3
|
||||
}
|
||||
|
||||
// Internal
|
||||
|
||||
@@ -191,6 +191,15 @@ class Navigator @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the Play Store and display the Call Blocker listing
|
||||
*/
|
||||
fun installCallBlocker() {
|
||||
val url = "https://play.google.com/store/apps/details?id=com.cuiet.blockCalls"
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the Play Store and display the Call Control listing
|
||||
*/
|
||||
|
||||
+4
@@ -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()
|
||||
|
||||
|
||||
+26
@@ -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()
|
||||
|
||||
+1
@@ -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
|
||||
)
|
||||
|
||||
+1
@@ -8,6 +8,7 @@ interface BlockingManagerView : QkViewContract<BlockingManagerState> {
|
||||
|
||||
fun activityResumed(): Observable<*>
|
||||
fun qksmsClicked(): Observable<*>
|
||||
fun callBlockerClicked(): Observable<*>
|
||||
fun callControlClicked(): Observable<*>
|
||||
fun siaClicked(): Observable<*>
|
||||
|
||||
|
||||
@@ -37,6 +37,14 @@
|
||||
app:summary="@string/blocking_manager_qksms_summary"
|
||||
app:title="@string/blocking_manager_qksms_title" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.RadioPreferenceView
|
||||
android:id="@+id/callBlocker"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:summary="@string/blocking_manager_call_blocker_summary"
|
||||
app:title="@string/blocking_manager_call_blocker_title"
|
||||
app:widget="@layout/blocking_manager_list_option" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.RadioPreferenceView
|
||||
android:id="@+id/callControl"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -289,6 +289,8 @@
|
||||
<string name="blocking_manager_title">Blocking Manager</string>
|
||||
<string name="blocking_manager_qksms_title">QKSMS</string>
|
||||
<string name="blocking_manager_qksms_summary">Built-in blocking functionality in QKSMS</string>
|
||||
<string name="blocking_manager_call_blocker_title" translatable="false">Call Blocker</string>
|
||||
<string name="blocking_manager_call_blocker_summary">Call Blocker is a program that blocks unwanted calls, call centers, spam, robocalls, telemarketing, private calls, hidden calls, anonymous calls, strangers, etc.</string>
|
||||
<string name="blocking_manager_call_control_title" translatable="false">Call Control</string>
|
||||
<string name="blocking_manager_call_control_summary">Automatically filter your calls and messages in one convenient place! Community IQ™ allows you to prevent unwanted messages from community known spammers</string>
|
||||
<string name="blocking_manager_sia_title" translatable="false">Should I Answer?</string>
|
||||
|
||||
Reference in New Issue
Block a user