Skip to content

Commit adbd5c2

Browse files
maskaravivekashishkumar468
authored andcommitted
Address code review comments (commons-app#3669)
1 parent 709dacc commit adbd5c2

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

app/src/main/java/fr/free/nrw/commons/utils/DownloadUtils.kt

+12-17
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,22 @@ object DownloadUtils {
2020
*/
2121
@JvmStatic
2222
fun downloadMedia(activity: Activity?, m: Media) {
23-
val imageUrl = m.getImageUrl()
24-
var fileName = m.getFilename()
25-
if (imageUrl == null || fileName == null || activity == null
26-
) {
27-
Timber.d(
28-
"Skipping download media as either imageUrl %s or filename %s activity is null",
29-
imageUrl, fileName
30-
)
23+
val imageUrl = m.imageUrl
24+
var fileName = m.filename
25+
if (imageUrl == null || fileName == null || activity == null) {
26+
Timber.d("Skipping download media as either imageUrl $imageUrl or filename $fileName activity is null")
3127
return
3228
}
3329
// Strip 'File:' from beginning of filename, we really shouldn't store it
34-
fileName = fileName.replaceFirst("^File:".toRegex(), "")
30+
fileName = fileName.substringAfter("File:")
3531
val imageUri = Uri.parse(imageUrl)
36-
val req = DownloadManager.Request(imageUri)
37-
//These are not the image title and description fields, they are download descs for notifications
38-
req.setDescription(activity.getString(R.string.app_name))
39-
req.setTitle(m.displayTitle)
40-
req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
41-
// Modern Android updates the gallery automatically. Yay!
42-
req.allowScanningByMediaScanner()
43-
req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
32+
val req = DownloadManager.Request(imageUri).apply {
33+
setTitle(m.displayTitle)
34+
setDescription(activity.getString(R.string.app_name))
35+
setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
36+
allowScanningByMediaScanner()
37+
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
38+
}
4439
PermissionUtils.checkPermissionsAndPerformAction(
4540
activity,
4641
permission.WRITE_EXTERNAL_STORAGE,

0 commit comments

Comments
 (0)