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
abstract class BaseAttachmentProvider<Type>(
protected val attachments: List<Type>,
private val attachments: List<Type>,
private val imageContentRenderer: ImageContentRenderer,
protected val fileService: FileService,
private val dateFormatter: VectorDateFormatter,
@ -58,6 +58,8 @@ abstract class BaseAttachmentProvider<Type>(
final override fun getItemCount() = attachments.size
protected fun getItem(position: Int) = attachments[position]
final override fun overlayViewAtPosition(context: Context, position: Int): View? {
if (position == -1) return null
if (overlayView == null) {

View file

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

View file

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