@@ -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