Skip to content

Commit 090960e

Browse files
committed
Store downloaded video files in separate folders per language
1 parent b08b7e3 commit 090960e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

app/src/main/java/ai/elimu/content_provider/util/FileHelper.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object FileHelper {
4747
if ((videoGson.id == null) || (videoGson.revisionNumber == null)) {
4848
return null
4949
}
50-
val videosDirectory = context.getExternalFilesDir(Environment.DIRECTORY_MOVIES)
50+
val videosDirectory = getVideosDirectory(context)
5151
val file = File(
5252
videosDirectory,
5353
videoGson.id.toString() + "_r" + videoGson.revisionNumber + "." + videoGson.videoFormat.toString()
@@ -64,11 +64,20 @@ object FileHelper {
6464
if ((videoGson.id == null) || (videoGson.revisionNumber == null)) {
6565
return null
6666
}
67-
val videosDirectory = context.getExternalFilesDir(Environment.DIRECTORY_MOVIES)
67+
val videosDirectory = getVideosDirectory(context)
6868
return File(
6969
videosDirectory, (videoGson.id
7070
.toString() + "_r" + videoGson.revisionNumber + "."
7171
+ videoGson.videoFormat.toString().lowercase(Locale.getDefault()))
7272
)
7373
}
74+
75+
private fun getVideosDirectory(context: Context): File? {
76+
val languageIsoCode: String? = SharedPreferencesHelper.getLanguage(context)?.isoCode
77+
78+
val videosDirectory = languageIsoCode?.let { isoCode ->
79+
context.getExternalFilesDir(Environment.DIRECTORY_MOVIES + "/lang-" + isoCode.uppercase())
80+
} ?: context.getExternalFilesDir(Environment.DIRECTORY_MOVIES)
81+
return videosDirectory
82+
}
7483
}

0 commit comments

Comments
 (0)