#1304 - Create blocking client for built-in android blocking

This commit is contained in:
moezbhatti
2019-06-20 01:27:15 -04:00
parent 60f41d9996
commit afa6199897
9 changed files with 125 additions and 12 deletions
@@ -18,6 +18,7 @@
*/
package com.moez.QKSMS.blocking
import io.reactivex.Completable
import io.reactivex.Single
interface BlockingClient {
@@ -25,6 +26,28 @@ interface BlockingClient {
/**
* Return a Single<Boolean> which emits whether or not the given [address] should be blocked
*/
fun shouldBlock(address: String): Single<Boolean>
fun isBlocked(address: String): Single<Boolean>
/**
* Returns true if the client is capable of blocking the address in the manager without any
* further user input
*/
fun canBlock(): Boolean = false
/**
* Blocks the number or opens the manager
*/
fun block(address: String): Completable
/**
* Returns true if the client is capable of unblocking the address in the manager without any
* further user input
*/
fun canUnblock(): Boolean = false
/**
* Unblocks the number or opens the manager
*/
fun unblock(address: String): Completable
}
@@ -57,7 +57,7 @@ class ReceiveMms @Inject constructor(
// to check if it should be blocked after we've pulled it into realm. If it
// turns out that it should be dropped, then delete it
// TODO Don't store blocked messages in the first place
val shouldBlock = blockingClient.shouldBlock(message.address).blockingGet()
val shouldBlock = blockingClient.isBlocked(message.address).blockingGet()
val shouldDrop = prefs.drop.get()
Timber.v("block=$shouldBlock, drop=$shouldDrop")
@@ -49,7 +49,7 @@ class ReceiveSms @Inject constructor(
// Don't continue if the sender is blocked
val messages = it.messages
val address = messages[0].displayOriginatingAddress
val shouldBlock = blockingClient.shouldBlock(address).blockingGet()
val shouldBlock = blockingClient.isBlocked(address).blockingGet()
val shouldDrop = prefs.drop.get()
Timber.v("block=$shouldBlock, drop=$shouldDrop")
@@ -0,0 +1,10 @@
package com.moez.QKSMS.model
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
open class BlockedNumber(
@PrimaryKey var id: Long = 0,
var address: String = ""
) : RealmObject()