Move blocked conversations to separate activity

This commit is contained in:
Moez Bhatti
2018-03-05 19:32:33 -05:00
parent 59a0b39362
commit c3fc34a8cc
18 changed files with 290 additions and 83 deletions
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.feature.blocked
import android.app.AlertDialog
import android.os.Bundle
import com.moez.QKSMS.R
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import common.di.appComponent
import common.util.extensions.setVisible
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.blocked_activity.*
import presentation.common.base.QkThemedActivity
import javax.inject.Inject
class BlockedActivity : QkThemedActivity<BlockedViewModel>(), BlockedView {
@Inject lateinit var blockedAdapter: BlockedAdapter
override val viewModelClass = BlockedViewModel::class
override val unblockIntent by lazy { blockedAdapter.unblock }
override val confirmUnblockIntent: Subject<Unit> = PublishSubject.create()
init {
appComponent.inject(this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.blocked_activity)
setTitle(R.string.blocked_title)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
viewModel.bindView(this)
colors.background
.autoDisposable(scope())
.subscribe { color -> window.decorView.setBackgroundColor(color) }
conversations.adapter = blockedAdapter
}
override fun render(state: BlockedState) {
blockedAdapter.flowable = state.data
empty.setVisible(state.empty)
}
override fun showUnblockDialog() {
AlertDialog.Builder(this)
.setTitle(R.string.blocked_unblock_dialog_title)
.setMessage(R.string.blocked_unblock_dialog_message)
.setPositiveButton(R.string.button_unblock, { _, _ -> confirmUnblockIntent.onNext(Unit) })
.setNegativeButton(R.string.button_cancel, null)
.show()
}
}
@@ -33,7 +33,7 @@ import javax.inject.Inject
class BlockedAdapter @Inject constructor(private val context: Context) : FlowableAdapter<Conversation>() {
val unblock = PublishSubject.create<Long>()
val unblock: PublishSubject<Long> = PublishSubject.create()
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): QkViewHolder {
return QkViewHolder(LayoutInflater.from(context).inflate(R.layout.blocked_list_item, parent, false))
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.feature.blocked
import data.model.Conversation
import io.reactivex.Flowable
data class BlockedState(
val data: Flowable<List<Conversation>>? = null,
val empty: Boolean = false
)
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.feature.blocked
import io.reactivex.Observable
import presentation.common.base.QkView
interface BlockedView : QkView<BlockedState> {
val unblockIntent: Observable<Long>
val confirmUnblockIntent: Observable<Unit>
fun showUnblockDialog()
}
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package presentation.feature.blocked
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import common.di.appComponent
import data.repository.MessageRepository
import interactor.MarkUnblocked
import io.reactivex.rxkotlin.withLatestFrom
import presentation.common.base.QkViewModel
import javax.inject.Inject
class BlockedViewModel : QkViewModel<BlockedView, BlockedState>(BlockedState()) {
@Inject lateinit var markUnblocked: MarkUnblocked
@Inject lateinit var messageRepo: MessageRepository
init {
appComponent.inject(this)
val conversations = messageRepo.getBlockedConversations()
.doOnNext { conversations -> newState { it.copy(empty = conversations.isEmpty()) } }
newState { it.copy(data = conversations) }
}
override fun bindView(view: BlockedView) {
super.bindView(view)
// Show confirm unblock conversation dialog
view.unblockIntent
.autoDisposable(view.scope())
.subscribe { view.showUnblockDialog() }
// Unblock conversation
view.confirmUnblockIntent
.withLatestFrom(view.unblockIntent, { _, threadId -> threadId })
.autoDisposable(view.scope())
.subscribe { threadId -> markUnblocked.execute(threadId) }
}
}
@@ -51,7 +51,6 @@ import kotlinx.android.synthetic.main.toolbar_search.*
import presentation.common.MenuItemAdapter
import presentation.common.Navigator
import presentation.common.base.QkThemedActivity
import presentation.feature.blocked.BlockedAdapter
import presentation.feature.conversations.ConversationItemTouchCallback
import presentation.feature.conversations.ConversationsAdapter
import javax.inject.Inject
@@ -59,7 +58,6 @@ import javax.inject.Inject
class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
@Inject lateinit var navigator: Navigator
@Inject lateinit var blockedAdapter: BlockedAdapter
@Inject lateinit var conversationsAdapter: ConversationsAdapter
@Inject lateinit var itemTouchCallback: ConversationItemTouchCallback
@Inject lateinit var menuItemAdapter: MenuItemAdapter
@@ -74,7 +72,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
inbox.clicks().map { DrawerItem.INBOX },
archived.clicks().map { DrawerItem.ARCHIVED },
scheduled.clicks().map { DrawerItem.SCHEDULED },
blocked.clicks().map { DrawerItem.BLOCKED },
settings.clicks().map { DrawerItem.SETTINGS },
plus.clicks().map { DrawerItem.PLUS },
help.clicks().map { DrawerItem.HELP }))
@@ -83,8 +80,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
override val conversationLongClickIntent by lazy { conversationsAdapter.longClicks }
override val conversationMenuItemIntent by lazy { menuItemAdapter.menuItemClicks }
override val confirmDeleteIntent: Subject<Unit> = PublishSubject.create()
override val unblockIntent by lazy { blockedAdapter.unblock }
override val confirmUnblockIntent: Subject<Unit> = PublishSubject.create()
override val swipeConversationIntent by lazy { itemTouchCallback.swipes }
override val undoSwipeConversationIntent: Subject<Unit> = PublishSubject.create()
@@ -154,7 +149,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
.doOnNext { tintList -> inboxIcon.imageTintList = tintList }
.doOnNext { tintList -> archivedIcon.imageTintList = tintList }
.doOnNext { tintList -> scheduledIcon.imageTintList = tintList }
.doOnNext { tintList -> blockedIcon.imageTintList = tintList }
.doOnNext { tintList -> settingsIcon.imageTintList = tintList }
.doOnNext { tintList -> plusIcon.imageTintList = tintList }
.doOnNext { tintList -> helpIcon.imageTintList = tintList }
@@ -166,7 +160,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
.doOnNext { color -> inbox.background = rowBackground(color) }
.doOnNext { color -> archived.background = rowBackground(color) }
.doOnNext { color -> scheduled.background = rowBackground(color) }
.doOnNext { color -> blocked.background = rowBackground(color) }
.autoDisposable(scope())
.subscribe()
@@ -229,17 +222,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
empty.setVisible(state.page.empty && !state.syncing)
compose.setVisible(false)
}
is Blocked -> {
if (!blocked.isSelected) toolbarSearch.setText(R.string.title_blocked)
if (recyclerView.adapter != blockedAdapter) recyclerView.adapter = blockedAdapter
blockedAdapter.flowable = state.page.data
itemTouchHelper.attachToRecyclerView(null)
menuItemAdapter.data = ArrayList()
empty.setText(R.string.blocked_empty_text)
empty.setVisible(state.page.empty && !state.syncing)
compose.setVisible(false)
}
}
when (state.page is Inbox && state.page.showArchivedSnackbar) {
@@ -253,8 +235,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
archivedIcon.isSelected = state.page is Archived
scheduled.isSelected = state.page is Scheduled
scheduledIcon.isSelected = state.page is Scheduled
blocked.isSelected = state.page is Blocked
blockedIcon.isSelected = state.page is Blocked
if (drawerLayout.isDrawerOpen(Gravity.START) && !state.drawerOpen) drawerLayout.closeDrawer(Gravity.START)
else if (!drawerLayout.isDrawerVisible(Gravity.START) && state.drawerOpen) drawerLayout.openDrawer(Gravity.START)
@@ -287,15 +267,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
.show()
}
override fun showUnblockDialog() {
AlertDialog.Builder(this)
.setTitle(R.string.dialog_unblock_title)
.setMessage(R.string.dialog_unblock_message)
.setPositiveButton(R.string.button_unblock, { _, _ -> confirmUnblockIntent.onNext(Unit) })
.setNegativeButton(R.string.button_cancel, null)
.show()
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.main, menu)
return super.onCreateOptionsMenu(menu)
@@ -45,8 +45,4 @@ data class Archived(
data class Scheduled(
val data: Any? = null,
val empty: Boolean = false) : MainPage()
data class Blocked(
val data: Flowable<List<Conversation>>? = null,
val empty: Boolean = false) : MainPage()
@@ -32,14 +32,11 @@ interface MainView : QkView<MainState> {
val conversationLongClickIntent: Observable<Long>
val conversationMenuItemIntent: Observable<Int>
val confirmDeleteIntent: Observable<Unit>
val unblockIntent: Observable<Long>
val confirmUnblockIntent: Observable<Unit>
val swipeConversationIntent: Observable<Int>
val undoSwipeConversationIntent: Observable<Unit>
fun clearSearch()
fun showDeleteDialog()
fun showUnblockDialog()
}
@@ -52,7 +52,6 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
@Inject lateinit var deleteConversation: DeleteConversation
@Inject lateinit var markArchived: MarkArchived
@Inject lateinit var markUnarchived: MarkUnarchived
@Inject lateinit var markUnblocked: MarkUnblocked
@Inject lateinit var partialSync: PartialSync
private val conversations by lazy {
@@ -75,16 +74,6 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
})
}
private val blockedConversations by lazy {
messageRepo.getBlockedConversations()
.withLatestFrom(state.toFlowable(), { conversations, state ->
(state.page as? Blocked)?.let { page ->
newState { it.copy(page = page.copy(empty = conversations.isEmpty())) }
}
conversations
})
}
private val menuArchive by lazy { MenuItem(context.getString(R.string.menu_archive), 0) }
private val menuUnarchive by lazy { MenuItem(context.getString(R.string.menu_unarchive), 1) }
private val menuDelete by lazy { MenuItem(context.getString(R.string.menu_delete), 2) }
@@ -169,7 +158,6 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
DrawerItem.INBOX -> newState { it.copy(page = Inbox(data = conversations)) }
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(archivedConversations)) }
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
DrawerItem.BLOCKED -> newState { it.copy(page = Blocked(blockedConversations)) }
else -> {
} // Do nothing
}
@@ -259,17 +247,6 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
.withLatestFrom(swipedConversation, { _, threadId -> threadId })
.autoDisposable(view.scope())
.subscribe { threadId -> markUnarchived.execute(threadId) }
// Show confirm unblock conversation dialog
view.unblockIntent
.autoDisposable(view.scope())
.subscribe { view.showUnblockDialog() }
// Unblock conversation
view.confirmUnblockIntent
.withLatestFrom(view.unblockIntent, { _, threadId -> threadId })
.autoDisposable(view.scope())
.subscribe { threadId -> markUnblocked.execute(threadId)}
}
}
@@ -122,6 +122,8 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
R.id.notifications -> navigator.showNotificationSettings()
R.id.blocked -> navigator.showBlockedConversations()
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
R.id.unicode -> prefs.unicode.set(!prefs.unicode.get())