forked from upstream-mirrors/quik
Display blocked conversations in blocked tab
This commit is contained in:
@@ -88,11 +88,14 @@ class MessageRepository @Inject constructor(
|
||||
})
|
||||
}
|
||||
|
||||
fun getBlockedConversations(): RealmResults<Conversation> {
|
||||
fun getBlockedConversations(): Flowable<List<Conversation>> {
|
||||
return Realm.getDefaultInstance()
|
||||
.where(Conversation::class.java)
|
||||
.equalTo("blocked", true)
|
||||
.findAll()
|
||||
.findAllAsync()
|
||||
.asFlowable()
|
||||
.filter { it.isLoaded }
|
||||
.map { it.toList() }
|
||||
}
|
||||
|
||||
fun getConversationAsync(threadId: Long): Conversation {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/ripple"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp">
|
||||
|
||||
<presentation.common.widget.GroupAvatarView
|
||||
android:id="@+id/avatars"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:layout_constraintEnd_toStartOf="@id/title"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<presentation.common.widget.QkTextView
|
||||
android:id="@+id/title"
|
||||
style="@style/TextPrimary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toEndOf="@id/avatars"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Moez Bhatti" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
@@ -55,6 +55,21 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/blocked"
|
||||
style="@style/DrawerRow">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/blockedIcon"
|
||||
style="@style/DrawerIcon"
|
||||
android:src="@drawable/ic_block_black_24dp" />
|
||||
|
||||
<presentation.common.widget.QkTextView
|
||||
style="@style/DrawerText"
|
||||
android:text="@string/drawer_blocked" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/scheduled"
|
||||
style="@style/DrawerRow"
|
||||
@@ -71,22 +86,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/blocked"
|
||||
style="@style/DrawerRow"
|
||||
android:alpha="0.5">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/blockedIcon"
|
||||
style="@style/DrawerIcon"
|
||||
android:src="@drawable/ic_block_black_24dp" />
|
||||
|
||||
<presentation.common.widget.QkTextView
|
||||
style="@style/DrawerText"
|
||||
android:text="@string/drawer_blocked" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<presentation.common.widget.Separator
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
|
||||
Reference in New Issue
Block a user