From 234ca8c08f766b4628dbe43c44446956dbfed11f Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Sat, 22 Oct 2022 14:59:33 +0530 Subject: [PATCH 1/8] Simplified the download notification --- .../com/github/libretube/services/DownloadService.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index dc5893993..706dcff04 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -48,7 +48,7 @@ class DownloadService : Service() { } if (downloadType != DownloadType.NONE) { - downloadManager() + downloadManager(videoName) } else { onDestroy() } @@ -60,7 +60,7 @@ class DownloadService : Service() { TODO("Not yet implemented") } - private fun downloadManager() { + private fun downloadManager(videoName: String) { // initialize and create the directories to download into val videoDownloadDir = DownloadHelper.getVideoDir(this) @@ -74,7 +74,7 @@ class DownloadService : Service() { ) if (downloadType in listOf(DownloadType.VIDEO, DownloadType.AUDIO_VIDEO)) { videoDownloadId = downloadManagerRequest( - getString(R.string.video), + videoName, getString(R.string.downloading), videoUrl, Uri.fromFile( @@ -82,9 +82,9 @@ class DownloadService : Service() { ) ) } - if (downloadType in listOf(DownloadType.AUDIO, DownloadType.AUDIO_VIDEO)) { + else if (downloadType in listOf(DownloadType.AUDIO, DownloadType.AUDIO_VIDEO)) { audioDownloadId = downloadManagerRequest( - getString(R.string.audio), + videoName, getString(R.string.downloading), audioUrl, Uri.fromFile( From ae87a1d05f5f08f3d096ad9d30b3993eecf5d7a5 Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Sat, 22 Oct 2022 23:33:19 +0530 Subject: [PATCH 2/8] Added the permission for hidden notification --- app/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 02a10b7ca..61d32266e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ - + From a066363e88e85248d81c4e7e6bed12c73aed1854 Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Sat, 22 Oct 2022 23:34:55 +0530 Subject: [PATCH 3/8] Modified the notification visibility for audio --- .../com/github/libretube/services/DownloadService.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 706dcff04..a6bea09bb 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -1,6 +1,7 @@ package com.github.libretube.services import android.app.DownloadManager +import android.app.DownloadManager.Request.VISIBILITY_HIDDEN import android.app.Service import android.content.BroadcastReceiver import android.content.Context @@ -77,16 +78,18 @@ class DownloadService : Service() { videoName, getString(R.string.downloading), videoUrl, + false, Uri.fromFile( File(videoDownloadDir, videoName) ) ) } - else if (downloadType in listOf(DownloadType.AUDIO, DownloadType.AUDIO_VIDEO)) { + if (downloadType in listOf(DownloadType.AUDIO, DownloadType.AUDIO_VIDEO)) { audioDownloadId = downloadManagerRequest( videoName, getString(R.string.downloading), audioUrl, + true, Uri.fromFile( File(audioDownloadDir, videoName) ) @@ -123,6 +126,7 @@ class DownloadService : Service() { title: String, descriptionText: String, url: String, + isAudio: Boolean, destination: Uri ): Long { val request: DownloadManager.Request = @@ -132,6 +136,9 @@ class DownloadService : Service() { .setDestinationUri(destination) .setAllowedOverMetered(true) // Set if download is allowed on Mobile network .setAllowedOverRoaming(true) + if (isAudio) { + request.setNotificationVisibility(VISIBILITY_HIDDEN) + } val downloadManager: DownloadManager = applicationContext.getSystemService(DOWNLOAD_SERVICE) as DownloadManager From 42ce52bf29e7411e1d69404afdcee979000f1278 Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Sun, 23 Oct 2022 21:23:20 +0530 Subject: [PATCH 4/8] Changed the download notification title --- .../com/github/libretube/services/DownloadService.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index a6bea09bb..a02933279 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -1,7 +1,6 @@ package com.github.libretube.services import android.app.DownloadManager -import android.app.DownloadManager.Request.VISIBILITY_HIDDEN import android.app.Service import android.content.BroadcastReceiver import android.content.Context @@ -27,7 +26,6 @@ class DownloadService : Service() { private lateinit var videoUrl: String private lateinit var audioUrl: String private var downloadType: Int = 3 - private var videoDownloadId: Long? = null private var audioDownloadId: Long? = null @@ -75,10 +73,9 @@ class DownloadService : Service() { ) if (downloadType in listOf(DownloadType.VIDEO, DownloadType.AUDIO_VIDEO)) { videoDownloadId = downloadManagerRequest( - videoName, + "[Video] $videoName", getString(R.string.downloading), videoUrl, - false, Uri.fromFile( File(videoDownloadDir, videoName) ) @@ -86,10 +83,9 @@ class DownloadService : Service() { } if (downloadType in listOf(DownloadType.AUDIO, DownloadType.AUDIO_VIDEO)) { audioDownloadId = downloadManagerRequest( - videoName, + "[Audio] $videoName", getString(R.string.downloading), audioUrl, - true, Uri.fromFile( File(audioDownloadDir, videoName) ) @@ -126,7 +122,6 @@ class DownloadService : Service() { title: String, descriptionText: String, url: String, - isAudio: Boolean, destination: Uri ): Long { val request: DownloadManager.Request = @@ -136,9 +131,6 @@ class DownloadService : Service() { .setDestinationUri(destination) .setAllowedOverMetered(true) // Set if download is allowed on Mobile network .setAllowedOverRoaming(true) - if (isAudio) { - request.setNotificationVisibility(VISIBILITY_HIDDEN) - } val downloadManager: DownloadManager = applicationContext.getSystemService(DOWNLOAD_SERVICE) as DownloadManager From 3b2c4d06d4ef4bdfdcb44cdb0e758449d19f02d9 Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Sun, 23 Oct 2022 21:25:21 +0530 Subject: [PATCH 5/8] Removed the permission for hidden notification --- app/src/main/AndroidManifest.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 61d32266e..1fd90ad13 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,6 @@ - From 8bd8be15223113792c42d35ff9a4271f8397a142 Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Sun, 23 Oct 2022 22:55:34 +0530 Subject: [PATCH 6/8] Fixed string resources --- .../java/com/github/libretube/services/DownloadService.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index a02933279..9a803e52d 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -26,6 +26,7 @@ class DownloadService : Service() { private lateinit var videoUrl: String private lateinit var audioUrl: String private var downloadType: Int = 3 + private var videoDownloadId: Long? = null private var audioDownloadId: Long? = null @@ -73,7 +74,7 @@ class DownloadService : Service() { ) if (downloadType in listOf(DownloadType.VIDEO, DownloadType.AUDIO_VIDEO)) { videoDownloadId = downloadManagerRequest( - "[Video] $videoName", + "[${getString(R.string.video)}] $videoName", getString(R.string.downloading), videoUrl, Uri.fromFile( @@ -83,7 +84,7 @@ class DownloadService : Service() { } if (downloadType in listOf(DownloadType.AUDIO, DownloadType.AUDIO_VIDEO)) { audioDownloadId = downloadManagerRequest( - "[Audio] $videoName", + "[${getString(R.string.audio)}] $videoName", getString(R.string.downloading), audioUrl, Uri.fromFile( From d1ae2e5096b06d36718a26f1ec7f1282eb3ddcb5 Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Sun, 23 Oct 2022 23:12:33 +0530 Subject: [PATCH 7/8] Formatted with ktlint --- .../main/java/com/github/libretube/services/DownloadService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 9a803e52d..a9658d393 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -26,7 +26,7 @@ class DownloadService : Service() { private lateinit var videoUrl: String private lateinit var audioUrl: String private var downloadType: Int = 3 - + private var videoDownloadId: Long? = null private var audioDownloadId: Long? = null From 3c878c3148a702083d613b636e025632721a27fd Mon Sep 17 00:00:00 2001 From: shantanu1k Date: Mon, 24 Oct 2022 10:59:56 +0530 Subject: [PATCH 8/8] minor fix --- .../java/com/github/libretube/services/DownloadService.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index a9658d393..e135cd32e 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -48,7 +48,7 @@ class DownloadService : Service() { } if (downloadType != DownloadType.NONE) { - downloadManager(videoName) + downloadManager() } else { onDestroy() } @@ -60,7 +60,7 @@ class DownloadService : Service() { TODO("Not yet implemented") } - private fun downloadManager(videoName: String) { + private fun downloadManager() { // initialize and create the directories to download into val videoDownloadDir = DownloadHelper.getVideoDir(this)