This commit is contained in:
Benoit Marty 2020-11-10 15:23:22 +01:00
parent ca70ddb810
commit 510f8ae0f5
3 changed files with 33 additions and 42 deletions

View File

@ -20,21 +20,28 @@ import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import androidx.core.view.isVisible
import com.bumptech.glide.request.target.CustomViewTarget import com.bumptech.glide.request.target.CustomViewTarget
import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.request.transition.Transition
import im.vector.app.R
import im.vector.app.core.date.DateFormatKind
import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.lib.attachmentviewer.AttachmentInfo import im.vector.lib.attachmentviewer.AttachmentInfo
import im.vector.lib.attachmentviewer.AttachmentSourceProvider import im.vector.lib.attachmentviewer.AttachmentSourceProvider
import im.vector.lib.attachmentviewer.ImageLoaderTarget import im.vector.lib.attachmentviewer.ImageLoaderTarget
import im.vector.lib.attachmentviewer.VideoLoaderTarget import im.vector.lib.attachmentviewer.VideoLoaderTarget
import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.events.model.isVideoMessage
import org.matrix.android.sdk.api.session.file.FileService import org.matrix.android.sdk.api.session.file.FileService
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import java.io.File import java.io.File
abstract class BaseAttachmentProvider( abstract class BaseAttachmentProvider(
private val imageContentRenderer: ImageContentRenderer, private val imageContentRenderer: ImageContentRenderer,
protected val fileService: FileService, protected val fileService: FileService,
protected val stringProvider: StringProvider private val dateFormatter: VectorDateFormatter,
private val stringProvider: StringProvider
) : AttachmentSourceProvider { ) : AttachmentSourceProvider {
interface InteractionListener { interface InteractionListener {
@ -48,7 +55,7 @@ abstract class BaseAttachmentProvider(
protected var overlayView: AttachmentOverlayView? = null protected var overlayView: AttachmentOverlayView? = null
override fun overlayViewAtPosition(context: Context, position: Int): View? { final override fun overlayViewAtPosition(context: Context, position: Int): View? {
if (position == -1) return null if (position == -1) return null
if (overlayView == null) { if (overlayView == null) {
overlayView = AttachmentOverlayView(context) overlayView = AttachmentOverlayView(context)
@ -65,9 +72,24 @@ abstract class BaseAttachmentProvider(
interactionListener?.videoSeekTo(percent) interactionListener?.videoSeekTo(percent)
} }
} }
val timelineEvent = getTimelineEventAtPosition(position)
if (timelineEvent != null) {
val dateString = dateFormatter.format(timelineEvent.root.originServerTs, DateFormatKind.DEFAULT_DATE_AND_TIME)
overlayView?.updateWith(
counter = stringProvider.getString(R.string.attachment_viewer_item_x_of_y, position + 1, getItemCount()),
senderInfo = "${timelineEvent.senderInfo.displayName} $dateString"
)
overlayView?.videoControlsGroup?.isVisible = timelineEvent.root.isVideoMessage()
} else {
overlayView?.updateWith("", "")
}
return overlayView return overlayView
} }
abstract fun getTimelineEventAtPosition(position: Int): TimelineEvent?
override fun loadImage(target: ImageLoaderTarget, info: AttachmentInfo.Image) { override fun loadImage(target: ImageLoaderTarget, info: AttachmentInfo.Image) {
(info.data as? ImageContentRenderer.Data)?.let { (info.data as? ImageContentRenderer.Data)?.let {
imageContentRenderer.render(it, target.contextView(), object : CustomViewTarget<ImageView, Drawable>(target.contextView()) { imageContentRenderer.render(it, target.contextView(), object : CustomViewTarget<ImageView, Drawable>(target.contextView()) {

View File

@ -16,28 +16,23 @@
package im.vector.app.features.media package im.vector.app.features.media
import android.content.Context
import android.view.View
import androidx.core.view.isVisible
import im.vector.app.R
import im.vector.app.core.date.DateFormatKind
import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.lib.attachmentviewer.AttachmentInfo import im.vector.lib.attachmentviewer.AttachmentInfo
import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.events.model.isVideoMessage
import org.matrix.android.sdk.api.session.file.FileService import org.matrix.android.sdk.api.session.file.FileService
import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.Room
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import java.io.File import java.io.File
class DataAttachmentRoomProvider( class DataAttachmentRoomProvider(
private val attachments: List<AttachmentData>, private val attachments: List<AttachmentData>,
private val room: Room?, private val room: Room?,
imageContentRenderer: ImageContentRenderer, imageContentRenderer: ImageContentRenderer,
private val dateFormatter: VectorDateFormatter, dateFormatter: VectorDateFormatter,
fileService: FileService, fileService: FileService,
stringProvider: StringProvider stringProvider: StringProvider
) : BaseAttachmentProvider(imageContentRenderer, fileService, stringProvider) { ) : BaseAttachmentProvider(imageContentRenderer, fileService, dateFormatter, stringProvider) {
override fun getItemCount(): Int = attachments.size override fun getItemCount(): Int = attachments.size
@ -76,21 +71,9 @@ class DataAttachmentRoomProvider(
} }
} }
override fun overlayViewAtPosition(context: Context, position: Int): View? { override fun getTimelineEventAtPosition(position: Int): TimelineEvent? {
super.overlayViewAtPosition(context, position)
val item = attachments[position] val item = attachments[position]
val timeLineEvent = room?.getTimeLineEvent(item.eventId) return room?.getTimeLineEvent(item.eventId)
if (timeLineEvent != null) {
val dateString = dateFormatter.format(timeLineEvent.root.originServerTs, DateFormatKind.DEFAULT_DATE_AND_TIME)
overlayView?.updateWith(
counter = stringProvider.getString(R.string.attachment_viewer_item_x_of_y, position + 1, attachments.size),
senderInfo = "${timeLineEvent.senderInfo.displayName} $dateString"
)
overlayView?.videoControlsGroup?.isVisible = timeLineEvent.root.isVideoMessage()
} else {
overlayView?.updateWith("", "")
}
return overlayView
} }
override fun getFileForSharing(position: Int, callback: (File?) -> Unit) { override fun getFileForSharing(position: Int, callback: (File?) -> Unit) {

View File

@ -16,17 +16,11 @@
package im.vector.app.features.media package im.vector.app.features.media
import android.content.Context
import android.view.View
import androidx.core.view.isVisible
import im.vector.app.R
import im.vector.app.core.date.DateFormatKind
import im.vector.app.core.date.VectorDateFormatter import im.vector.app.core.date.VectorDateFormatter
import im.vector.app.core.resources.StringProvider import im.vector.app.core.resources.StringProvider
import im.vector.lib.attachmentviewer.AttachmentInfo import im.vector.lib.attachmentviewer.AttachmentInfo
import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.MatrixCallback
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.isVideoMessage
import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.file.FileService import org.matrix.android.sdk.api.session.file.FileService
import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.Room
@ -43,10 +37,10 @@ import javax.inject.Inject
class RoomEventsAttachmentProvider( class RoomEventsAttachmentProvider(
private val attachments: List<TimelineEvent>, private val attachments: List<TimelineEvent>,
imageContentRenderer: ImageContentRenderer, imageContentRenderer: ImageContentRenderer,
private val dateFormatter: VectorDateFormatter, dateFormatter: VectorDateFormatter,
fileService: FileService, fileService: FileService,
stringProvider: StringProvider stringProvider: StringProvider
) : BaseAttachmentProvider(imageContentRenderer, fileService, stringProvider) { ) : BaseAttachmentProvider(imageContentRenderer, fileService, dateFormatter, stringProvider) {
override fun getItemCount(): Int { override fun getItemCount(): Int {
return attachments.size return attachments.size
@ -127,16 +121,8 @@ class RoomEventsAttachmentProvider(
} }
} }
override fun overlayViewAtPosition(context: Context, position: Int): View? { override fun getTimelineEventAtPosition(position: Int): TimelineEvent? {
super.overlayViewAtPosition(context, position) return attachments[position]
val item = attachments[position]
val dateString = dateFormatter.format(item.root.originServerTs, DateFormatKind.DEFAULT_DATE_AND_TIME)
overlayView?.updateWith(
counter = stringProvider.getString(R.string.attachment_viewer_item_x_of_y, position + 1, attachments.size),
senderInfo = "${item.senderInfo.displayName} $dateString"
)
overlayView?.videoControlsGroup?.isVisible = item.root.isVideoMessage()
return overlayView
} }
override fun getFileForSharing(position: Int, callback: (File?) -> Unit) { override fun getFileForSharing(position: Int, callback: (File?) -> Unit) {