forked from upstream-mirrors/quik
Display blocked conversations in blocked tab
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 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>() {
|
||||
|
||||
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.avatars.contacts = conversation.recipients.map { recipient ->
|
||||
recipient.contact ?: Contact().apply { numbers.add(PhoneNumber().apply { address = recipient.address }) }
|
||||
}
|
||||
|
||||
view.title.text = conversation.getTitle()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -51,6 +51,7 @@ 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
|
||||
@@ -58,6 +59,7 @@ 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
|
||||
@@ -111,7 +113,6 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
drawer.clicks().subscribe()
|
||||
|
||||
scheduled.isEnabled = false
|
||||
blocked.isEnabled = false
|
||||
|
||||
colors.background
|
||||
.doOnNext { color -> window.decorView.setBackgroundColor(color) }
|
||||
@@ -197,8 +198,8 @@ 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)
|
||||
@@ -207,8 +208,8 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
|
||||
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)
|
||||
@@ -226,7 +227,8 @@ class MainActivity : QkThemedActivity<MainViewModel>(), MainView {
|
||||
|
||||
is Blocked -> {
|
||||
if (!blocked.isSelected) toolbarSearch.setText(R.string.title_blocked)
|
||||
recyclerView.adapter = null
|
||||
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)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package presentation.feature.main
|
||||
|
||||
import data.model.Conversation
|
||||
import data.model.InboxItem
|
||||
import data.model.MenuItem
|
||||
import io.reactivex.Flowable
|
||||
@@ -47,5 +48,5 @@ data class Scheduled(
|
||||
val empty: Boolean = false) : MainPage()
|
||||
|
||||
data class Blocked(
|
||||
val data: Any? = null,
|
||||
val data: Flowable<List<Conversation>>? = null,
|
||||
val empty: Boolean = false) : MainPage()
|
||||
@@ -74,6 +74,16 @@ 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) }
|
||||
@@ -158,7 +168,7 @@ 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()) }
|
||||
DrawerItem.BLOCKED -> newState { it.copy(page = Blocked(blockedConversations)) }
|
||||
else -> {
|
||||
} // Do nothing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user