Merge branch 'blocking' into qksms3

This commit is contained in:
Moez Bhatti
2018-03-05 19:42:29 -05:00
48 changed files with 672 additions and 167 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()
}
}
@@ -0,0 +1,55 @@
/*
* 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.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.moez.QKSMS.R
import data.model.Contact
import data.model.Conversation
import data.model.PhoneNumber
import io.reactivex.subjects.PublishSubject
import kotlinx.android.synthetic.main.blocked_list_item.view.*
import presentation.common.base.FlowableAdapter
import presentation.common.base.QkViewHolder
import javax.inject.Inject
class BlockedAdapter @Inject constructor(private val context: Context) : FlowableAdapter<Conversation>() {
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))
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val conversation = getItem(position)
val view = holder.itemView
view.setOnClickListener { unblock.onNext(conversation.id) }
view.avatars.contacts = conversation.recipients.map { recipient ->
recipient.contact ?: Contact().apply { numbers.add(PhoneNumber().apply { address = recipient.address }) }
}
view.title.text = conversation.getTitle()
}
}
@@ -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) }
}
}
@@ -25,6 +25,7 @@ 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 kotlinx.android.synthetic.main.conversation_info_activity.*
import presentation.common.Navigator
@@ -36,6 +37,7 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
override val viewModelClass = ConversationInfoViewModel::class
override val notificationsIntent by lazy { notifications.clicks() }
override val archiveIntent by lazy { archive.clicks() }
override val blockIntent by lazy { block.clicks() }
override val deleteIntent by lazy { delete.clicks() }
override val confirmDeleteIntent: PublishSubject<Unit> = PublishSubject.create()
@@ -77,11 +79,19 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
recipientAdapter.data = state.recipients
notifications.setVisible(!state.blocked)
archive.setVisible(!state.blocked)
archive.title = getString(when (state.archived) {
true -> R.string.info_unarchive
false -> R.string.info_archive
})
block.title = getString(when (state.blocked) {
true -> R.string.info_unblock
false -> R.string.info_block
})
mediaAdapter.data = state.media
}
@@ -24,6 +24,7 @@ import data.model.Recipient
data class ConversationInfoState(
val recipients: List<Recipient> = listOf(),
val archived: Boolean = false,
val blocked: Boolean = false,
val media: List<MmsPart> = ArrayList(),
val hasError: Boolean = false
)
@@ -25,6 +25,7 @@ interface ConversationInfoView : QkView<ConversationInfoState> {
val notificationsIntent: Observable<Unit>
val archiveIntent: Observable<Unit>
val blockIntent: Observable<Unit>
val deleteIntent: Observable<Unit>
val confirmDeleteIntent: Observable<Unit>
@@ -20,17 +20,13 @@ package presentation.feature.conversationinfo
import android.content.Context
import android.content.Intent
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.asObservable
import common.util.extensions.makeToast
import data.model.Conversation
import data.repository.MessageRepository
import interactor.DeleteConversation
import interactor.MarkArchived
import interactor.MarkUnarchived
import interactor.*
import io.reactivex.Observable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
@@ -45,6 +41,8 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
@Inject lateinit var messageRepo: MessageRepository
@Inject lateinit var markArchived: MarkArchived
@Inject lateinit var markUnarchived: MarkUnarchived
@Inject lateinit var markBlocked: MarkBlocked
@Inject lateinit var markUnblocked: MarkUnblocked
@Inject lateinit var navigator: Navigator
@Inject lateinit var deleteConversation: DeleteConversation
@@ -67,6 +65,8 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
disposables += markArchived
disposables += markUnarchived
disposables += markBlocked
disposables += markUnblocked
disposables += deleteConversation
// Update the recipients whenever they change
@@ -81,6 +81,12 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
.distinctUntilChanged()
.subscribe { archived -> newState { it.copy(archived = archived) } }
// Update the view's blocked state whenever it changes
disposables += conversation
.map { conversation -> conversation.blocked }
.distinctUntilChanged()
.subscribe { blocked -> newState { it.copy(blocked = blocked) } }
// Load the attachments from the conversation
disposables += messageRepo.getPartsForConversation(threadId)
.map { parts -> parts.filter { part -> part.isImage() } }
@@ -103,8 +109,19 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
.autoDisposable(view.scope())
.subscribe { conversation ->
when (conversation.archived) {
true -> markUnarchived.execute(conversation.id, { context.makeToast(R.string.toast_unarchived) })
false -> markArchived.execute(conversation.id, { context.makeToast(R.string.toast_archived) })
true -> markUnarchived.execute(conversation.id)
false -> markArchived.execute(conversation.id)
}
}
// Toggle the blocked state of the conversation
view.blockIntent
.withLatestFrom(conversation, { _, conversation -> conversation })
.autoDisposable(view.scope())
.subscribe { conversation ->
when (conversation.blocked) {
true -> markUnblocked.execute(conversation.id)
false -> markBlocked.execute(conversation.id)
}
}
@@ -72,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 }))
@@ -111,7 +110,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
drawer.clicks().subscribe()
scheduled.isEnabled = false
blocked.isEnabled = false
colors.background
.doOnNext { color -> window.decorView.setBackgroundColor(color) }
@@ -151,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 }
@@ -163,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()
@@ -197,22 +193,24 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
when (state.page) {
is Inbox -> {
if (!inbox.isSelected) toolbarSearch.text = null
if (recyclerView.adapter != conversationsAdapter) recyclerView.adapter = conversationsAdapter
if (conversationsAdapter.flowable != state.page.data) conversationsAdapter.flowable = state.page.data
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
conversationsAdapter.flowable = state.page.data
itemTouchHelper.attachToRecyclerView(recyclerView)
menuItemAdapter.data = state.page.menu
empty.setText(R.string.inbox_empty_text)
empty.setVisible(state.page.empty && !state.syncing)
compose.setVisible(true)
}
is Archived -> {
if (!archived.isSelected) toolbarSearch.setText(R.string.title_archived)
if (recyclerView.adapter != conversationsAdapter) recyclerView.adapter = conversationsAdapter
if (conversationsAdapter.flowable != state.page.data) conversationsAdapter.flowable = state.page.data
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
conversationsAdapter.flowable = state.page.data
itemTouchHelper.attachToRecyclerView(null)
menuItemAdapter.data = state.page.menu
empty.setText(R.string.archived_empty_text)
empty.setVisible(state.page.empty && !state.syncing)
compose.setVisible(true)
}
is Scheduled -> {
@@ -222,15 +220,7 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
menuItemAdapter.data = ArrayList()
empty.setText(R.string.scheduled_empty_text)
empty.setVisible(state.page.empty && !state.syncing)
}
is Blocked -> {
if (!blocked.isSelected) toolbarSearch.setText(R.string.title_blocked)
recyclerView.adapter = null
itemTouchHelper.attachToRecyclerView(null)
menuItemAdapter.data = ArrayList()
empty.setText(R.string.blocked_empty_text)
empty.setVisible(state.page.empty && !state.syncing)
compose.setVisible(false)
}
}
@@ -245,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)
@@ -18,6 +18,7 @@
*/
package presentation.feature.main
import data.model.Conversation
import data.model.InboxItem
import data.model.MenuItem
import io.reactivex.Flowable
@@ -43,9 +44,5 @@ data class Archived(
val menu: List<MenuItem> = ArrayList()) : MainPage()
data class Scheduled(
val data: Any? = null,
val empty: Boolean = false) : MainPage()
data class Blocked(
val data: Any? = null,
val empty: Boolean = false) : MainPage()
@@ -19,7 +19,6 @@
package presentation.feature.main
import io.reactivex.Observable
import io.reactivex.subjects.Subject
import presentation.common.base.QkView
interface MainView : QkView<MainState> {
@@ -31,10 +30,10 @@ interface MainView : QkView<MainState> {
val drawerItemIntent: Observable<DrawerItem>
val conversationClickIntent: Observable<Long>
val conversationLongClickIntent: Observable<Long>
val conversationMenuItemIntent: Subject<Int>
val confirmDeleteIntent: Subject<Unit>
val conversationMenuItemIntent: Observable<Int>
val confirmDeleteIntent: Observable<Unit>
val swipeConversationIntent: Observable<Int>
val undoSwipeConversationIntent: Subject<Unit>
val undoSwipeConversationIntent: Observable<Unit>
fun clearSearch()
fun showDeleteDialog()
@@ -158,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()) }
else -> {
} // Do nothing
}
@@ -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())