When necessary, show dialog prompting user to go to external blocking manager

This commit is contained in:
moezbhatti
2019-06-21 02:40:11 -04:00
parent 25132b58d6
commit a3824825f6
21 changed files with 195 additions and 83 deletions
@@ -0,0 +1,37 @@
package com.moez.QKSMS.blocking
import com.moez.QKSMS.util.Preferences
import io.reactivex.Completable
import io.reactivex.Single
import javax.inject.Inject
import javax.inject.Singleton
/**
* Delegates requests to the active blocking client
*/
@Singleton
class BlockingManager @Inject constructor(
private val prefs: Preferences,
private val callControlBlockingClient: CallControlBlockingClient,
private val qkBlockingClient: QkBlockingClient,
private val shouldIAnswerBlockingClient: ShouldIAnswerBlockingClient
) : BlockingClient {
private val client: BlockingClient
get() = when (prefs.blockingManager.get()) {
Preferences.BLOCKING_MANAGER_SIA -> shouldIAnswerBlockingClient
Preferences.BLOCKING_MANAGER_CC -> callControlBlockingClient
else -> qkBlockingClient
}
override fun isBlocked(address: String): Single<Boolean> = client.isBlocked(address)
override fun canBlock(): Boolean = client.canBlock()
override fun block(addresses: List<String>): Completable = client.block(addresses)
override fun canUnblock(): Boolean = client.canUnblock()
override fun unblock(addresses: List<String>): Completable = client.unblock(addresses)
}
@@ -55,11 +55,14 @@ class CallControlBlockingClient @Inject constructor(
override fun canBlock(): Boolean = true override fun canBlock(): Boolean = true
override fun block(address: String): Completable = Completable.fromCallable { override fun block(addresses: List<String>): Completable = Completable.fromCallable {
CallControl.report(context, CallControl.Report(address)) val reports = addresses.map { CallControl.Report(it) }
CallControl.report(context, arrayListOf<CallControl.Report>().apply { addAll(reports) })
} }
override fun unblock(address: String): Completable = Completable.fromCallable { override fun unblock(addresses: List<String>): Completable = Completable.fromCallable {
// Only show a particular address if we're only unblocking that one
val address = addresses.takeIf { it.size == 1 }?.first()
CallControl.openBlockedList(context, address) CallControl.openBlockedList(context, address)
} }
@@ -19,6 +19,7 @@
package com.moez.QKSMS.blocking package com.moez.QKSMS.blocking
import android.content.Context import android.content.Context
import android.content.Intent
import android.os.Build import android.os.Build
import android.provider.BlockedNumberContract import android.provider.BlockedNumberContract
import android.telecom.TelecomManager import android.telecom.TelecomManager
@@ -45,11 +46,12 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block
override fun canBlock(): Boolean = Build.VERSION.SDK_INT < 24 override fun canBlock(): Boolean = Build.VERSION.SDK_INT < 24
override fun block(address: String): Completable = Completable.fromCallable { override fun block(addresses: List<String>): Completable = Completable.fromCallable {
when { when {
Build.VERSION.SDK_INT >= 24 -> { Build.VERSION.SDK_INT >= 24 -> {
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
val intent = telecomManager.createManageBlockedNumbersIntent() val intent = telecomManager.createManageBlockedNumbersIntent()
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent) context.startActivity(intent)
} }
@@ -58,7 +60,7 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block
.max("id")?.toLong() ?: -1 .max("id")?.toLong() ?: -1
realm.executeTransaction { realm.executeTransaction {
realm.insert(BlockedNumber(maxId + 1, address)) realm.insert(addresses.mapIndexed { index, address -> BlockedNumber(maxId + 1 + index, address) })
} }
} }
} }
@@ -66,15 +68,19 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block
override fun canUnblock(): Boolean = true override fun canUnblock(): Boolean = true
override fun unblock(address: String): Completable = Completable.fromCallable { override fun unblock(addresses: List<String>): Completable = Completable.fromCallable {
when { when {
Build.VERSION.SDK_INT >= 24 -> BlockedNumberContract.unblock(context, address) Build.VERSION.SDK_INT >= 24 -> addresses.forEach { address ->
BlockedNumberContract.unblock(context, address)
}
else -> Realm.getDefaultInstance().use { realm -> else -> Realm.getDefaultInstance().use { realm ->
val ids = realm val ids = realm
.where(BlockedNumber::class.java) .where(BlockedNumber::class.java)
.findAll() .findAll()
.filter { number -> PhoneNumberUtils.compare(number.address, address) } .filter { number ->
addresses.any { address -> PhoneNumberUtils.compare(number.address, address) }
}
.map { number -> number.id } .map { number -> number.id }
.toLongArray() .toLongArray()
@@ -56,9 +56,9 @@ class ShouldIAnswerBlockingClient @Inject constructor(
return Binder(context, prefs, address).isBlocked() return Binder(context, prefs, address).isBlocked()
} }
override fun block(address: String): Completable = Completable.fromCallable { showSia() } override fun block(addresses: List<String>): Completable = Completable.fromCallable { showSia() }
override fun unblock(address: String): Completable = Completable.fromCallable { showSia() } override fun unblock(addresses: List<String>): Completable = Completable.fromCallable { showSia() }
private fun showSia() { private fun showSia() {
val pm = context.packageManager val pm = context.packageManager
@@ -141,6 +141,13 @@ class ConversationRepositoryImpl @Inject constructor(
.findFirst() .findFirst()
} }
override fun getConversations(vararg threadIds: Long): RealmResults<Conversation> {
return Realm.getDefaultInstance()
.where(Conversation::class.java)
.anyOf("id", threadIds)
.findAll()
}
override fun getThreadId(recipient: String): Long? { override fun getThreadId(recipient: String): Long? {
return getThreadId(listOf(recipient)) return getThreadId(listOf(recipient))
} }
@@ -35,9 +35,9 @@ interface BlockingClient {
fun canBlock(): Boolean = false fun canBlock(): Boolean = false
/** /**
* Blocks the number or opens the manager * Blocks the numbers or opens the manager
*/ */
fun block(address: String): Completable fun block(addresses: List<String>): Completable
/** /**
* Returns true if the client is capable of unblocking the address in the manager without any * Returns true if the client is capable of unblocking the address in the manager without any
@@ -46,8 +46,8 @@ interface BlockingClient {
fun canUnblock(): Boolean = false fun canUnblock(): Boolean = false
/** /**
* Unblocks the number or opens the manager * Unblocks the numbers or opens the manager
*/ */
fun unblock(address: String): Completable fun unblock(addresses: List<String>): Completable
} }
@@ -43,6 +43,11 @@ interface ConversationRepository {
fun getConversation(threadId: Long): Conversation? fun getConversation(threadId: Long): Conversation?
/**
* Returns all conversations with an id in [threadIds]
*/
fun getConversations(vararg threadIds: Long): RealmResults<Conversation>
fun getThreadId(recipient: String): Long? fun getThreadId(recipient: String): Long?
fun getThreadId(recipients: Collection<String>): Long? fun getThreadId(recipients: Collection<String>): Long?
@@ -60,6 +60,10 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
const val SWIPE_ACTION_CALL = 3 const val SWIPE_ACTION_CALL = 3
const val SWIPE_ACTION_READ = 4 const val SWIPE_ACTION_READ = 4
const val SWIPE_ACTION_UNREAD = 5 const val SWIPE_ACTION_UNREAD = 5
const val BLOCKING_MANAGER_QKSMS = 0
const val BLOCKING_MANAGER_CC = 1
const val BLOCKING_MANAGER_SIA = 2
} }
// Internal // Internal
@@ -76,6 +80,7 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
val black = rxPrefs.getBoolean("black", false) val black = rxPrefs.getBoolean("black", false)
val systemFont = rxPrefs.getBoolean("systemFont", false) val systemFont = rxPrefs.getBoolean("systemFont", false)
val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL) val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL)
val blockingManager = rxPrefs.getInteger("blockingManager", BLOCKING_MANAGER_QKSMS)
val callControl = rxPrefs.getBoolean("callControl", false) val callControl = rxPrefs.getBoolean("callControl", false)
val sia = rxPrefs.getBoolean("sia", false) val sia = rxPrefs.getBoolean("sia", false)
val drop = rxPrefs.getBoolean("drop", false) val drop = rxPrefs.getBoolean("drop", false)
@@ -18,7 +18,6 @@
*/ */
package com.moez.QKSMS.feature.blocked package com.moez.QKSMS.feature.blocked
import android.app.AlertDialog
import android.os.Bundle import android.os.Bundle
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProviders
@@ -26,8 +25,6 @@ import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R import com.moez.QKSMS.R
import com.moez.QKSMS.common.base.QkThemedActivity import com.moez.QKSMS.common.base.QkThemedActivity
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.blocked_activity.* import kotlinx.android.synthetic.main.blocked_activity.*
import kotlinx.android.synthetic.main.settings_switch_widget.view.* import kotlinx.android.synthetic.main.settings_switch_widget.view.*
import javax.inject.Inject import javax.inject.Inject
@@ -40,8 +37,7 @@ class BlockedActivity : QkThemedActivity(), BlockedView {
override val ccClickedIntent by lazy { callControl.clicks() } override val ccClickedIntent by lazy { callControl.clicks() }
override val siaClickedIntent by lazy { shouldIAnswer.clicks() } override val siaClickedIntent by lazy { shouldIAnswer.clicks() }
override val dropClickedIntent by lazy { drop.clicks() } override val dropClickedIntent by lazy { drop.clicks() }
override val unblockIntent by lazy { blockedAdapter.unblock } override val conversationClicks by lazy { blockedAdapter.clicks }
override val confirmUnblockIntent: Subject<Long> = PublishSubject.create()
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[BlockedViewModel::class.java] } private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[BlockedViewModel::class.java] }
@@ -65,13 +61,4 @@ class BlockedActivity : QkThemedActivity(), BlockedView {
blockedAdapter.updateData(state.data) blockedAdapter.updateData(state.data)
} }
override fun showUnblockDialog(threadId: Long) {
AlertDialog.Builder(this)
.setTitle(R.string.blocked_unblock_dialog_title)
.setMessage(R.string.blocked_unblock_dialog_message)
.setPositiveButton(R.string.button_unblock) { _, _ -> confirmUnblockIntent.onNext(threadId) }
.setNegativeButton(R.string.button_cancel, null)
.show()
}
} }
@@ -30,14 +30,14 @@ import javax.inject.Inject
class BlockedAdapter @Inject constructor() : QkRealmAdapter<Conversation>() { class BlockedAdapter @Inject constructor() : QkRealmAdapter<Conversation>() {
val unblock: PublishSubject<Long> = PublishSubject.create() val clicks: PublishSubject<Long> = PublishSubject.create()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false) val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false)
return QkViewHolder(view).apply { return QkViewHolder(view).apply {
view.setOnClickListener { view.setOnClickListener {
val conversation = getItem(adapterPosition) ?: return@setOnClickListener val conversation = getItem(adapterPosition) ?: return@setOnClickListener
unblock.onNext(conversation.id) clicks.onNext(conversation.id)
} }
} }
} }
@@ -47,6 +47,7 @@ class BlockedAdapter @Inject constructor() : QkRealmAdapter<Conversation>() {
val view = holder.containerView val view = holder.containerView
view.avatars.contacts = conversation.recipients view.avatars.contacts = conversation.recipients
view.title.collapseEnabled = conversation.recipients.size > 1
view.title.text = conversation.getTitle() view.title.text = conversation.getTitle()
} }
@@ -26,9 +26,6 @@ interface BlockedView : QkView<BlockedState> {
val ccClickedIntent: Observable<*> val ccClickedIntent: Observable<*>
val siaClickedIntent: Observable<*> val siaClickedIntent: Observable<*>
val dropClickedIntent: Observable<*> val dropClickedIntent: Observable<*>
val unblockIntent: Observable<Long> val conversationClicks: Observable<Long>
val confirmUnblockIntent: Observable<Long>
fun showUnblockDialog(threadId: Long) }
}
@@ -22,7 +22,6 @@ import android.content.Context
import com.moez.QKSMS.common.Navigator import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkViewModel import com.moez.QKSMS.common.base.QkViewModel
import com.moez.QKSMS.common.util.extensions.isInstalled import com.moez.QKSMS.common.util.extensions.isInstalled
import com.moez.QKSMS.interactor.MarkUnblocked
import com.moez.QKSMS.manager.AnalyticsManager import com.moez.QKSMS.manager.AnalyticsManager
import com.moez.QKSMS.repository.ConversationRepository import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.util.Preferences import com.moez.QKSMS.util.Preferences
@@ -35,7 +34,6 @@ class BlockedViewModel @Inject constructor(
private val context: Context, private val context: Context,
private val analytics: AnalyticsManager, private val analytics: AnalyticsManager,
private val conversationRepo: ConversationRepository, private val conversationRepo: ConversationRepository,
private val markUnblocked: MarkUnblocked,
private val navigator: Navigator, private val navigator: Navigator,
private val prefs: Preferences private val prefs: Preferences
) : QkViewModel<BlockedView, BlockedState>(BlockedState()) { ) : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
@@ -93,15 +91,9 @@ class BlockedViewModel @Inject constructor(
.autoDisposable(view.scope()) .autoDisposable(view.scope())
.subscribe { prefs.drop.set(!prefs.drop.get()) } .subscribe { prefs.drop.set(!prefs.drop.get()) }
// Show confirm unblock conversation dialog view.conversationClicks
view.unblockIntent
.autoDisposable(view.scope()) .autoDisposable(view.scope())
.subscribe { threadId -> view.showUnblockDialog(threadId) } .subscribe { threadId -> navigator.showConversation(threadId) }
// Unblock conversation
view.confirmUnblockIntent
.autoDisposable(view.scope())
.subscribe { threadId -> markUnblocked.execute(listOf(threadId)) }
} }
} }
@@ -0,0 +1,75 @@
package com.moez.QKSMS.feature.blocked
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import com.moez.QKSMS.R
import com.moez.QKSMS.blocking.BlockingClient
import com.moez.QKSMS.interactor.MarkBlocked
import com.moez.QKSMS.interactor.MarkUnblocked
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.util.Preferences
import javax.inject.Inject
// TODO: Once we have a custom dialog based on conductor, turn this into a controller
class BlockingDialog @Inject constructor(
private val blockingManager: BlockingClient,
private val context: Context,
private val conversationRepo: ConversationRepository,
private val prefs: Preferences,
private val markBlocked: MarkBlocked,
private val markUnblocked: MarkUnblocked
) {
fun show(activity: Activity, conversationIds: List<Long>, block: Boolean) {
val addresses = conversationIds.toLongArray()
.let(conversationRepo::getConversations)
.flatMap { conversation -> conversation.recipients }
.map { it.address }
.distinct()
// If we can block/unblock in the external manager, then just fire that off and exit
if (block) {
markBlocked.execute(conversationIds)
if (blockingManager.canBlock()) {
blockingManager.block(addresses).subscribe()
return
}
} else {
markUnblocked.execute(conversationIds)
if (blockingManager.canUnblock()) {
blockingManager.unblock(addresses).subscribe()
return
}
}
val res = when (block) {
true -> R.plurals.settings_blocking_block_external
false -> R.plurals.settings_blocking_unblock_external
}
val manager = context.getString(when (prefs.blockingManager.get()) {
Preferences.BLOCKING_MANAGER_SIA -> R.string.settings_should_i_answer_title
Preferences.BLOCKING_MANAGER_CC -> R.string.settings_call_control_title
else -> R.string.settings_blocking_manager_android
})
val message = context.resources.getQuantityString(res, addresses.size, manager)
// Otherwise, show a dialog asking the user if they want to be directed to the external
// blocking manager
AlertDialog.Builder(activity)
.setTitle(R.string.main_menu_block)
.setMessage(message)
.setPositiveButton(R.string.button_yes) { _, _ ->
when (block) {
true -> blockingManager.block(addresses)
false -> blockingManager.unblock(addresses)
}.subscribe()
}
.setNegativeButton(R.string.button_cancel) { _, _ -> }
.create()
.show()
}
}
@@ -30,6 +30,7 @@ import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
import com.moez.QKSMS.common.util.extensions.scrapViews import com.moez.QKSMS.common.util.extensions.scrapViews
import com.moez.QKSMS.common.util.extensions.setVisible import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.common.widget.FieldDialog import com.moez.QKSMS.common.widget.FieldDialog
import com.moez.QKSMS.feature.blocked.BlockingDialog
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoModule import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoModule
import com.moez.QKSMS.feature.themepicker.ThemePickerController import com.moez.QKSMS.feature.themepicker.ThemePickerController
import com.moez.QKSMS.injection.appComponent import com.moez.QKSMS.injection.appComponent
@@ -46,6 +47,7 @@ class ConversationInfoController(
) : QkController<ConversationInfoView, ConversationInfoState, ConversationInfoPresenter>(), ConversationInfoView { ) : QkController<ConversationInfoView, ConversationInfoState, ConversationInfoPresenter>(), ConversationInfoView {
@Inject override lateinit var presenter: ConversationInfoPresenter @Inject override lateinit var presenter: ConversationInfoPresenter
@Inject lateinit var blockingDialog: BlockingDialog
@Inject lateinit var navigator: Navigator @Inject lateinit var navigator: Navigator
@Inject lateinit var recipientAdapter: ConversationRecipientAdapter @Inject lateinit var recipientAdapter: ConversationRecipientAdapter
@Inject lateinit var mediaAdapter: ConversationMediaAdapter @Inject lateinit var mediaAdapter: ConversationMediaAdapter
@@ -142,6 +144,10 @@ class ConversationInfoController(
.popChangeHandler(QkChangeHandler())) .popChangeHandler(QkChangeHandler()))
} }
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
blockingDialog.show(activity!!, conversations, block)
}
override fun showDeleteDialog() { override fun showDeleteDialog() {
AlertDialog.Builder(activity!!) AlertDialog.Builder(activity!!)
.setTitle(R.string.dialog_delete_title) .setTitle(R.string.dialog_delete_title)
@@ -23,9 +23,7 @@ import com.moez.QKSMS.common.base.QkPresenter
import com.moez.QKSMS.extensions.asObservable import com.moez.QKSMS.extensions.asObservable
import com.moez.QKSMS.interactor.DeleteConversations import com.moez.QKSMS.interactor.DeleteConversations
import com.moez.QKSMS.interactor.MarkArchived import com.moez.QKSMS.interactor.MarkArchived
import com.moez.QKSMS.interactor.MarkBlocked
import com.moez.QKSMS.interactor.MarkUnarchived import com.moez.QKSMS.interactor.MarkUnarchived
import com.moez.QKSMS.interactor.MarkUnblocked
import com.moez.QKSMS.manager.PermissionManager import com.moez.QKSMS.manager.PermissionManager
import com.moez.QKSMS.model.Conversation import com.moez.QKSMS.model.Conversation
import com.moez.QKSMS.repository.ConversationRepository import com.moez.QKSMS.repository.ConversationRepository
@@ -46,8 +44,6 @@ class ConversationInfoPresenter @Inject constructor(
private val deleteConversations: DeleteConversations, private val deleteConversations: DeleteConversations,
private val markArchived: MarkArchived, private val markArchived: MarkArchived,
private val markUnarchived: MarkUnarchived, private val markUnarchived: MarkUnarchived,
private val markBlocked: MarkBlocked,
private val markUnblocked: MarkUnblocked,
private val navigator: Navigator, private val navigator: Navigator,
private val permissionManager: PermissionManager private val permissionManager: PermissionManager
) : QkPresenter<ConversationInfoView, ConversationInfoState>( ) : QkPresenter<ConversationInfoView, ConversationInfoState>(
@@ -71,8 +67,6 @@ class ConversationInfoPresenter @Inject constructor(
disposables += markArchived disposables += markArchived
disposables += markUnarchived disposables += markUnarchived
disposables += markBlocked
disposables += markUnblocked
disposables += deleteConversations disposables += deleteConversations
// Update the recipients whenever they change // Update the recipients whenever they change
@@ -145,12 +139,7 @@ class ConversationInfoPresenter @Inject constructor(
view.blockClicks() view.blockClicks()
.withLatestFrom(conversation) { _, conversation -> conversation } .withLatestFrom(conversation) { _, conversation -> conversation }
.autoDisposable(view.scope()) .autoDisposable(view.scope())
.subscribe { conversation -> .subscribe { conversation -> view.showBlockingDialog(listOf(conversation.id), !conversation.blocked) }
when (conversation.blocked) {
true -> markUnblocked.execute(listOf(conversation.id))
false -> markBlocked.execute(listOf(conversation.id))
}
}
// Show the delete confirmation dialog // Show the delete confirmation dialog
view.deleteClicks() view.deleteClicks()
@@ -34,6 +34,7 @@ interface ConversationInfoView : QkViewContract<ConversationInfoState> {
fun showNameDialog(name: String) fun showNameDialog(name: String)
fun showThemePicker(threadId: Long) fun showThemePicker(threadId: Long)
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
fun showDeleteDialog() fun showDeleteDialog()
} }
@@ -51,6 +51,7 @@ import com.moez.QKSMS.common.util.extensions.scrapViews
import com.moez.QKSMS.common.util.extensions.setBackgroundTint import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.common.util.extensions.setVisible import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.feature.blocked.BlockingDialog
import com.moez.QKSMS.feature.changelog.ChangelogDialog import com.moez.QKSMS.feature.changelog.ChangelogDialog
import com.moez.QKSMS.feature.conversations.ConversationItemTouchCallback import com.moez.QKSMS.feature.conversations.ConversationItemTouchCallback
import com.moez.QKSMS.feature.conversations.ConversationsAdapter import com.moez.QKSMS.feature.conversations.ConversationsAdapter
@@ -71,6 +72,7 @@ import javax.inject.Inject
class MainActivity : QkThemedActivity(), MainView { class MainActivity : QkThemedActivity(), MainView {
@Inject lateinit var blockingDialog: BlockingDialog
@Inject lateinit var disposables: CompositeDisposable @Inject lateinit var disposables: CompositeDisposable
@Inject lateinit var navigator: Navigator @Inject lateinit var navigator: Navigator
@Inject lateinit var conversationsAdapter: ConversationsAdapter @Inject lateinit var conversationsAdapter: ConversationsAdapter
@@ -156,7 +158,8 @@ class MainActivity : QkThemedActivity(), MainView {
.autoDisposable(scope()) .autoDisposable(scope())
.subscribe { theme -> .subscribe { theme ->
// Set the color for the drawer icons // Set the color for the drawer icons
val states = arrayOf(intArrayOf(android.R.attr.state_activated), intArrayOf(-android.R.attr.state_activated)) val states = arrayOf(intArrayOf(android.R.attr.state_activated),
intArrayOf(-android.R.attr.state_activated))
resolveThemeColor(android.R.attr.textColorSecondary) resolveThemeColor(android.R.attr.textColorSecondary)
.let { textSecondary -> ColorStateList(states, intArrayOf(theme.theme, textSecondary)) } .let { textSecondary -> ColorStateList(states, intArrayOf(theme.theme, textSecondary)) }
.let { tintList -> .let { tintList ->
@@ -268,8 +271,10 @@ class MainActivity : QkThemedActivity(), MainView {
inbox.isActivated = state.page is Inbox inbox.isActivated = state.page is Inbox
archived.isActivated = state.page is Archived archived.isActivated = state.page is Archived
if (drawerLayout.isDrawerOpen(GravityCompat.START) && !state.drawerOpen) drawerLayout.closeDrawer(GravityCompat.START) if (drawerLayout.isDrawerOpen(GravityCompat.START) && !state.drawerOpen) drawerLayout.closeDrawer(
else if (!drawerLayout.isDrawerVisible(GravityCompat.START) && state.drawerOpen) drawerLayout.openDrawer(GravityCompat.START) GravityCompat.START)
else if (!drawerLayout.isDrawerVisible(GravityCompat.START) && state.drawerOpen) drawerLayout.openDrawer(
GravityCompat.START)
when (state.syncing) { when (state.syncing) {
is SyncRepository.SyncProgress.Idle -> { is SyncRepository.SyncProgress.Idle -> {
@@ -341,6 +346,10 @@ class MainActivity : QkThemedActivity(), MainView {
conversationsAdapter.clearSelection() conversationsAdapter.clearSelection()
} }
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
blockingDialog.show(this, conversations, block)
}
override fun showDeleteDialog(conversations: List<Long>) { override fun showDeleteDialog(conversations: List<Long>) {
val count = conversations.size val count = conversations.size
AlertDialog.Builder(this) AlertDialog.Builder(this)
@@ -46,6 +46,7 @@ interface MainView : QkView<MainState> {
fun requestPermissions() fun requestPermissions()
fun clearSearch() fun clearSearch()
fun clearSelection() fun clearSelection()
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
fun showDeleteDialog(conversations: List<Long>) fun showDeleteDialog(conversations: List<Long>)
fun showChangelog(changelog: ChangelogManager.Changelog) fun showChangelog(changelog: ChangelogManager.Changelog)
fun showArchivedSnackbar() fun showArchivedSnackbar()
@@ -27,7 +27,6 @@ import com.moez.QKSMS.extensions.removeAccents
import com.moez.QKSMS.interactor.DeleteConversations import com.moez.QKSMS.interactor.DeleteConversations
import com.moez.QKSMS.interactor.MarkAllSeen import com.moez.QKSMS.interactor.MarkAllSeen
import com.moez.QKSMS.interactor.MarkArchived import com.moez.QKSMS.interactor.MarkArchived
import com.moez.QKSMS.interactor.MarkBlocked
import com.moez.QKSMS.interactor.MarkPinned import com.moez.QKSMS.interactor.MarkPinned
import com.moez.QKSMS.interactor.MarkRead import com.moez.QKSMS.interactor.MarkRead
import com.moez.QKSMS.interactor.MarkUnarchived import com.moez.QKSMS.interactor.MarkUnarchived
@@ -64,7 +63,6 @@ class MainViewModel @Inject constructor(
private val conversationRepo: ConversationRepository, private val conversationRepo: ConversationRepository,
private val deleteConversations: DeleteConversations, private val deleteConversations: DeleteConversations,
private val markArchived: MarkArchived, private val markArchived: MarkArchived,
private val markBlocked: MarkBlocked,
private val markPinned: MarkPinned, private val markPinned: MarkPinned,
private val markRead: MarkRead, private val markRead: MarkRead,
private val markUnarchived: MarkUnarchived, private val markUnarchived: MarkUnarchived,
@@ -319,7 +317,7 @@ class MainViewModel @Inject constructor(
view.optionsItemIntent view.optionsItemIntent
.filter { itemId -> itemId == R.id.block } .filter { itemId -> itemId == R.id.block }
.withLatestFrom(view.conversationsSelectedIntent) { _, conversations -> .withLatestFrom(view.conversationsSelectedIntent) { _, conversations ->
markBlocked.execute(conversations) view.showBlockingDialog(conversations, true)
view.clearSelection() view.clearSelection()
} }
.autoDisposable(view.scope()) .autoDisposable(view.scope())
@@ -26,9 +26,7 @@ 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.BlockingClient
import com.moez.QKSMS.blocking.CallControlBlockingClient import com.moez.QKSMS.blocking.BlockingManager
import com.moez.QKSMS.blocking.QkBlockingClient
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
@@ -78,7 +76,6 @@ import com.moez.QKSMS.repository.ScheduledMessageRepository
import com.moez.QKSMS.repository.ScheduledMessageRepositoryImpl import com.moez.QKSMS.repository.ScheduledMessageRepositoryImpl
import com.moez.QKSMS.repository.SyncRepository import com.moez.QKSMS.repository.SyncRepository
import com.moez.QKSMS.repository.SyncRepositoryImpl import com.moez.QKSMS.repository.SyncRepositoryImpl
import com.moez.QKSMS.util.Preferences
import com.squareup.moshi.Moshi import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dagger.Module import dagger.Module
@@ -132,16 +129,7 @@ class AppModule(private var application: Application) {
fun provideAnalyticsManager(manager: AnalyticsManagerImpl): AnalyticsManager = manager fun provideAnalyticsManager(manager: AnalyticsManagerImpl): AnalyticsManager = manager
@Provides @Provides
fun externalBlockingManager( fun blockingClient(manager: BlockingManager): BlockingClient = manager
callControl: CallControlBlockingClient,
sia: ShouldIAnswerBlockingClient,
qksms: QkBlockingClient,
prefs: Preferences
): BlockingClient = when {
prefs.callControl.get() -> callControl
prefs.sia.get() -> sia
else -> qksms
}
@Provides @Provides
fun changelogManager(manager: ChangelogManagerImpl): ChangelogManager = manager fun changelogManager(manager: ChangelogManagerImpl): ChangelogManager = manager
+10 -5
View File
@@ -223,8 +223,15 @@
<string name="settings_blocking_title">Blocking</string> <string name="settings_blocking_title">Blocking</string>
<string name="settings_blocking_manager_title">Blocking Manager</string> <string name="settings_blocking_manager_title">Blocking Manager</string>
<string name="settings_blocking_qksms_summary">Built-in blocking functionality in QKSMS</string> <string name="settings_blocking_qksms_summary">Built-in blocking functionality in QKSMS</string>
<string name="settings_blocking_block_external">Would you also like to block this number in %s?</string> <plurals name="settings_blocking_block_external">
<string name="settings_blocking_unblock_external">Would you also like to block this number in %s?</string> <item quantity="one">Would you also like to block this number in %s?</item>
<item quantity="other">Would you also like to block these numbers in %s?</item>
</plurals>
<plurals name="settings_blocking_unblock_external">
<item quantity="one">Would you also like to unblock this number in %s?</item>
<item quantity="other">Would you also like to unblock these numbers in %s?</item>
</plurals>
<string name="settings_blocking_manager_android">Android Blocking Manager</string>
<!-- Do not translate --> <!-- Do not translate -->
<string name="settings_call_control_title">Call Control</string> <string name="settings_call_control_title">Call Control</string>
<string name="settings_call_control_summary">Automatically filter your calls and messages in one convenient place! Community IQ™ allows you to prevent unwanted messages from community known spammers</string> <string name="settings_call_control_summary">Automatically filter your calls and messages in one convenient place! Community IQ™ allows you to prevent unwanted messages from community known spammers</string>
@@ -267,8 +274,6 @@
<string name="blocked_title">Blocking</string> <string name="blocked_title">Blocking</string>
<string name="blocked_empty">Your blocked conversations will appear here</string> <string name="blocked_empty">Your blocked conversations will appear here</string>
<string name="blocked_unblock_dialog_title">Unblock</string>
<string name="blocked_unblock_dialog_message">Would you like to unblock this conversation?</string>
<string name="about_title">About</string> <string name="about_title">About</string>
<string name="about_version_title">Version</string> <string name="about_version_title">Version</string>
@@ -332,13 +337,13 @@
<item>Delete</item> <item>Delete</item>
</string-array> </string-array>
<string name="button_yes">Yes</string>
<string name="button_cancel">Cancel</string> <string name="button_cancel">Cancel</string>
<string name="button_delete">Delete</string> <string name="button_delete">Delete</string>
<string name="button_save">Save</string> <string name="button_save">Save</string>
<string name="button_stop">Stop</string> <string name="button_stop">Stop</string>
<string name="button_more">More</string> <string name="button_more">More</string>
<string name="button_set">Set</string> <string name="button_set">Set</string>
<string name="button_unblock">Unblock</string>
<string name="button_undo">Undo</string> <string name="button_undo">Undo</string>
<string name="toast_copied">Copied</string> <string name="toast_copied">Copied</string>