Refactor ExternalBlockingManager to BlockingClient

This commit is contained in:
moezbhatti
2019-05-29 18:09:35 -04:00
parent 5883f661ff
commit 4db125037a
6 changed files with 14 additions and 15 deletions
@@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>. * along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.moez.QKSMS.manager package com.moez.QKSMS.blocking
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
@@ -35,10 +35,10 @@ import io.reactivex.subjects.SingleSubject
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class ExternalBlockingManagerImpl @Inject constructor( class ShouldIAnswerBlockingClient @Inject constructor(
private val context: Context, private val context: Context,
private val prefs: Preferences private val prefs: Preferences
) : ExternalBlockingManager { ) : BlockingClient {
companion object { companion object {
const val RATING_UNKNOWN = 0 const val RATING_UNKNOWN = 0
@@ -16,11 +16,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>. * along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.moez.QKSMS.manager package com.moez.QKSMS.blocking
import io.reactivex.Single import io.reactivex.Single
interface ExternalBlockingManager { interface BlockingClient {
/** /**
* Return a Single<Boolean> which emits whether or not the given [address] should be blocked * Return a Single<Boolean> which emits whether or not the given [address] should be blocked
@@ -19,9 +19,9 @@
package com.moez.QKSMS.interactor package com.moez.QKSMS.interactor
import android.net.Uri import android.net.Uri
import com.moez.QKSMS.blocking.BlockingClient
import com.moez.QKSMS.extensions.mapNotNull import com.moez.QKSMS.extensions.mapNotNull
import com.moez.QKSMS.manager.ActiveConversationManager import com.moez.QKSMS.manager.ActiveConversationManager
import com.moez.QKSMS.manager.ExternalBlockingManager
import com.moez.QKSMS.manager.NotificationManager import com.moez.QKSMS.manager.NotificationManager
import com.moez.QKSMS.repository.ConversationRepository import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.repository.MessageRepository import com.moez.QKSMS.repository.MessageRepository
@@ -32,7 +32,7 @@ import javax.inject.Inject
class ReceiveMms @Inject constructor( class ReceiveMms @Inject constructor(
private val activeConversationManager: ActiveConversationManager, private val activeConversationManager: ActiveConversationManager,
private val conversationRepo: ConversationRepository, private val conversationRepo: ConversationRepository,
private val externalBlockingManager: ExternalBlockingManager, private val blockingClient: BlockingClient,
private val syncManager: SyncRepository, private val syncManager: SyncRepository,
private val messageRepo: MessageRepository, private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager, private val notificationManager: NotificationManager,
@@ -54,7 +54,7 @@ class ReceiveMms @Inject constructor(
// to check if it should be blocked after we've pulled it into realm. If it // to check if it should be blocked after we've pulled it into realm. If it
// turns out that it should be blocked, then delete it // turns out that it should be blocked, then delete it
// TODO Don't store blocked messages in the first place // TODO Don't store blocked messages in the first place
!externalBlockingManager.shouldBlock(message.address).blockingGet().also { blocked -> !blockingClient.shouldBlock(message.address).blockingGet().also { blocked ->
if (blocked) messageRepo.deleteMessages(message.id) if (blocked) messageRepo.deleteMessages(message.id)
} }
} }
@@ -19,8 +19,8 @@
package com.moez.QKSMS.interactor package com.moez.QKSMS.interactor
import android.telephony.SmsMessage import android.telephony.SmsMessage
import com.moez.QKSMS.blocking.BlockingClient
import com.moez.QKSMS.extensions.mapNotNull import com.moez.QKSMS.extensions.mapNotNull
import com.moez.QKSMS.manager.ExternalBlockingManager
import com.moez.QKSMS.manager.NotificationManager import com.moez.QKSMS.manager.NotificationManager
import com.moez.QKSMS.manager.ShortcutManager import com.moez.QKSMS.manager.ShortcutManager
import com.moez.QKSMS.repository.ConversationRepository import com.moez.QKSMS.repository.ConversationRepository
@@ -30,7 +30,7 @@ import javax.inject.Inject
class ReceiveSms @Inject constructor( class ReceiveSms @Inject constructor(
private val conversationRepo: ConversationRepository, private val conversationRepo: ConversationRepository,
private val externalBlockingManager: ExternalBlockingManager, private val blockingClient: BlockingClient,
private val messageRepo: MessageRepository, private val messageRepo: MessageRepository,
private val notificationManager: NotificationManager, private val notificationManager: NotificationManager,
private val updateBadge: UpdateBadge, private val updateBadge: UpdateBadge,
@@ -45,7 +45,7 @@ class ReceiveSms @Inject constructor(
.filter { .filter {
// Don't continue if the sender is blocked // Don't continue if the sender is blocked
val address = it.messages[0].displayOriginatingAddress val address = it.messages[0].displayOriginatingAddress
!externalBlockingManager.shouldBlock(address).blockingGet() !blockingClient.shouldBlock(address).blockingGet()
} }
.map { .map {
val messages = it.messages val messages = it.messages
@@ -73,7 +73,6 @@ class BlockedViewModel @Inject constructor(
"org.mistergroup.shouldianswerpersonal", "org.mistergroup.shouldianswerpersonal",
"org.mistergroup.muzutozvednout") "org.mistergroup.muzutozvednout")
.any(context::isInstalled) .any(context::isInstalled)
} }
.map { installed -> .map { installed ->
if (!installed) { if (!installed) {
@@ -25,6 +25,8 @@ import android.content.Context
import android.preference.PreferenceManager import android.preference.PreferenceManager
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.f2prateek.rx.preferences2.RxSharedPreferences import com.f2prateek.rx.preferences2.RxSharedPreferences
import com.moez.QKSMS.blocking.BlockingClient
import com.moez.QKSMS.blocking.ShouldIAnswerBlockingClient
import com.moez.QKSMS.common.ViewModelFactory import com.moez.QKSMS.common.ViewModelFactory
import com.moez.QKSMS.common.util.NotificationManagerImpl import com.moez.QKSMS.common.util.NotificationManagerImpl
import com.moez.QKSMS.common.util.ShortcutManagerImpl import com.moez.QKSMS.common.util.ShortcutManagerImpl
@@ -40,8 +42,6 @@ import com.moez.QKSMS.manager.AnalyticsManager
import com.moez.QKSMS.manager.AnalyticsManagerImpl import com.moez.QKSMS.manager.AnalyticsManagerImpl
import com.moez.QKSMS.manager.ChangelogManager import com.moez.QKSMS.manager.ChangelogManager
import com.moez.QKSMS.manager.ChangelogManagerImpl import com.moez.QKSMS.manager.ChangelogManagerImpl
import com.moez.QKSMS.manager.ExternalBlockingManager
import com.moez.QKSMS.manager.ExternalBlockingManagerImpl
import com.moez.QKSMS.manager.KeyManager import com.moez.QKSMS.manager.KeyManager
import com.moez.QKSMS.manager.KeyManagerImpl import com.moez.QKSMS.manager.KeyManagerImpl
import com.moez.QKSMS.manager.NotificationManager import com.moez.QKSMS.manager.NotificationManager
@@ -129,7 +129,7 @@ class AppModule(private var application: Application) {
fun provideAnalyticsManager(manager: AnalyticsManagerImpl): AnalyticsManager = manager fun provideAnalyticsManager(manager: AnalyticsManagerImpl): AnalyticsManager = manager
@Provides @Provides
fun externalBlockingManager(manager: ExternalBlockingManagerImpl): ExternalBlockingManager = manager fun externalBlockingManager(manager: ShouldIAnswerBlockingClient): BlockingClient = manager
@Provides @Provides
fun changelogManager(manager: ChangelogManagerImpl): ChangelogManager = manager fun changelogManager(manager: ChangelogManagerImpl): ChangelogManager = manager