From 83090452b5c9190714ec5548a16d06eb454eea12 Mon Sep 17 00:00:00 2001 From: moezbhatti Date: Wed, 26 Jun 2019 02:01:46 -0400 Subject: [PATCH] Build out blocking client for pre api 24 devices --- .../moez/QKSMS/blocking/QkBlockingClient.kt | 42 ++------- .../repository/BlockingRepositoryImpl.kt | 87 +++++++++++++++++++ .../QKSMS/repository/BlockingRepository.kt | 36 ++++++++ .../feature/blocking/BlockingController.kt | 25 ++++++ .../QKSMS/feature/blocking/BlockingDialog.kt | 20 ++++- .../feature/blocking/BlockingPresenter.kt | 31 ++++++- .../QKSMS/feature/blocking/BlockingView.kt | 1 + .../blocking/numbers/BlockedNumbersAdapter.kt | 52 +++++++++++ .../numbers/BlockedNumbersController.kt | 87 +++++++++++++++++++ .../numbers/BlockedNumbersPresenter.kt | 49 +++++++++++ .../blocking/numbers/BlockedNumbersState.kt | 27 ++++++ .../blocking/numbers/BlockedNumbersView.kt | 32 +++++++ .../com/moez/QKSMS/injection/AppComponent.kt | 2 + .../com/moez/QKSMS/injection/AppModule.kt | 6 +- .../res/layout/blocked_number_list_item.xml | 47 ++++++++++ .../res/layout/blocked_numbers_add_dialog.xml | 50 +++++++++++ .../res/layout/blocked_numbers_controller.xml | 58 +++++++++++++ .../main/res/layout/blocking_controller.xml | 1 + presentation/src/main/res/values/strings.xml | 9 +- 19 files changed, 624 insertions(+), 38 deletions(-) create mode 100644 data/src/main/java/com/moez/QKSMS/repository/BlockingRepositoryImpl.kt create mode 100644 domain/src/main/java/com/moez/QKSMS/repository/BlockingRepository.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersAdapter.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersController.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersPresenter.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersState.kt create mode 100644 presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersView.kt create mode 100644 presentation/src/main/res/layout/blocked_number_list_item.xml create mode 100644 presentation/src/main/res/layout/blocked_numbers_add_dialog.xml create mode 100644 presentation/src/main/res/layout/blocked_numbers_controller.xml diff --git a/data/src/main/java/com/moez/QKSMS/blocking/QkBlockingClient.kt b/data/src/main/java/com/moez/QKSMS/blocking/QkBlockingClient.kt index 8b20e7fa..12032e55 100644 --- a/data/src/main/java/com/moez/QKSMS/blocking/QkBlockingClient.kt +++ b/data/src/main/java/com/moez/QKSMS/blocking/QkBlockingClient.kt @@ -23,25 +23,22 @@ import android.content.Intent import android.os.Build import android.provider.BlockedNumberContract import android.telecom.TelecomManager -import android.telephony.PhoneNumberUtils import androidx.core.content.contentValuesOf -import com.moez.QKSMS.extensions.anyOf -import com.moez.QKSMS.model.BlockedNumber +import com.moez.QKSMS.repository.BlockingRepository import io.reactivex.Completable import io.reactivex.Single -import io.realm.Realm import javax.inject.Inject -class QkBlockingClient @Inject constructor(private val context: Context) : BlockingClient { +class QkBlockingClient @Inject constructor( + private val context: Context, + private val blockingRepo: BlockingRepository +) : BlockingClient { override fun isBlocked(address: String): Single = Single.fromCallable { when { Build.VERSION.SDK_INT >= 24 -> BlockedNumberContract.isBlocked(context, address) - else -> Realm.getDefaultInstance() - .where(BlockedNumber::class.java) - .findAll() - .any { number -> PhoneNumberUtils.compare(number.address, address) } + else -> blockingRepo.isBlocked(address) } } @@ -54,14 +51,7 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block context.contentResolver.insert(BlockedNumberContract.BlockedNumbers.CONTENT_URI, cv) } - else -> Realm.getDefaultInstance().use { realm -> - val maxId = realm.where(BlockedNumber::class.java) - .max("id")?.toLong() ?: -1 - - realm.executeTransaction { - realm.insert(addresses.mapIndexed { index, address -> BlockedNumber(maxId + 1 + index, address) }) - } - } + else -> blockingRepo.blockNumber(*addresses.toTypedArray()) } } @@ -73,21 +63,7 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block BlockedNumberContract.unblock(context, address) } - else -> Realm.getDefaultInstance().use { realm -> - val ids = realm - .where(BlockedNumber::class.java) - .findAll() - .filter { number -> - addresses.any { address -> PhoneNumberUtils.compare(number.address, address) } - } - .map { number -> number.id } - .toLongArray() - - realm.executeTransaction { - realm.where(BlockedNumber::class.java) - .anyOf("id", ids) - } - } + else -> blockingRepo.unblockNumbers(*addresses.toTypedArray()) } } @@ -100,7 +76,7 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block context.startActivity(intent) } - else -> {} // TODO + else -> {} // TODO: Do this here once we implement AndroidX navigation } } diff --git a/data/src/main/java/com/moez/QKSMS/repository/BlockingRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/BlockingRepositoryImpl.kt new file mode 100644 index 00000000..c71335b8 --- /dev/null +++ b/data/src/main/java/com/moez/QKSMS/repository/BlockingRepositoryImpl.kt @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.repository + +import android.telephony.PhoneNumberUtils +import com.moez.QKSMS.extensions.anyOf +import com.moez.QKSMS.model.BlockedNumber +import io.realm.Realm +import io.realm.RealmResults +import javax.inject.Inject + +class BlockingRepositoryImpl @Inject constructor() : BlockingRepository { + + override fun blockNumber(vararg addresses: String) { + val newAddresses = addresses.filter { address -> !isBlocked(address) } + + Realm.getDefaultInstance().use { realm -> + val maxId = realm.where(BlockedNumber::class.java) + .max("id")?.toLong() ?: -1 + + realm.executeTransaction { + realm.insert(newAddresses.mapIndexed { index, address -> BlockedNumber(maxId + 1 + index, address) }) + } + } + } + + override fun getBlockedNumbers(): RealmResults { + val realm = Realm.getDefaultInstance() + return realm.where(BlockedNumber::class.java) + .findAllAsync() + } + + override fun isBlocked(address: String): Boolean { + return Realm.getDefaultInstance().use { realm -> + realm.where(BlockedNumber::class.java) + .findAll() + .any { number -> PhoneNumberUtils.compare(number.address, address) } + } + } + + override fun unblockNumber(id: Long) { + Realm.getDefaultInstance().use { realm -> + realm.executeTransaction { + realm.where(BlockedNumber::class.java) + .equalTo("id", id) + .findAll() + .deleteAllFromRealm() + } + } + } + + override fun unblockNumbers(vararg addresses: String) { + Realm.getDefaultInstance().use { realm -> + val ids = realm.where(BlockedNumber::class.java) + .findAll() + .filter { number -> + addresses.any { address -> PhoneNumberUtils.compare(number.address, address) } + } + .map { number -> number.id } + .toLongArray() + + realm.executeTransaction { + realm.where(BlockedNumber::class.java) + .anyOf("id", ids) + .findAll() + .deleteAllFromRealm() + } + } + } + +} diff --git a/domain/src/main/java/com/moez/QKSMS/repository/BlockingRepository.kt b/domain/src/main/java/com/moez/QKSMS/repository/BlockingRepository.kt new file mode 100644 index 00000000..8f6e3f94 --- /dev/null +++ b/domain/src/main/java/com/moez/QKSMS/repository/BlockingRepository.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.repository + +import com.moez.QKSMS.model.BlockedNumber +import io.realm.RealmResults + +interface BlockingRepository { + + fun blockNumber(vararg addresses: String) + + fun getBlockedNumbers(): RealmResults + + fun isBlocked(address: String): Boolean + + fun unblockNumber(id: Long) + + fun unblockNumbers(vararg addresses: String) + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt index 69283645..1864fc29 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingController.kt @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ package com.moez.QKSMS.feature.blocking import android.view.View @@ -10,6 +28,7 @@ import com.moez.QKSMS.common.base.QkController import com.moez.QKSMS.common.util.Colors import com.moez.QKSMS.common.util.extensions.setTint import com.moez.QKSMS.feature.blocking.manager.BlockingManagerController +import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController import com.moez.QKSMS.injection.appComponent import io.reactivex.Observable import kotlinx.android.synthetic.main.blocking_controller.* @@ -61,4 +80,10 @@ class BlockingController : QkController + * + * 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 . + */ package com.moez.QKSMS.feature.blocking import android.app.Activity @@ -51,7 +69,7 @@ class BlockingDialog @Inject constructor( val manager = context.getString(when (prefs.blockingManager.get()) { Preferences.BLOCKING_MANAGER_SIA -> R.string.blocking_manager_sia_title Preferences.BLOCKING_MANAGER_CC -> R.string.blocking_manager_call_control_title - else -> R.string.blocking_manager_android + else -> R.string.app_name }) val message = context.resources.getQuantityString(res, addresses.size, manager) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingPresenter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingPresenter.kt index 74404551..393cb124 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingPresenter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingPresenter.kt @@ -1,6 +1,25 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ package com.moez.QKSMS.feature.blocking import android.content.Context +import android.os.Build import com.moez.QKSMS.R import com.moez.QKSMS.blocking.BlockingManager import com.moez.QKSMS.common.Navigator @@ -31,7 +50,7 @@ class BlockingPresenter @Inject constructor( } } .map(context::getString) - .subscribe { manager -> newState { copy(blockingManager = manager) }} + .subscribe { manager -> newState { copy(blockingManager = manager) } } disposables += prefs.drop.asObservable() .subscribe { enabled -> newState { copy(dropEnabled = enabled) } } @@ -46,7 +65,15 @@ class BlockingPresenter @Inject constructor( view.settingsClicks .autoDisposable(view.scope()) - .subscribe { blockingManager.openSettings() } + .subscribe { + // TODO: This is a hack, get rid of it once we implement AndroidX navigation + val client = prefs.blockingManager.get() + if (client == Preferences.BLOCKING_MANAGER_QKSMS && Build.VERSION.SDK_INT < 24) { + view.openBlockedNumbers() + } else { + blockingManager.openSettings() + } + } view.dropClickedIntent .autoDisposable(view.scope()) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt index 631411c2..acf4fa2c 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/BlockingView.kt @@ -29,4 +29,5 @@ interface BlockingView : QkViewContract { val conversationClicks: Observable fun openBlockingManager() + fun openBlockedNumbers() } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersAdapter.kt new file mode 100644 index 00000000..9ddf541f --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersAdapter.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.numbers + +import android.view.LayoutInflater +import android.view.ViewGroup +import com.moez.QKSMS.R +import com.moez.QKSMS.common.base.QkRealmAdapter +import com.moez.QKSMS.common.base.QkViewHolder +import com.moez.QKSMS.model.BlockedNumber +import io.reactivex.subjects.PublishSubject +import io.reactivex.subjects.Subject +import kotlinx.android.synthetic.main.blocked_number_list_item.* +import kotlinx.android.synthetic.main.blocked_number_list_item.view.* + +class BlockedNumbersAdapter : QkRealmAdapter() { + + val unblockAddress: Subject = PublishSubject.create() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_number_list_item, parent, false) + return QkViewHolder(view).apply { + containerView.unblock.setOnClickListener { + val number = getItem(adapterPosition) ?: return@setOnClickListener + unblockAddress.onNext(number.id) + } + } + } + + override fun onBindViewHolder(holder: QkViewHolder, position: Int) { + val item = getItem(position)!! + + holder.number.text = item.address + } + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersController.kt new file mode 100644 index 00000000..7a34c1ea --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersController.kt @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.numbers + +import android.view.LayoutInflater +import android.view.View +import androidx.appcompat.app.AlertDialog +import com.jakewharton.rxbinding2.view.clicks +import com.moez.QKSMS.R +import com.moez.QKSMS.common.base.QkController +import com.moez.QKSMS.common.util.Colors +import com.moez.QKSMS.common.util.extensions.setBackgroundTint +import com.moez.QKSMS.common.util.extensions.setTint +import com.moez.QKSMS.injection.appComponent +import io.reactivex.Observable +import io.reactivex.subjects.PublishSubject +import io.reactivex.subjects.Subject +import kotlinx.android.synthetic.main.blocked_numbers_add_dialog.view.* +import kotlinx.android.synthetic.main.blocked_numbers_controller.* +import javax.inject.Inject + +class BlockedNumbersController : QkController(), + BlockedNumbersView { + + @Inject override lateinit var presenter: BlockedNumbersPresenter + @Inject lateinit var colors: Colors + + private val adapter = BlockedNumbersAdapter() + private val saveAddressSubject: Subject = PublishSubject.create() + + init { + appComponent.inject(this) + retainViewMode = RetainViewMode.RETAIN_DETACH + layoutRes = R.layout.blocked_numbers_controller + } + + override fun onAttach(view: View) { + super.onAttach(view) + presenter.bindIntents(this) + setTitle(R.string.blocked_numbers_title) + showBackButton(true) + } + + override fun onViewCreated() { + super.onViewCreated() + add.setBackgroundTint(colors.theme().theme) + add.setTint(colors.theme().textPrimary) + adapter.emptyView = empty + numbers.adapter = adapter + } + + override fun render(state: BlockedNumbersState) { + adapter.updateData(state.numbers) + } + + override fun unblockAddress(): Observable = adapter.unblockAddress + override fun addAddress(): Observable<*> = add.clicks() + override fun saveAddress(): Observable = saveAddressSubject + + override fun showAddDialog() { + val layout = LayoutInflater.from(activity).inflate(R.layout.blocked_numbers_add_dialog, null) + val dialog = AlertDialog.Builder(activity!!) + .setView(layout) + .setPositiveButton(R.string.blocked_numbers_dialog_block) { _, _ -> + saveAddressSubject.onNext(layout.input.text.toString()) + } + .setNegativeButton(R.string.button_cancel) { _, _ -> } + dialog.show() + } + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersPresenter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersPresenter.kt new file mode 100644 index 00000000..b7fbb3ac --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersPresenter.kt @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.numbers + +import com.moez.QKSMS.common.base.QkPresenter +import com.moez.QKSMS.repository.BlockingRepository +import com.uber.autodispose.kotlin.autoDisposable +import javax.inject.Inject + +class BlockedNumbersPresenter @Inject constructor( + private val blockingRepo: BlockingRepository +) : QkPresenter( + BlockedNumbersState(numbers = blockingRepo.getBlockedNumbers()) +) { + + override fun bindIntents(view: BlockedNumbersView) { + super.bindIntents(view) + + view.unblockAddress() + .doOnNext(blockingRepo::unblockNumber) + .autoDisposable(view.scope()) + .subscribe() + + view.addAddress() + .autoDisposable(view.scope()) + .subscribe { view.showAddDialog() } + + view.saveAddress() + .autoDisposable(view.scope()) + .subscribe{ address -> blockingRepo.blockNumber(address) } + } + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersState.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersState.kt new file mode 100644 index 00000000..abc20600 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersState.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.numbers + +import com.moez.QKSMS.model.BlockedNumber +import io.realm.RealmList +import io.realm.RealmResults + +data class BlockedNumbersState( + val numbers: RealmResults? = null +) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersView.kt new file mode 100644 index 00000000..b537c944 --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/blocking/numbers/BlockedNumbersView.kt @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +package com.moez.QKSMS.feature.blocking.numbers + +import com.moez.QKSMS.common.base.QkViewContract +import io.reactivex.Observable + +interface BlockedNumbersView : QkViewContract { + + fun unblockAddress(): Observable + fun addAddress(): Observable<*> + fun saveAddress(): Observable + + fun showAddDialog() + +} diff --git a/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt b/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt index 0c35f5c0..8ca92a31 100644 --- a/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt +++ b/presentation/src/main/java/com/moez/QKSMS/injection/AppComponent.kt @@ -31,6 +31,7 @@ import com.moez.QKSMS.common.widget.RadioPreferenceView import com.moez.QKSMS.feature.backup.BackupController import com.moez.QKSMS.feature.blocking.BlockingController import com.moez.QKSMS.feature.blocking.manager.BlockingManagerController +import com.moez.QKSMS.feature.blocking.numbers.BlockedNumbersController import com.moez.QKSMS.feature.compose.DetailedChipView import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoComponent import com.moez.QKSMS.feature.settings.SettingsController @@ -62,6 +63,7 @@ interface AppComponent { fun inject(controller: AboutController) fun inject(controller: BackupController) + fun inject(controller: BlockedNumbersController) fun inject(controller: BlockingController) fun inject(controller: BlockingManagerController) fun inject(controller: SettingsController) diff --git a/presentation/src/main/java/com/moez/QKSMS/injection/AppModule.kt b/presentation/src/main/java/com/moez/QKSMS/injection/AppModule.kt index d2d7a572..18d9cf20 100644 --- a/presentation/src/main/java/com/moez/QKSMS/injection/AppModule.kt +++ b/presentation/src/main/java/com/moez/QKSMS/injection/AppModule.kt @@ -1,4 +1,3 @@ - /* * Copyright (C) 2017 Moez Bhatti * @@ -64,6 +63,8 @@ import com.moez.QKSMS.mapper.CursorToRecipientImpl import com.moez.QKSMS.mapper.RatingManagerImpl import com.moez.QKSMS.repository.BackupRepository import com.moez.QKSMS.repository.BackupRepositoryImpl +import com.moez.QKSMS.repository.BlockingRepository +import com.moez.QKSMS.repository.BlockingRepositoryImpl import com.moez.QKSMS.repository.ContactRepository import com.moez.QKSMS.repository.ContactRepositoryImpl import com.moez.QKSMS.repository.ConversationRepository @@ -174,6 +175,9 @@ class AppModule(private var application: Application) { @Provides fun provideBackupRepository(repository: BackupRepositoryImpl): BackupRepository = repository + @Provides + fun provideBlockingRepository(repository: BlockingRepositoryImpl): BlockingRepository = repository + @Provides fun provideContactRepository(repository: ContactRepositoryImpl): ContactRepository = repository diff --git a/presentation/src/main/res/layout/blocked_number_list_item.xml b/presentation/src/main/res/layout/blocked_number_list_item.xml new file mode 100644 index 00000000..93bcb893 --- /dev/null +++ b/presentation/src/main/res/layout/blocked_number_list_item.xml @@ -0,0 +1,47 @@ + + + + + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/layout/blocked_numbers_add_dialog.xml b/presentation/src/main/res/layout/blocked_numbers_add_dialog.xml new file mode 100644 index 00000000..87bae892 --- /dev/null +++ b/presentation/src/main/res/layout/blocked_numbers_add_dialog.xml @@ -0,0 +1,50 @@ + + + + + + + + + diff --git a/presentation/src/main/res/layout/blocked_numbers_controller.xml b/presentation/src/main/res/layout/blocked_numbers_controller.xml new file mode 100644 index 00000000..1aa4e148 --- /dev/null +++ b/presentation/src/main/res/layout/blocked_numbers_controller.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/layout/blocking_controller.xml b/presentation/src/main/res/layout/blocking_controller.xml index 5dd076de..e33c1d1b 100644 --- a/presentation/src/main/res/layout/blocking_controller.xml +++ b/presentation/src/main/res/layout/blocking_controller.xml @@ -57,6 +57,7 @@ android:layout_width="72dp" android:layout_height="72dp" android:background="?attr/selectableItemBackground" + android:contentDescription="@string/blocking_manager_settings_cd" android:padding="24dp" android:src="@drawable/ic_settings_black_24dp" app:layout_constraintBottom_toBottomOf="@id/blockingManager" diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 5889ce4d..a9c579e0 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -252,6 +252,7 @@ Enter duration (seconds) Blocking + Open settings for selected blocking manager Drop messages Drop incoming messages from blocked senders instead of hiding them Blocked conversations @@ -259,7 +260,6 @@ Blocking Manager Built-in blocking functionality in QKSMS - Android Blocking Manager Call Control Automatically filter your calls and messages in one convenient place! Community IQ™ allows you to prevent unwanted messages from community known spammers @@ -267,6 +267,13 @@ Should I Answer? Automatically filter messages from unsolicited numbers by using the \"Should I Answer\" app + Blocked numbers + Your blocked numbers will appear here + Block a new number + Block texts from + Phone number + Block + Would you also like to block this number in %s? Would you also like to block these numbers in %s?