forked from upstream-mirrors/quik
Allow toggling of SIA integration, and direct user to play store if not installed
This commit is contained in:
@@ -30,10 +30,14 @@ import androidx.os.bundleOf
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.subjects.SingleSubject
|
||||
import timber.log.Timber
|
||||
import util.Preferences
|
||||
import util.tryOrNull
|
||||
import javax.inject.Inject
|
||||
|
||||
class ExternalBlockingManagerImpl @Inject constructor(private val context: Context) : ExternalBlockingManager {
|
||||
class ExternalBlockingManagerImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val prefs: Preferences
|
||||
) : ExternalBlockingManager {
|
||||
|
||||
companion object {
|
||||
const val RATING_UNKNOWN = 0
|
||||
@@ -48,23 +52,33 @@ class ExternalBlockingManagerImpl @Inject constructor(private val context: Conte
|
||||
* Return a Single<Boolean> which emits whether or not the given [address] should be blocked
|
||||
*/
|
||||
override fun shouldBlock(address: String): Single<Boolean> {
|
||||
return Binder(context, address).shouldBlock()
|
||||
return Binder(context, prefs, address).shouldBlock()
|
||||
}
|
||||
|
||||
private class Binder(private val context: Context, private val address: String) : ServiceConnection {
|
||||
private class Binder(
|
||||
private val context: Context,
|
||||
private val prefs: Preferences,
|
||||
private val address: String
|
||||
) : ServiceConnection {
|
||||
|
||||
private val subject: SingleSubject<Boolean> = SingleSubject.create()
|
||||
private var serviceMessenger: Messenger? = null
|
||||
private var isBound: Boolean = false
|
||||
|
||||
fun shouldBlock(): Single<Boolean> {
|
||||
// If either version of Should I Answer? is installed, build the intent to request a rating
|
||||
val intent = tryOrNull {
|
||||
context.packageManager.getApplicationInfo("org.mistergroup.shouldianswerpersonal", 0).enabled
|
||||
Intent("org.mistergroup.shouldianswerpersonal.PublicService").setPackage("org.mistergroup.shouldianswerpersonal")
|
||||
} ?: tryOrNull {
|
||||
context.packageManager.getApplicationInfo("org.mistergroup.muzutozvednout", 0).enabled
|
||||
Intent("org.mistergroup.muzutozvednout.PublicService").setPackage("org.mistergroup.muzutozvednout")
|
||||
|
||||
var intent: Intent? = null
|
||||
|
||||
// If either version of Should I Answer? is installed and SIA is enabled, build the
|
||||
// intent to request a rating
|
||||
if (prefs.sia.get()) {
|
||||
intent = tryOrNull {
|
||||
context.packageManager.getApplicationInfo("org.mistergroup.shouldianswerpersonal", 0).enabled
|
||||
Intent("org.mistergroup.shouldianswerpersonal.PublicService").setPackage("org.mistergroup.shouldianswerpersonal")
|
||||
} ?: tryOrNull {
|
||||
context.packageManager.getApplicationInfo("org.mistergroup.muzutozvednout", 0).enabled
|
||||
Intent("org.mistergroup.muzutozvednout.PublicService").setPackage("org.mistergroup.muzutozvednout")
|
||||
}
|
||||
}
|
||||
|
||||
// If the intent isn't null, bind the service and wait for a result. Otherwise, don't block
|
||||
|
||||
@@ -91,14 +91,11 @@ class MessageRepositoryImpl @Inject constructor(
|
||||
.findAll())
|
||||
}
|
||||
|
||||
override fun getBlockedConversations(): Flowable<List<Conversation>> {
|
||||
override fun getBlockedConversations(): RealmResults<Conversation> {
|
||||
return Realm.getDefaultInstance()
|
||||
.where(Conversation::class.java)
|
||||
.equalTo("blocked", true)
|
||||
.findAllAsync()
|
||||
.asFlowable()
|
||||
.filter { it.isLoaded }
|
||||
.map { it.toList() }
|
||||
}
|
||||
|
||||
override fun getConversationAsync(threadId: Long): Conversation {
|
||||
|
||||
@@ -45,6 +45,7 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
|
||||
val nightStart = rxPrefs.getString("nightStart", "6:00 PM")
|
||||
val nightEnd = rxPrefs.getString("nightEnd", "6:00 AM")
|
||||
val black = rxPrefs.getBoolean("black", false)
|
||||
val sia = rxPrefs.getBoolean("sia", false)
|
||||
val autoEmoji = rxPrefs.getBoolean("autoEmoji", true)
|
||||
val delivery = rxPrefs.getBoolean("delivery", false)
|
||||
val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL)
|
||||
|
||||
Reference in New Issue
Block a user