forked from upstream-mirrors/quik
Show messages in QkReplyActivity
This commit is contained in:
@@ -225,6 +225,15 @@ class MessageRepositoryImpl @Inject constructor(
|
|||||||
.findAll()
|
.findAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getUnreadMessages(threadId: Long): RealmResults<Message> {
|
||||||
|
return Realm.getDefaultInstance()
|
||||||
|
.where(Message::class.java)
|
||||||
|
.equalTo("read", false)
|
||||||
|
.equalTo("threadId", threadId)
|
||||||
|
.sort("date")
|
||||||
|
.findAll()
|
||||||
|
}
|
||||||
|
|
||||||
override fun markArchived(threadId: Long) {
|
override fun markArchived(threadId: Long) {
|
||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
val conversation = realm.where(Conversation::class.java)
|
val conversation = realm.where(Conversation::class.java)
|
||||||
|
|||||||
@@ -64,6 +64,12 @@ interface MessageRepository {
|
|||||||
*/
|
*/
|
||||||
fun getUnreadUnseenMessages(threadId: Long): RealmResults<Message>
|
fun getUnreadUnseenMessages(threadId: Long): RealmResults<Message>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the list of messages which should be shown in the quickreply popup
|
||||||
|
* for a given conversation
|
||||||
|
*/
|
||||||
|
fun getUnreadMessages(threadId: Long): RealmResults<Message>
|
||||||
|
|
||||||
fun markArchived(threadId: Long)
|
fun markArchived(threadId: Long)
|
||||||
|
|
||||||
fun markUnarchived(threadId: Long)
|
fun markUnarchived(threadId: Long)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.jakewharton.rxbinding2.view.RxView
|
import com.jakewharton.rxbinding2.view.RxView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
|
import common.base.QkViewHolder
|
||||||
import common.util.Colors
|
import common.util.Colors
|
||||||
import common.util.DateFormatter
|
import common.util.DateFormatter
|
||||||
import common.util.extensions.dpToPx
|
import common.util.extensions.dpToPx
|
||||||
@@ -44,7 +45,6 @@ import model.Contact
|
|||||||
import model.Conversation
|
import model.Conversation
|
||||||
import model.Message
|
import model.Message
|
||||||
import model.PhoneNumber
|
import model.PhoneNumber
|
||||||
import common.base.QkViewHolder
|
|
||||||
import util.extensions.isImage
|
import util.extensions.isImage
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -65,6 +65,8 @@ class MessagesAdapter @Inject constructor(
|
|||||||
|
|
||||||
var data: Pair<Conversation, RealmResults<Message>>? = null
|
var data: Pair<Conversation, RealmResults<Message>>? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
|
if (field === value) return
|
||||||
|
|
||||||
field = value
|
field = value
|
||||||
people.clear()
|
people.clear()
|
||||||
contactMap.clear()
|
contactMap.clear()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package feature.qkreply
|
package feature.qkreply
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
@@ -27,13 +28,17 @@ import com.uber.autodispose.android.lifecycle.scope
|
|||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import common.base.QkThemedActivity
|
import common.base.QkThemedActivity
|
||||||
import common.util.extensions.setBackgroundTint
|
import common.util.extensions.setBackgroundTint
|
||||||
|
import feature.compose.MessagesAdapter
|
||||||
import injection.appComponent
|
import injection.appComponent
|
||||||
import kotlinx.android.synthetic.main.qkreply_activity.*
|
import kotlinx.android.synthetic.main.qkreply_activity.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class QkReplyActivity : QkThemedActivity<QkReplyViewModel>(), QkReplyView {
|
class QkReplyActivity : QkThemedActivity<QkReplyViewModel>(), QkReplyView {
|
||||||
|
|
||||||
override val viewModelClass = QkReplyViewModel::class
|
override val viewModelClass = QkReplyViewModel::class
|
||||||
|
|
||||||
|
@Inject lateinit var adapter: MessagesAdapter
|
||||||
|
|
||||||
init {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
}
|
}
|
||||||
@@ -48,16 +53,22 @@ class QkReplyActivity : QkThemedActivity<QkReplyViewModel>(), QkReplyView {
|
|||||||
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||||
viewModel.bindView(this)
|
viewModel.bindView(this)
|
||||||
|
|
||||||
|
|
||||||
toolbar.clipToOutline = true
|
|
||||||
|
|
||||||
colors.composeBackground
|
colors.composeBackground
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { color -> background.setBackgroundTint(color) }
|
.subscribe { color -> background.setBackgroundTint(color) }
|
||||||
|
|
||||||
|
toolbar.clipToOutline = true
|
||||||
|
|
||||||
|
val layoutManager = LinearLayoutManager(this).apply { stackFromEnd = true }
|
||||||
|
|
||||||
|
messages.layoutManager = layoutManager
|
||||||
|
messages.adapter = adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(state: QkReplyState) {
|
override fun render(state: QkReplyState) {
|
||||||
title = state.title
|
title = state.title
|
||||||
|
|
||||||
|
adapter.data = state.data
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAppThemeResourcesObservable() = colors.appDialogThemeResources
|
override fun getAppThemeResourcesObservable() = colors.appDialogThemeResources
|
||||||
|
|||||||
@@ -19,9 +19,10 @@
|
|||||||
package feature.qkreply
|
package feature.qkreply
|
||||||
|
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
|
import model.Conversation
|
||||||
import model.Message
|
import model.Message
|
||||||
|
|
||||||
data class QkReplyState(
|
data class QkReplyState(
|
||||||
val title: String = "",
|
val title: String = "",
|
||||||
val data: RealmResults<Message>? = null
|
val data: Pair<Conversation, RealmResults<Message>>? = null
|
||||||
)
|
)
|
||||||
@@ -40,7 +40,11 @@ class QkReplyViewModel(intent: Intent) : QkViewModel<QkReplyView, QkReplyState>(
|
|||||||
.asObservable<Conversation>()
|
.asObservable<Conversation>()
|
||||||
.filter { it.isLoaded }
|
.filter { it.isLoaded }
|
||||||
.filter { it.isValid }
|
.filter { it.isValid }
|
||||||
.subscribe { conversation -> newState { it.copy(title = conversation.getTitle()) } }
|
.distinctUntilChanged()
|
||||||
|
.doOnNext { conversation -> newState { it.copy(title = conversation.getTitle()) } }
|
||||||
|
.map { conversation -> Pair(conversation, messageRepo.getUnreadMessages(conversation.id)) }
|
||||||
|
.doOnNext { data -> newState { it.copy(data = data) } }
|
||||||
|
.subscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,19 @@
|
|||||||
android:elevation="8dp"
|
android:elevation="8dp"
|
||||||
tools:context="feature.qkreply.QkReplyActivity">
|
tools:context="feature.qkreply.QkReplyActivity">
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/messages"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
app:layout_constrainedHeight="true"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/toolbar" />
|
||||||
|
|
||||||
<android.support.v7.widget.Toolbar
|
<android.support.v7.widget.Toolbar
|
||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
style="@style/Toolbar"
|
style="@style/Toolbar"
|
||||||
@@ -46,18 +59,6 @@
|
|||||||
|
|
||||||
</android.support.v7.widget.Toolbar>
|
</android.support.v7.widget.Toolbar>
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
|
||||||
android:id="@+id/messages"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="200dp"
|
|
||||||
android:paddingBottom="8dp"
|
|
||||||
android:paddingTop="8dp"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/toolbar"
|
|
||||||
tools:listitem="@layout/message_list_item_out" />
|
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="8dp"
|
android:layout_height="8dp"
|
||||||
|
|||||||
Reference in New Issue
Block a user