Cleanup
This commit is contained in:
@@ -39,7 +39,6 @@ interface MediaViewerEntryPoint : FeatureEntryPoint {
|
||||
val canShowInfo: Boolean,
|
||||
) : NodeInputs
|
||||
|
||||
// TODO convert to sealed class and add eventId to the 2nd and 3rd items
|
||||
enum class MediaViewerMode {
|
||||
SingleMedia,
|
||||
TimelineImagesAndVideos,
|
||||
|
||||
@@ -50,7 +50,7 @@ class TimelineMediaGalleryDataSource @Inject constructor(
|
||||
override fun groupedMediaItemsFlow(): Flow<AsyncData<GroupedMediaItems>> = groupedMediaItemsFlow
|
||||
|
||||
override fun getLastData(): AsyncData<GroupedMediaItems> = groupedMediaItemsFlow.replayCache.firstOrNull()
|
||||
?: mediaTimeline.getCache()?.let { AsyncData.Success(it) }
|
||||
?: mediaTimeline.cache?.let { AsyncData.Success(it) }
|
||||
?: AsyncData.Uninitialized
|
||||
|
||||
private val isStarted = AtomicBoolean(false)
|
||||
@@ -61,7 +61,7 @@ class TimelineMediaGalleryDataSource @Inject constructor(
|
||||
return
|
||||
}
|
||||
flow {
|
||||
val cache = mediaTimeline.getCache()
|
||||
val cache = mediaTimeline.cache
|
||||
if (cache != null) {
|
||||
groupedMediaItemsFlow.emit(AsyncData.Success(cache))
|
||||
} else {
|
||||
|
||||
@@ -9,6 +9,7 @@ package io.element.android.libraries.mediaviewer.impl.gallery
|
||||
|
||||
import io.element.android.libraries.architecture.AsyncData
|
||||
import io.element.android.libraries.designsystem.utils.snackbar.SnackbarMessage
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
import io.element.android.libraries.mediaviewer.impl.R
|
||||
import io.element.android.libraries.mediaviewer.impl.details.MediaBottomSheetState
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
@@ -34,6 +35,12 @@ data class GroupedMediaItems(
|
||||
}
|
||||
}
|
||||
|
||||
fun GroupedMediaItems.hasEvent(eventId: EventId): Boolean {
|
||||
return (fileItems + imageAndVideoItems)
|
||||
.filterIsInstance<MediaItem.Event>()
|
||||
.any { it.eventId() == eventId }
|
||||
}
|
||||
|
||||
enum class MediaGalleryMode(val stringResource: Int) {
|
||||
Images(R.string.screen_media_browser_list_mode_media),
|
||||
Files(R.string.screen_media_browser_list_mode_files),
|
||||
|
||||
@@ -440,10 +440,7 @@ private fun LoadingMoreIndicator(
|
||||
}
|
||||
val latestEventSink by rememberUpdatedState(eventSink)
|
||||
LaunchedEffect(item.timestamp) {
|
||||
// TODO Add isFake to the model instead of using -1 for timestamp
|
||||
if (item.timestamp != -1L) {
|
||||
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
|
||||
}
|
||||
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import javax.inject.Inject
|
||||
|
||||
interface MediaTimeline {
|
||||
suspend fun getTimeline(): Result<Timeline>
|
||||
fun getCache(): GroupedMediaItems?
|
||||
val cache: GroupedMediaItems?
|
||||
fun orCache(data: GroupedMediaItems): GroupedMediaItems
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class LiveMediaTimeline @Inject constructor(
|
||||
}
|
||||
|
||||
// No cache for LiveMediaTimeline
|
||||
override fun getCache(): GroupedMediaItems? = null
|
||||
override val cache = null
|
||||
override fun orCache(data: GroupedMediaItems) = data
|
||||
}
|
||||
|
||||
@@ -61,41 +61,28 @@ class LiveMediaTimeline @Inject constructor(
|
||||
class FocusedMediaTimeline(
|
||||
private val room: MatrixRoom,
|
||||
private val eventId: EventId,
|
||||
private val initialMediaItem: MediaItem.Event,
|
||||
initialMediaItem: MediaItem.Event,
|
||||
) : MediaTimeline {
|
||||
override suspend fun getTimeline(): Result<Timeline> {
|
||||
return room.mediaTimeline(eventId)
|
||||
}
|
||||
|
||||
override fun getCache(): GroupedMediaItems {
|
||||
// TODO Cleanup
|
||||
return GroupedMediaItems(
|
||||
fileItems = persistentListOf(
|
||||
MediaItem.LoadingIndicator(
|
||||
id = UniqueId("loading_forwards"),
|
||||
direction = Timeline.PaginationDirection.FORWARDS,
|
||||
timestamp = -1L,
|
||||
),
|
||||
initialMediaItem,
|
||||
MediaItem.LoadingIndicator(
|
||||
id = UniqueId("loading_backwards"),
|
||||
direction = Timeline.PaginationDirection.BACKWARDS,
|
||||
timestamp = -1L,
|
||||
),
|
||||
),
|
||||
imageAndVideoItems = persistentListOf(
|
||||
MediaItem.LoadingIndicator(
|
||||
id = UniqueId("loading_forwards"),
|
||||
direction = Timeline.PaginationDirection.FORWARDS,
|
||||
timestamp = -1L,
|
||||
),
|
||||
initialMediaItem,
|
||||
MediaItem.LoadingIndicator(
|
||||
id = UniqueId("loading_backwards"),
|
||||
direction = Timeline.PaginationDirection.BACKWARDS,
|
||||
timestamp = -1L,
|
||||
),
|
||||
),
|
||||
override val cache = persistentListOf(
|
||||
MediaItem.LoadingIndicator(
|
||||
id = UniqueId("loading_forwards"),
|
||||
direction = Timeline.PaginationDirection.FORWARDS,
|
||||
timestamp = 0L,
|
||||
),
|
||||
initialMediaItem,
|
||||
MediaItem.LoadingIndicator(
|
||||
id = UniqueId("loading_backwards"),
|
||||
direction = Timeline.PaginationDirection.BACKWARDS,
|
||||
timestamp = 0L,
|
||||
),
|
||||
).let {
|
||||
GroupedMediaItems(
|
||||
fileItems = it,
|
||||
imageAndVideoItems = it,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -103,13 +90,7 @@ class FocusedMediaTimeline(
|
||||
return if (data.hasEvent(eventId)) {
|
||||
data
|
||||
} else {
|
||||
getCache()
|
||||
cache
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun GroupedMediaItems.hasEvent(eventId: EventId): Boolean {
|
||||
return (fileItems + imageAndVideoItems)
|
||||
.filterIsInstance<MediaItem.Event>()
|
||||
.any { it.eventId() == eventId }
|
||||
}
|
||||
|
||||
@@ -50,11 +50,3 @@ sealed interface MediaViewerPageData {
|
||||
override val pagerKey: Long,
|
||||
) : MediaViewerPageData
|
||||
}
|
||||
|
||||
fun MediaViewerPageData.toKey(): String {
|
||||
return when (this) {
|
||||
is MediaViewerPageData.Failure -> "Failure"
|
||||
is MediaViewerPageData.Loading -> "Loading_${direction}"
|
||||
is MediaViewerPageData.MediaViewerData -> eventId?.value ?: mediaSource.url
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ class KonsistClassNameTest {
|
||||
"Enterprise",
|
||||
"Fdroid",
|
||||
"FileExtensionExtractor",
|
||||
"LiveMediaTimeline",
|
||||
"KeyStore",
|
||||
"Matrix",
|
||||
"Noop",
|
||||
|
||||
Reference in New Issue
Block a user