mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
When necessary, show dialog prompting user to go to external blocking manager
This commit is contained in:
@@ -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 block(address: String): Completable = Completable.fromCallable {
|
||||
CallControl.report(context, CallControl.Report(address))
|
||||
override fun block(addresses: List<String>): Completable = Completable.fromCallable {
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.moez.QKSMS.blocking
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.provider.BlockedNumberContract
|
||||
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 block(address: String): Completable = Completable.fromCallable {
|
||||
override fun block(addresses: List<String>): Completable = Completable.fromCallable {
|
||||
when {
|
||||
Build.VERSION.SDK_INT >= 24 -> {
|
||||
val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
|
||||
val intent = telecomManager.createManageBlockedNumbersIntent()
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ class QkBlockingClient @Inject constructor(private val context: Context) : Block
|
||||
.max("id")?.toLong() ?: -1
|
||||
|
||||
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 unblock(address: String): Completable = Completable.fromCallable {
|
||||
override fun unblock(addresses: List<String>): Completable = Completable.fromCallable {
|
||||
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 ->
|
||||
val ids = realm
|
||||
.where(BlockedNumber::class.java)
|
||||
.findAll()
|
||||
.filter { number -> PhoneNumberUtils.compare(number.address, address) }
|
||||
.filter { number ->
|
||||
addresses.any { address -> PhoneNumberUtils.compare(number.address, address) }
|
||||
}
|
||||
.map { number -> number.id }
|
||||
.toLongArray()
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@ class ShouldIAnswerBlockingClient @Inject constructor(
|
||||
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() {
|
||||
val pm = context.packageManager
|
||||
|
||||
@@ -141,6 +141,13 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.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? {
|
||||
return getThreadId(listOf(recipient))
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ interface BlockingClient {
|
||||
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
|
||||
@@ -46,8 +46,8 @@ interface BlockingClient {
|
||||
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?
|
||||
|
||||
/**
|
||||
* Returns all conversations with an id in [threadIds]
|
||||
*/
|
||||
fun getConversations(vararg threadIds: Long): RealmResults<Conversation>
|
||||
|
||||
fun getThreadId(recipient: 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_READ = 4
|
||||
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
|
||||
@@ -76,6 +80,7 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
|
||||
val black = rxPrefs.getBoolean("black", false)
|
||||
val systemFont = rxPrefs.getBoolean("systemFont", false)
|
||||
val textSize = rxPrefs.getInteger("textSize", TEXT_SIZE_NORMAL)
|
||||
val blockingManager = rxPrefs.getInteger("blockingManager", BLOCKING_MANAGER_QKSMS)
|
||||
val callControl = rxPrefs.getBoolean("callControl", false)
|
||||
val sia = rxPrefs.getBoolean("sia", false)
|
||||
val drop = rxPrefs.getBoolean("drop", false)
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.blocked
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
@@ -26,8 +25,6 @@ import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkThemedActivity
|
||||
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.settings_switch_widget.view.*
|
||||
import javax.inject.Inject
|
||||
@@ -40,8 +37,7 @@ class BlockedActivity : QkThemedActivity(), BlockedView {
|
||||
override val ccClickedIntent by lazy { callControl.clicks() }
|
||||
override val siaClickedIntent by lazy { shouldIAnswer.clicks() }
|
||||
override val dropClickedIntent by lazy { drop.clicks() }
|
||||
override val unblockIntent by lazy { blockedAdapter.unblock }
|
||||
override val confirmUnblockIntent: Subject<Long> = PublishSubject.create()
|
||||
override val conversationClicks by lazy { blockedAdapter.clicks }
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[BlockedViewModel::class.java] }
|
||||
|
||||
@@ -65,13 +61,4 @@ class BlockedActivity : QkThemedActivity(), BlockedView {
|
||||
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>() {
|
||||
|
||||
val unblock: PublishSubject<Long> = PublishSubject.create()
|
||||
val clicks: PublishSubject<Long> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false)
|
||||
return QkViewHolder(view).apply {
|
||||
view.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
|
||||
|
||||
view.avatars.contacts = conversation.recipients
|
||||
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||
view.title.text = conversation.getTitle()
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,6 @@ interface BlockedView : QkView<BlockedState> {
|
||||
val ccClickedIntent: Observable<*>
|
||||
val siaClickedIntent: Observable<*>
|
||||
val dropClickedIntent: Observable<*>
|
||||
val unblockIntent: Observable<Long>
|
||||
val confirmUnblockIntent: Observable<Long>
|
||||
val conversationClicks: 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.base.QkViewModel
|
||||
import com.moez.QKSMS.common.util.extensions.isInstalled
|
||||
import com.moez.QKSMS.interactor.MarkUnblocked
|
||||
import com.moez.QKSMS.manager.AnalyticsManager
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
@@ -35,7 +34,6 @@ class BlockedViewModel @Inject constructor(
|
||||
private val context: Context,
|
||||
private val analytics: AnalyticsManager,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val markUnblocked: MarkUnblocked,
|
||||
private val navigator: Navigator,
|
||||
private val prefs: Preferences
|
||||
) : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
|
||||
@@ -93,15 +91,9 @@ class BlockedViewModel @Inject constructor(
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { prefs.drop.set(!prefs.drop.get()) }
|
||||
|
||||
// Show confirm unblock conversation dialog
|
||||
view.unblockIntent
|
||||
view.conversationClicks
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> view.showUnblockDialog(threadId) }
|
||||
|
||||
// Unblock conversation
|
||||
view.confirmUnblockIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { threadId -> markUnblocked.execute(listOf(threadId)) }
|
||||
.subscribe { threadId -> navigator.showConversation(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()
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -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.setVisible
|
||||
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.themepicker.ThemePickerController
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
@@ -46,6 +47,7 @@ class ConversationInfoController(
|
||||
) : QkController<ConversationInfoView, ConversationInfoState, ConversationInfoPresenter>(), ConversationInfoView {
|
||||
|
||||
@Inject override lateinit var presenter: ConversationInfoPresenter
|
||||
@Inject lateinit var blockingDialog: BlockingDialog
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var recipientAdapter: ConversationRecipientAdapter
|
||||
@Inject lateinit var mediaAdapter: ConversationMediaAdapter
|
||||
@@ -142,6 +144,10 @@ class ConversationInfoController(
|
||||
.popChangeHandler(QkChangeHandler()))
|
||||
}
|
||||
|
||||
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
|
||||
blockingDialog.show(activity!!, conversations, block)
|
||||
}
|
||||
|
||||
override fun showDeleteDialog() {
|
||||
AlertDialog.Builder(activity!!)
|
||||
.setTitle(R.string.dialog_delete_title)
|
||||
|
||||
+1
-12
@@ -23,9 +23,7 @@ import com.moez.QKSMS.common.base.QkPresenter
|
||||
import com.moez.QKSMS.extensions.asObservable
|
||||
import com.moez.QKSMS.interactor.DeleteConversations
|
||||
import com.moez.QKSMS.interactor.MarkArchived
|
||||
import com.moez.QKSMS.interactor.MarkBlocked
|
||||
import com.moez.QKSMS.interactor.MarkUnarchived
|
||||
import com.moez.QKSMS.interactor.MarkUnblocked
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
@@ -46,8 +44,6 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markArchived: MarkArchived,
|
||||
private val markUnarchived: MarkUnarchived,
|
||||
private val markBlocked: MarkBlocked,
|
||||
private val markUnblocked: MarkUnblocked,
|
||||
private val navigator: Navigator,
|
||||
private val permissionManager: PermissionManager
|
||||
) : QkPresenter<ConversationInfoView, ConversationInfoState>(
|
||||
@@ -71,8 +67,6 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
|
||||
disposables += markArchived
|
||||
disposables += markUnarchived
|
||||
disposables += markBlocked
|
||||
disposables += markUnblocked
|
||||
disposables += deleteConversations
|
||||
|
||||
// Update the recipients whenever they change
|
||||
@@ -145,12 +139,7 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
view.blockClicks()
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation ->
|
||||
when (conversation.blocked) {
|
||||
true -> markUnblocked.execute(listOf(conversation.id))
|
||||
false -> markBlocked.execute(listOf(conversation.id))
|
||||
}
|
||||
}
|
||||
.subscribe { conversation -> view.showBlockingDialog(listOf(conversation.id), !conversation.blocked) }
|
||||
|
||||
// Show the delete confirmation dialog
|
||||
view.deleteClicks()
|
||||
|
||||
+1
@@ -34,6 +34,7 @@ interface ConversationInfoView : QkViewContract<ConversationInfoState> {
|
||||
|
||||
fun showNameDialog(name: String)
|
||||
fun showThemePicker(threadId: Long)
|
||||
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
|
||||
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.setTint
|
||||
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.conversations.ConversationItemTouchCallback
|
||||
import com.moez.QKSMS.feature.conversations.ConversationsAdapter
|
||||
@@ -71,6 +72,7 @@ import javax.inject.Inject
|
||||
|
||||
class MainActivity : QkThemedActivity(), MainView {
|
||||
|
||||
@Inject lateinit var blockingDialog: BlockingDialog
|
||||
@Inject lateinit var disposables: CompositeDisposable
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var conversationsAdapter: ConversationsAdapter
|
||||
@@ -156,7 +158,8 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
.autoDisposable(scope())
|
||||
.subscribe { theme ->
|
||||
// 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)
|
||||
.let { textSecondary -> ColorStateList(states, intArrayOf(theme.theme, textSecondary)) }
|
||||
.let { tintList ->
|
||||
@@ -268,8 +271,10 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
inbox.isActivated = state.page is Inbox
|
||||
archived.isActivated = state.page is Archived
|
||||
|
||||
if (drawerLayout.isDrawerOpen(GravityCompat.START) && !state.drawerOpen) drawerLayout.closeDrawer(GravityCompat.START)
|
||||
else if (!drawerLayout.isDrawerVisible(GravityCompat.START) && state.drawerOpen) drawerLayout.openDrawer(GravityCompat.START)
|
||||
if (drawerLayout.isDrawerOpen(GravityCompat.START) && !state.drawerOpen) drawerLayout.closeDrawer(
|
||||
GravityCompat.START)
|
||||
else if (!drawerLayout.isDrawerVisible(GravityCompat.START) && state.drawerOpen) drawerLayout.openDrawer(
|
||||
GravityCompat.START)
|
||||
|
||||
when (state.syncing) {
|
||||
is SyncRepository.SyncProgress.Idle -> {
|
||||
@@ -341,6 +346,10 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
conversationsAdapter.clearSelection()
|
||||
}
|
||||
|
||||
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
|
||||
blockingDialog.show(this, conversations, block)
|
||||
}
|
||||
|
||||
override fun showDeleteDialog(conversations: List<Long>) {
|
||||
val count = conversations.size
|
||||
AlertDialog.Builder(this)
|
||||
|
||||
@@ -46,6 +46,7 @@ interface MainView : QkView<MainState> {
|
||||
fun requestPermissions()
|
||||
fun clearSearch()
|
||||
fun clearSelection()
|
||||
fun showBlockingDialog(conversations: List<Long>, block: Boolean)
|
||||
fun showDeleteDialog(conversations: List<Long>)
|
||||
fun showChangelog(changelog: ChangelogManager.Changelog)
|
||||
fun showArchivedSnackbar()
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.moez.QKSMS.extensions.removeAccents
|
||||
import com.moez.QKSMS.interactor.DeleteConversations
|
||||
import com.moez.QKSMS.interactor.MarkAllSeen
|
||||
import com.moez.QKSMS.interactor.MarkArchived
|
||||
import com.moez.QKSMS.interactor.MarkBlocked
|
||||
import com.moez.QKSMS.interactor.MarkPinned
|
||||
import com.moez.QKSMS.interactor.MarkRead
|
||||
import com.moez.QKSMS.interactor.MarkUnarchived
|
||||
@@ -64,7 +63,6 @@ class MainViewModel @Inject constructor(
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markArchived: MarkArchived,
|
||||
private val markBlocked: MarkBlocked,
|
||||
private val markPinned: MarkPinned,
|
||||
private val markRead: MarkRead,
|
||||
private val markUnarchived: MarkUnarchived,
|
||||
@@ -319,7 +317,7 @@ class MainViewModel @Inject constructor(
|
||||
view.optionsItemIntent
|
||||
.filter { itemId -> itemId == R.id.block }
|
||||
.withLatestFrom(view.conversationsSelectedIntent) { _, conversations ->
|
||||
markBlocked.execute(conversations)
|
||||
view.showBlockingDialog(conversations, true)
|
||||
view.clearSelection()
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -26,9 +26,7 @@ import android.preference.PreferenceManager
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import com.moez.QKSMS.blocking.BlockingClient
|
||||
import com.moez.QKSMS.blocking.CallControlBlockingClient
|
||||
import com.moez.QKSMS.blocking.QkBlockingClient
|
||||
import com.moez.QKSMS.blocking.ShouldIAnswerBlockingClient
|
||||
import com.moez.QKSMS.blocking.BlockingManager
|
||||
import com.moez.QKSMS.common.ViewModelFactory
|
||||
import com.moez.QKSMS.common.util.NotificationManagerImpl
|
||||
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.SyncRepository
|
||||
import com.moez.QKSMS.repository.SyncRepositoryImpl
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import dagger.Module
|
||||
@@ -132,16 +129,7 @@ class AppModule(private var application: Application) {
|
||||
fun provideAnalyticsManager(manager: AnalyticsManagerImpl): AnalyticsManager = manager
|
||||
|
||||
@Provides
|
||||
fun externalBlockingManager(
|
||||
callControl: CallControlBlockingClient,
|
||||
sia: ShouldIAnswerBlockingClient,
|
||||
qksms: QkBlockingClient,
|
||||
prefs: Preferences
|
||||
): BlockingClient = when {
|
||||
prefs.callControl.get() -> callControl
|
||||
prefs.sia.get() -> sia
|
||||
else -> qksms
|
||||
}
|
||||
fun blockingClient(manager: BlockingManager): BlockingClient = manager
|
||||
|
||||
@Provides
|
||||
fun changelogManager(manager: ChangelogManagerImpl): ChangelogManager = manager
|
||||
|
||||
@@ -223,8 +223,15 @@
|
||||
<string name="settings_blocking_title">Blocking</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_block_external">Would you also like to block this number in %s?</string>
|
||||
<string name="settings_blocking_unblock_external">Would you also like to block this number in %s?</string>
|
||||
<plurals name="settings_blocking_block_external">
|
||||
<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 -->
|
||||
<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>
|
||||
@@ -267,8 +274,6 @@
|
||||
|
||||
<string name="blocked_title">Blocking</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_version_title">Version</string>
|
||||
@@ -332,13 +337,13 @@
|
||||
<item>Delete</item>
|
||||
</string-array>
|
||||
|
||||
<string name="button_yes">Yes</string>
|
||||
<string name="button_cancel">Cancel</string>
|
||||
<string name="button_delete">Delete</string>
|
||||
<string name="button_save">Save</string>
|
||||
<string name="button_stop">Stop</string>
|
||||
<string name="button_more">More</string>
|
||||
<string name="button_set">Set</string>
|
||||
<string name="button_unblock">Unblock</string>
|
||||
<string name="button_undo">Undo</string>
|
||||
|
||||
<string name="toast_copied">Copied</string>
|
||||
|
||||
Reference in New Issue
Block a user