@@ -20,27 +20,22 @@ object DownloadUtils {
20
20
*/
21
21
@JvmStatic
22
22
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" )
31
27
return
32
28
}
33
29
// Strip 'File:' from beginning of filename, we really shouldn't store it
34
- fileName = fileName.replaceFirst( " ^ File:" .toRegex(), " " )
30
+ fileName = fileName.substringAfter( " File:" )
35
31
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
+ }
44
39
PermissionUtils .checkPermissionsAndPerformAction(
45
40
activity,
46
41
permission.WRITE_EXTERNAL_STORAGE ,
0 commit comments