Loading data/src/main/java/com/moez/QKSMS/blocking/BlockingManager.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading data/src/main/java/com/moez/QKSMS/blocking/CallBlockerBlockingClient.kt 0 → 100644 +84 −0 Original line number Diff line number Diff line /* * 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) } } domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt +9 −0 Original line number Diff line number Diff line Loading @@ -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 */ Loading presentation/src/main/java/com/moez/QKSMS/feature/blocking/manager/BlockingManagerController.kt +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() Loading Loading
data/src/main/java/com/moez/QKSMS/blocking/BlockingManager.kt +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading
data/src/main/java/com/moez/QKSMS/blocking/CallBlockerBlockingClient.kt 0 → 100644 +84 −0 Original line number Diff line number Diff line /* * 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) } }
domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
presentation/src/main/java/com/moez/QKSMS/common/Navigator.kt +9 −0 Original line number Diff line number Diff line Loading @@ -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 */ Loading
presentation/src/main/java/com/moez/QKSMS/feature/blocking/manager/BlockingManagerController.kt +4 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() Loading