mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Address code review comments (#3669)
This commit is contained in:
parent
ff310e43e2
commit
fcd2867d26
1 changed files with 12 additions and 17 deletions
|
|
@ -20,27 +20,22 @@ object DownloadUtils {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun downloadMedia(activity: Activity?, m: Media) {
|
fun downloadMedia(activity: Activity?, m: Media) {
|
||||||
val imageUrl = m.getImageUrl()
|
val imageUrl = m.imageUrl
|
||||||
var fileName = m.getFilename()
|
var fileName = m.filename
|
||||||
if (imageUrl == null || fileName == null || activity == null
|
if (imageUrl == null || fileName == null || activity == null) {
|
||||||
) {
|
Timber.d("Skipping download media as either imageUrl $imageUrl or filename $fileName activity is null")
|
||||||
Timber.d(
|
|
||||||
"Skipping download media as either imageUrl %s or filename %s activity is null",
|
|
||||||
imageUrl, fileName
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Strip 'File:' from beginning of filename, we really shouldn't store it
|
// Strip 'File:' from beginning of filename, we really shouldn't store it
|
||||||
fileName = fileName.replaceFirst("^File:".toRegex(), "")
|
fileName = fileName.substringAfter("File:")
|
||||||
val imageUri = Uri.parse(imageUrl)
|
val imageUri = Uri.parse(imageUrl)
|
||||||
val req = DownloadManager.Request(imageUri)
|
val req = DownloadManager.Request(imageUri).apply {
|
||||||
//These are not the image title and description fields, they are download descs for notifications
|
setTitle(m.displayTitle)
|
||||||
req.setDescription(activity.getString(R.string.app_name))
|
setDescription(activity.getString(R.string.app_name))
|
||||||
req.setTitle(m.displayTitle)
|
setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
|
||||||
req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
|
allowScanningByMediaScanner()
|
||||||
// Modern Android updates the gallery automatically. Yay!
|
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||||
req.allowScanningByMediaScanner()
|
}
|
||||||
req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
|
||||||
PermissionUtils.checkPermissionsAndPerformAction(
|
PermissionUtils.checkPermissionsAndPerformAction(
|
||||||
activity,
|
activity,
|
||||||
permission.WRITE_EXTERNAL_STORAGE,
|
permission.WRITE_EXTERNAL_STORAGE,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue