forked from upstream-mirrors/quik
Show media history of conversation in info activity
This commit is contained in:
+7
-2
@@ -20,7 +20,6 @@ package presentation.feature.conversationinfo
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.widget.LinearLayoutManager
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
@@ -40,6 +39,8 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
|
||||
override val confirmDeleteIntent: PublishSubject<Unit> = PublishSubject.create()
|
||||
|
||||
@Inject lateinit var recipientAdapter: ConversationRecipientAdapter
|
||||
@Inject lateinit var mediaAdapter: ConversationMediaAdapter
|
||||
@Inject lateinit var itemDecoration: GridSpacingItemDecoration
|
||||
|
||||
init {
|
||||
appComponent.inject(this)
|
||||
@@ -56,8 +57,10 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
|
||||
.autoDisposable(scope())
|
||||
.subscribe { color -> window.decorView.setBackgroundColor(color) }
|
||||
|
||||
recipients.layoutManager = LinearLayoutManager(this)
|
||||
recipients.adapter = recipientAdapter
|
||||
|
||||
media.adapter = mediaAdapter
|
||||
media.addItemDecoration(itemDecoration)
|
||||
}
|
||||
|
||||
override fun render(state: ConversationInfoState) {
|
||||
@@ -72,6 +75,8 @@ class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(),
|
||||
true -> R.string.info_unarchive
|
||||
false -> R.string.info_archive
|
||||
})
|
||||
|
||||
mediaAdapter.data = state.media
|
||||
}
|
||||
|
||||
override fun showDeleteDialog() {
|
||||
|
||||
@@ -18,10 +18,12 @@
|
||||
*/
|
||||
package presentation.feature.conversationinfo
|
||||
|
||||
import data.model.MmsPart
|
||||
import data.model.Recipient
|
||||
|
||||
data class ConversationInfoState(
|
||||
val recipients: List<Recipient> = listOf(),
|
||||
val archived: Boolean = false,
|
||||
val media: List<MmsPart> = ArrayList(),
|
||||
val hasError: Boolean = false
|
||||
)
|
||||
@@ -80,6 +80,12 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
.map { conversation -> conversation.archived }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { archived -> newState { it.copy(archived = archived) } }
|
||||
|
||||
// Load the attachments from the conversation
|
||||
disposables += messageRepo.getPartsForConversation(threadId)
|
||||
.map { parts -> parts.filter { part -> part.isImage() } }
|
||||
.map { parts -> parts.reversed() }
|
||||
.subscribe { media -> newState { it.copy(media = media) } }
|
||||
}
|
||||
|
||||
override fun bindView(view: ConversationInfoView) {
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.conversationinfo
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import common.util.Colors
|
||||
import common.util.GlideApp
|
||||
import data.model.MmsPart
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import kotlinx.android.synthetic.main.conversation_media_list_item.view.*
|
||||
import presentation.common.Navigator
|
||||
import presentation.common.base.QkAdapter
|
||||
import presentation.common.base.QkViewHolder
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationMediaAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors,
|
||||
private val navigator: Navigator
|
||||
) : QkAdapter<MmsPart>() {
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): QkViewHolder {
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.conversation_media_list_item, parent, false)
|
||||
|
||||
disposables += colors.separator.subscribe { color -> view.setBackgroundColor(color) }
|
||||
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val part = getItem(position)
|
||||
val view = holder.itemView
|
||||
|
||||
GlideApp.with(context)
|
||||
.load(part.image)
|
||||
.fitCenter()
|
||||
.into(view.thumbnail)
|
||||
|
||||
view.thumbnail.setOnClickListener {
|
||||
navigator.showImage(part.id)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView?) {
|
||||
disposables.clear()
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.conversationinfo
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import common.util.extensions.dpToPx
|
||||
import javax.inject.Inject
|
||||
|
||||
class GridSpacingItemDecoration @Inject constructor(context: Context) : RecyclerView.ItemDecoration() {
|
||||
|
||||
private val spanCount = 3
|
||||
private val spacing = 2.dpToPx(context)
|
||||
|
||||
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
|
||||
val position = parent.getChildAdapterPosition(view)
|
||||
val column = position % spanCount
|
||||
|
||||
outRect.left = column * spacing / spanCount
|
||||
outRect.right = spacing - (column + 1) * spacing / spanCount
|
||||
|
||||
if (position >= spanCount) {
|
||||
outRect.top = spacing
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user