Skip to content

Commit 18a7e94

Browse files
committed
Extend Signal subdirectory organization to all media types
Now all media types are organized in Signal subdirectories - Images: Pictures/Signal/ - Videos: Movies/Signal/ - Audio: Music/Signal/ - Documents: Documents/Signal/ (Android 9-) or Download/Signal/ (Android 10+) Note: Documents vs Downloads difference for generic files existed before this change - this PR only adds Signal subdirectory organization.
1 parent c10d09e commit 18a7e94

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/src/main/java/org/thoughtcrime/securesms/util/SaveAttachmentUtil.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,14 @@ object SaveAttachmentUtil {
156156
MediaStore.MediaColumns.DATE_MODIFIED to TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
157157
)
158158

159-
if (Build.VERSION.SDK_INT > 28 && contentType.startsWith("image/")) {
160-
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + "/Signal")
159+
if (Build.VERSION.SDK_INT > 28) {
160+
val relativePath = when {
161+
contentType.startsWith("image/") -> Environment.DIRECTORY_PICTURES + "/Signal"
162+
contentType.startsWith("video/") -> Environment.DIRECTORY_MOVIES + "/Signal"
163+
contentType.startsWith("audio/") -> Environment.DIRECTORY_MUSIC + "/Signal"
164+
else -> Environment.DIRECTORY_DOWNLOADS + "/Signal"
165+
}
166+
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativePath)
161167
}
162168

163169
if (Build.VERSION.SDK_INT > 28) {
@@ -217,10 +223,10 @@ object SaveAttachmentUtil {
217223

218224
private fun getExternalPathForType(contentType: String): String? {
219225
val storage: File? = when {
220-
contentType.startsWith("video/") -> Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)
221-
contentType.startsWith("audio/") -> Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
226+
contentType.startsWith("video/") -> File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "Signal")
227+
contentType.startsWith("audio/") -> File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), "Signal")
222228
contentType.startsWith("image/") -> File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Signal")
223-
else -> Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
229+
else -> File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Signal")
224230
}
225231

226232
return storage?.let { ensureExternalPath(storage) }?.absolutePath

0 commit comments

Comments
 (0)