Skip to content

Commit

Permalink
Code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mardous committed Nov 16, 2024
1 parent 0c7b81c commit 68ac3cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,19 @@ import android.provider.MediaStore
internal enum class StatusSaveType(
internal val dirName: String,
internal val fileMimeType: String,
internal val contentUri: Uri
internal val contentUri: Uri,
internal val dirTypeProvider: (SaveLocation) -> String
) {
IMAGE_SAVE(
"Saved Image Statuses",
"image/jpeg",
MediaStore.Images.Media.EXTERNAL_CONTENT_URI
dirName = "Saved Image Statuses",
fileMimeType = "image/jpeg",
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
dirTypeProvider = { it.imageDir }
),
VIDEO_SAVE(
"Saved Video Statuses",
"video/mp4",
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
dirName = "Saved Video Statuses",
fileMimeType = "video/mp4",
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
dirTypeProvider = { it.videoDir }
);

internal fun getDirType(location: SaveLocation) =
when (this) {
IMAGE_SAVE -> location.imageDir
VIDEO_SAVE -> location.videoDir
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ enum class StatusType(@StringRes val nameRes: Int, val format: String, private v

@TargetApi(Build.VERSION_CODES.Q)
fun getRelativePath(location: SaveLocation): String =
String.format("%s/%s", saveType.getDirType(location), saveType.dirName)
String.format("%s/%s", saveType.dirTypeProvider(location), saveType.dirName)

fun getSavesDirectory(location: SaveLocation): File =
File(Environment.getExternalStoragePublicDirectory(saveType.getDirType(location)), saveType.dirName)
File(Environment.getExternalStoragePublicDirectory(saveType.dirTypeProvider(location)), saveType.dirName)

fun getSavedContentFiles(location: SaveLocation): Array<File> {
val directory = getSavesDirectory(location)
Expand Down

0 comments on commit 68ac3cb

Please sign in to comment.