forked from upstream-mirrors/quik
When necessary, show dialog prompting user to go to external blocking manager
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user