Show conversation title in GalleryActivity

This commit is contained in:
Moez Bhatti
2018-02-13 20:45:45 -05:00
parent 943d6bab5f
commit 7255767a9e
4 changed files with 19 additions and 4 deletions
@@ -154,6 +154,13 @@ class MessageRepository @Inject constructor(
.findFirst() .findFirst()
} }
fun getMessageForPart(id: Long): Message? {
return Realm.getDefaultInstance()
.where(Message::class.java)
.equalTo("parts.id", id)
.findFirst()
}
fun getPart(id: Long): MmsPart? { fun getPart(id: Long): MmsPart? {
return Realm.getDefaultInstance() return Realm.getDefaultInstance()
.where(MmsPart::class.java) .where(MmsPart::class.java)
@@ -35,13 +35,14 @@ class GalleryActivity : QkActivity<GalleryViewModel>(), GalleryView {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.gallery_activity) setContentView(R.layout.gallery_activity)
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
title = ""
viewModel.bindView(this) viewModel.bindView(this)
} }
override fun render(state: GalleryState) { override fun render(state: GalleryState) {
toolbar.setVisible(state.navigationVisible) toolbar.setVisible(state.navigationVisible)
title = state.title
if (image.drawable == null) { if (image.drawable == null) {
GlideApp.with(this).load(state.imagePath).into(image) GlideApp.with(this).load(state.imagePath).into(image)
} }
@@ -20,5 +20,6 @@ package presentation.feature.gallery
data class GalleryState( data class GalleryState(
val navigationVisible: Boolean = true, val navigationVisible: Boolean = true,
val title: String = "",
val imagePath: String = "" val imagePath: String = ""
) )
@@ -37,13 +37,19 @@ class GalleryViewModel(intent: Intent) : QkViewModel<GalleryView, GalleryState>(
init { init {
appComponent.inject(this) appComponent.inject(this)
disposables += Flowable.just(intent) val partIdFlowable = Flowable.just(intent)
.map { it.getLongExtra("partId", 0L) } .map { it.getLongExtra("partId", 0L) }
.filter { partId -> partId != 0L } .filter { partId -> partId != 0L }
disposables += partIdFlowable
.mapNotNull { partId -> messageRepo.getPart(partId) } .mapNotNull { partId -> messageRepo.getPart(partId) }
.mapNotNull { part -> part.image } .mapNotNull { part -> part.image }
.doOnNext { path -> newState { it.copy(imagePath = path) } } .subscribe { path -> newState { it.copy(imagePath = path) } }
.subscribe()
disposables += partIdFlowable
.mapNotNull { partId -> messageRepo.getMessageForPart(partId) }
.mapNotNull { message -> messageRepo.getConversation(message.threadId) }
.subscribe { conversation -> newState { it.copy(title = conversation.getTitle()) } }
} }
override fun bindView(view: GalleryView) { override fun bindView(view: GalleryView) {