From 6a4e9474e3d4c5b8da0408fe182c5d56c206679b Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti <66936649+anilbeesetti@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:18:05 +0530 Subject: [PATCH] Refactor: Rename Directory model to Folder model (#483) * refactor: get sorted video use case to use repository function instead of filtering * refactor: rename Directory model to Folder model * lint: run KtlintFormat --- .../mappers/DirectoryEntityToDirectory.kt | 4 +-- .../data/repository/LocalMediaRepository.kt | 12 ++++--- .../core/data/repository/MediaRepository.kt | 28 +++++++-------- .../repository/fake/FakeMediaRepository.kt | 10 ++++-- ...sUseCase.kt => GetSortedFoldersUseCase.kt} | 16 ++++----- .../core/domain/GetSortedVideosUseCase.kt | 36 +++++++++---------- .../core/model/{Directory.kt => Folder.kt} | 4 +-- .../MediaLibraryPreferencesViewModel.kt | 6 ++-- .../videopicker/MediaPickerScreenTest.kt | 8 ++--- .../videopicker/composables/FolderItem.kt | 16 ++++----- .../videopicker/composables/MediaContent.kt | 16 ++++----- .../feature/videopicker/screens/MediaState.kt | 4 +-- .../screens/media/MediaPickerViewModel.kt | 6 ++-- 13 files changed, 87 insertions(+), 79 deletions(-) rename core/domain/src/main/java/dev/anilbeesetti/nextplayer/core/domain/{GetSortedDirectoriesUseCase.kt => GetSortedFoldersUseCase.kt} (82%) rename core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/{Directory.kt => Folder.kt} (89%) diff --git a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/DirectoryEntityToDirectory.kt b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/DirectoryEntityToDirectory.kt index c5ad8ea97..73b3e360f 100644 --- a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/DirectoryEntityToDirectory.kt +++ b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/DirectoryEntityToDirectory.kt @@ -2,9 +2,9 @@ package dev.anilbeesetti.nextplayer.core.data.mappers import dev.anilbeesetti.nextplayer.core.common.Utils import dev.anilbeesetti.nextplayer.core.database.entities.DirectoryEntity -import dev.anilbeesetti.nextplayer.core.model.Directory +import dev.anilbeesetti.nextplayer.core.model.Folder -fun DirectoryEntity.toDirectory() = Directory( +fun DirectoryEntity.toFolder() = Folder( name = name, path = path, mediaSize = size, diff --git a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/LocalMediaRepository.kt b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/LocalMediaRepository.kt index ee5d2618b..3aaf87947 100644 --- a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/LocalMediaRepository.kt +++ b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/LocalMediaRepository.kt @@ -7,7 +7,7 @@ import androidx.activity.result.IntentSenderRequest import dagger.hilt.android.qualifiers.ApplicationContext import dev.anilbeesetti.nextplayer.core.common.di.ApplicationScope import dev.anilbeesetti.nextplayer.core.common.extensions.deleteFiles -import dev.anilbeesetti.nextplayer.core.data.mappers.toDirectory +import dev.anilbeesetti.nextplayer.core.data.mappers.toFolder import dev.anilbeesetti.nextplayer.core.data.mappers.toVideo import dev.anilbeesetti.nextplayer.core.data.mappers.toVideoState import dev.anilbeesetti.nextplayer.core.data.models.VideoState @@ -15,7 +15,7 @@ import dev.anilbeesetti.nextplayer.core.database.dao.DirectoryDao import dev.anilbeesetti.nextplayer.core.database.dao.MediumDao import dev.anilbeesetti.nextplayer.core.database.entities.DirectoryEntity import dev.anilbeesetti.nextplayer.core.database.entities.MediumEntity -import dev.anilbeesetti.nextplayer.core.model.Directory +import dev.anilbeesetti.nextplayer.core.model.Folder import dev.anilbeesetti.nextplayer.core.model.Video import javax.inject.Inject import kotlinx.coroutines.CoroutineScope @@ -36,8 +36,12 @@ class LocalMediaRepository @Inject constructor( return mediumDao.getAll().map { it.map(MediumEntity::toVideo) } } - override fun getDirectoriesFlow(): Flow> { - return directoryDao.getAll().map { it.map(DirectoryEntity::toDirectory) } + override fun getVideosFlowFromFolderPath(folderPath: String): Flow> { + return mediumDao.getAllFromDirectory(folderPath).map { it.map(MediumEntity::toVideo) } + } + + override fun getFoldersFlow(): Flow> { + return directoryDao.getAll().map { it.map(DirectoryEntity::toFolder) } } override suspend fun getVideoState(path: String): VideoState? { diff --git a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/MediaRepository.kt b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/MediaRepository.kt index edb407cac..46c215e04 100644 --- a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/MediaRepository.kt +++ b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/MediaRepository.kt @@ -3,7 +3,7 @@ package dev.anilbeesetti.nextplayer.core.data.repository import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.IntentSenderRequest import dev.anilbeesetti.nextplayer.core.data.models.VideoState -import dev.anilbeesetti.nextplayer.core.model.Directory +import dev.anilbeesetti.nextplayer.core.model.Folder import dev.anilbeesetti.nextplayer.core.model.Video import kotlinx.coroutines.flow.Flow @@ -14,7 +14,18 @@ interface MediaRepository { */ fun getVideosFlow(): Flow> - fun getDirectoriesFlow(): Flow> + /** + * Get list of [Video]s as flow for a specific directory + * @param folderPath the path the directory from which the videos should be returned + * @return flow of list of video items + */ + fun getVideosFlowFromFolderPath(folderPath: String): Flow> + + /** + * Get list of [Folder]s as flow + * @return flow of list of folder items + */ + fun getFoldersFlow(): Flow> /** * Save video state @@ -25,19 +36,8 @@ interface MediaRepository { * -1 to disable track * null to not change track */ - suspend fun saveVideoState( - path: String, - position: Long, - audioTrackIndex: Int?, - subtitleTrackIndex: Int?, - playbackSpeed: Float? - ) + suspend fun saveVideoState(path: String, position: Long, audioTrackIndex: Int?, subtitleTrackIndex: Int?, playbackSpeed: Float?) - /** - * Get video state - * @param path path of the video - * @return [VideoState] of the video - */ suspend fun getVideoState(path: String): VideoState? suspend fun deleteVideos(videoUris: List, intentSenderLauncher: ActivityResultLauncher) diff --git a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/fake/FakeMediaRepository.kt b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/fake/FakeMediaRepository.kt index 94e59746e..fe12e714d 100644 --- a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/fake/FakeMediaRepository.kt +++ b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/repository/fake/FakeMediaRepository.kt @@ -4,7 +4,7 @@ import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.IntentSenderRequest import dev.anilbeesetti.nextplayer.core.data.models.VideoState import dev.anilbeesetti.nextplayer.core.data.repository.MediaRepository -import dev.anilbeesetti.nextplayer.core.model.Directory +import dev.anilbeesetti.nextplayer.core.model.Folder import dev.anilbeesetti.nextplayer.core.model.Video import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf @@ -12,13 +12,17 @@ import kotlinx.coroutines.flow.flowOf class FakeMediaRepository : MediaRepository { val videos = mutableListOf