Show blocking reason if available

This commit is contained in:
moezbhatti
2019-10-10 19:15:38 -04:00
parent 56d13dfe3e
commit d46193abba
16 changed files with 182 additions and 80 deletions
@@ -50,15 +50,15 @@ class CallControlBlockingClient @Inject constructor(
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
val uri = Uri.withAppendedPath(CallControl.LOOKUP_TEXT_URI, address)
val blocked = tryOrNull {
val blockReason = tryOrNull {
context.contentResolver.query(uri, projection, null, null, null) // Query URI
?.use { cursor -> cursor.map(::LookupResult) } // Map to Result object
?.any { result -> result.blockReason != null } // Check if any are blocked
} == true // If none are blocked or we errored at some point, return false
?.find { result -> result.blockReason != null } // Check if any are blocked
}?.blockReason // If none are blocked or we errored at some point, return false
when (blocked) {
true -> BlockingClient.Action.BLOCK
false -> BlockingClient.Action.UNBLOCK
when (blockReason) {
null -> BlockingClient.Action.Unblock
else -> BlockingClient.Action.Block(blockReason)
}
}
@@ -33,8 +33,8 @@ class QksmsBlockingClient @Inject constructor(
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
when (blockingRepo.isBlocked(address)) {
true -> BlockingClient.Action.BLOCK
false -> BlockingClient.Action.UNBLOCK
true -> BlockingClient.Action.Block()
false -> BlockingClient.Action.Unblock
}
}
@@ -59,8 +59,8 @@ class ShouldIAnswerBlockingClient @Inject constructor(
return Binder(context, address).isBlocked()
.map { blocked ->
when (blocked) {
true -> BlockingClient.Action.BLOCK
false -> BlockingClient.Action.DO_NOTHING
true -> BlockingClient.Action.Block()
false -> BlockingClient.Action.DoNothing
}
}
}