Last cleanup

This commit is contained in:
Benoit Marty 2020-11-10 15:36:22 +01:00 committed by Benoit Marty
parent 45e534bbf5
commit f57fc827fe
3 changed files with 9 additions and 8 deletions

View File

@ -38,7 +38,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import java.io.File import java.io.File
abstract class BaseAttachmentProvider<Type>( abstract class BaseAttachmentProvider<Type>(
protected val attachments: List<Type>, private val attachments: List<Type>,
private val imageContentRenderer: ImageContentRenderer, private val imageContentRenderer: ImageContentRenderer,
protected val fileService: FileService, protected val fileService: FileService,
private val dateFormatter: VectorDateFormatter, private val dateFormatter: VectorDateFormatter,
@ -58,6 +58,8 @@ abstract class BaseAttachmentProvider<Type>(
final override fun getItemCount() = attachments.size final override fun getItemCount() = attachments.size
protected fun getItem(position: Int) = attachments[position]
final 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) {

View File

@ -35,7 +35,7 @@ class DataAttachmentRoomProvider(
) : BaseAttachmentProvider<AttachmentData>(attachments, imageContentRenderer, fileService, dateFormatter, stringProvider) { ) : BaseAttachmentProvider<AttachmentData>(attachments, imageContentRenderer, fileService, dateFormatter, stringProvider) {
override fun getAttachmentInfoAt(position: Int): AttachmentInfo { override fun getAttachmentInfoAt(position: Int): AttachmentInfo {
return attachments[position].let { return getItem(position).let {
when (it) { when (it) {
is ImageContentRenderer.Data -> { is ImageContentRenderer.Data -> {
if (it.mimeType == "image/gif") { if (it.mimeType == "image/gif") {
@ -70,12 +70,12 @@ class DataAttachmentRoomProvider(
} }
override fun getTimelineEventAtPosition(position: Int): TimelineEvent? { override fun getTimelineEventAtPosition(position: Int): TimelineEvent? {
val item = attachments[position] val item = getItem(position)
return room?.getTimeLineEvent(item.eventId) return room?.getTimeLineEvent(item.eventId)
} }
override fun getFileForSharing(position: Int, callback: (File?) -> Unit) { override fun getFileForSharing(position: Int, callback: (File?) -> Unit) {
val item = attachments[position] val item = getItem(position)
fileService.downloadFile( fileService.downloadFile(
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE, downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
id = item.eventId, id = item.eventId,

View File

@ -40,7 +40,7 @@ class RoomEventsAttachmentProvider(
) : BaseAttachmentProvider<TimelineEvent>(attachments, imageContentRenderer, fileService, dateFormatter, stringProvider) { ) : BaseAttachmentProvider<TimelineEvent>(attachments, imageContentRenderer, fileService, dateFormatter, stringProvider) {
override fun getAttachmentInfoAt(position: Int): AttachmentInfo { override fun getAttachmentInfoAt(position: Int): AttachmentInfo {
return attachments[position].let { return getItem(position).let {
val content = it.root.getClearContent().toModel<MessageContent>() as? MessageWithAttachmentContent val content = it.root.getClearContent().toModel<MessageContent>() as? MessageWithAttachmentContent
if (content is MessageImageContent) { if (content is MessageImageContent) {
val data = ImageContentRenderer.Data( val data = ImageContentRenderer.Data(
@ -115,11 +115,11 @@ class RoomEventsAttachmentProvider(
} }
override fun getTimelineEventAtPosition(position: Int): TimelineEvent? { override fun getTimelineEventAtPosition(position: Int): TimelineEvent? {
return attachments[position] return getItem(position)
} }
override fun getFileForSharing(position: Int, callback: (File?) -> Unit) { override fun getFileForSharing(position: Int, callback: (File?) -> Unit) {
attachments[position].let { timelineEvent -> getItem(position).let { timelineEvent ->
val messageContent = timelineEvent.root.getClearContent().toModel<MessageContent>() val messageContent = timelineEvent.root.getClearContent().toModel<MessageContent>()
as? MessageWithAttachmentContent as? MessageWithAttachmentContent
@ -144,4 +144,3 @@ class RoomEventsAttachmentProvider(
} }
} }
} }