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.view.View
import android.widget.ImageView
import androidx.core.view.isVisible
import com.bumptech.glide.request.target.CustomViewTarget
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.lib.attachmentviewer.AttachmentInfo
import im.vector.lib.attachmentviewer.AttachmentSourceProvider
import im.vector.lib.attachmentviewer.ImageLoaderTarget
import im.vector.lib.attachmentviewer.VideoLoaderTarget
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.room.timeline.TimelineEvent
import java.io.File
abstract class BaseAttachmentProvider(
private val imageContentRenderer: ImageContentRenderer,
protected val fileService: FileService,
protected val stringProvider: StringProvider
private val dateFormatter: VectorDateFormatter,
private val stringProvider: StringProvider
) : AttachmentSourceProvider {
interface InteractionListener {
@ -48,7 +55,7 @@ abstract class BaseAttachmentProvider(
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 (overlayView == null) {
overlayView = AttachmentOverlayView(context)
@ -65,9 +72,24 @@ abstract class BaseAttachmentProvider(
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
}
abstract fun getTimelineEventAtPosition(position: Int): TimelineEvent?
override fun loadImage(target: ImageLoaderTarget, info: AttachmentInfo.Image) {
(info.data as? ImageContentRenderer.Data)?.let {
imageContentRenderer.render(it, target.contextView(), object : CustomViewTarget<ImageView, Drawable>(target.contextView()) {

View file

@ -16,28 +16,23 @@
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.resources.StringProvider
import im.vector.lib.attachmentviewer.AttachmentInfo
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.room.Room
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import java.io.File
class DataAttachmentRoomProvider(
private val attachments: List<AttachmentData>,
private val room: Room?,
imageContentRenderer: ImageContentRenderer,
private val dateFormatter: VectorDateFormatter,
dateFormatter: VectorDateFormatter,
fileService: FileService,
stringProvider: StringProvider
) : BaseAttachmentProvider(imageContentRenderer, fileService, stringProvider) {
) : BaseAttachmentProvider(imageContentRenderer, fileService, dateFormatter, stringProvider) {
override fun getItemCount(): Int = attachments.size
@ -76,21 +71,9 @@ class DataAttachmentRoomProvider(
}
}
override fun overlayViewAtPosition(context: Context, position: Int): View? {
super.overlayViewAtPosition(context, position)
override fun getTimelineEventAtPosition(position: Int): TimelineEvent? {
val item = attachments[position]
val timeLineEvent = 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
return room?.getTimeLineEvent(item.eventId)
}
override fun getFileForSharing(position: Int, callback: (File?) -> Unit) {

View file

@ -16,17 +16,11 @@
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.resources.StringProvider
import im.vector.lib.attachmentviewer.AttachmentInfo
import org.matrix.android.sdk.api.MatrixCallback
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.file.FileService
import org.matrix.android.sdk.api.session.room.Room
@ -43,10 +37,10 @@ import javax.inject.Inject
class RoomEventsAttachmentProvider(
private val attachments: List<TimelineEvent>,
imageContentRenderer: ImageContentRenderer,
private val dateFormatter: VectorDateFormatter,
dateFormatter: VectorDateFormatter,
fileService: FileService,
stringProvider: StringProvider
) : BaseAttachmentProvider(imageContentRenderer, fileService, stringProvider) {
) : BaseAttachmentProvider(imageContentRenderer, fileService, dateFormatter, stringProvider) {
override fun getItemCount(): Int {
return attachments.size
@ -127,16 +121,8 @@ class RoomEventsAttachmentProvider(
}
}
override fun overlayViewAtPosition(context: Context, position: Int): View? {
super.overlayViewAtPosition(context, 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 getTimelineEventAtPosition(position: Int): TimelineEvent? {
return attachments[position]
}
override fun getFileForSharing(position: Int, callback: (File?) -> Unit) {