From 53f7a9fe176fa5f912bf46a7bf7b63837ce3b78f Mon Sep 17 00:00:00 2001 From: rimthekid Date: Fri, 4 Mar 2022 22:52:30 +0400 Subject: [PATCH] failure notif --- app/release/output-metadata.json | 26 ++++++++-------- .../com/github/libretube/DownloadService.kt | 31 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 8d992d142..50d7ff07a 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -20,6 +20,19 @@ "versionName": "0.2.2", "outputFile": "app-x86_64-release.apk" }, + { + "type": "ONE_OF_MANY", + "filters": [ + { + "filterType": "ABI", + "value": "x86" + } + ], + "attributes": [], + "versionCode": 4, + "versionName": "0.2.2", + "outputFile": "app-x86-release.apk" + }, { "type": "ONE_OF_MANY", "filters": [ @@ -45,19 +58,6 @@ "versionCode": 4, "versionName": "0.2.2", "outputFile": "app-arm64-v8a-release.apk" - }, - { - "type": "ONE_OF_MANY", - "filters": [ - { - "filterType": "ABI", - "value": "x86" - } - ], - "attributes": [], - "versionCode": 4, - "versionName": "0.2.2", - "outputFile": "app-x86-release.apk" } ], "elementType": "File" diff --git a/app/src/main/java/com/github/libretube/DownloadService.kt b/app/src/main/java/com/github/libretube/DownloadService.kt index 027ffe9e9..3058b06fb 100644 --- a/app/src/main/java/com/github/libretube/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/DownloadService.kt @@ -12,6 +12,7 @@ import android.os.Environment import android.os.IBinder import android.util.Log import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat import com.arthenica.ffmpegkit.FFmpegKit import java.io.File @@ -193,7 +194,18 @@ class DownloadService : Service(){ val folder_main = ".tmp" val f = File(path, folder_main) f.deleteRecursively() - //Toast.makeText(this@DownloadService, R.string.dlcomplete, Toast.LENGTH_LONG).show() + if (returnCode.toString()!="0"){ + var builder = NotificationCompat.Builder(this@DownloadService, "failed") + .setSmallIcon(R.drawable.ic_download) + .setContentTitle(resources.getString(R.string.downloadfailed)) + .setContentText("failure") + .setPriority(NotificationCompat.PRIORITY_HIGH) + createNotificationChannel() + with(NotificationManagerCompat.from(this@DownloadService)) { + // notificationId is a unique int for each notification that you must define + notify(69, builder.build()) + } + } stopForeground(true) stopService(Intent(this@DownloadService,DownloadService::class.java)) }, { @@ -214,7 +226,22 @@ class DownloadService : Service(){ } } - + private fun createNotificationChannel() { + // Create the NotificationChannel, but only on API 26+ because + // the NotificationChannel class is new and not in the support library + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val name = "failed" + val descriptionText = "Download Failed" + val importance = NotificationManager.IMPORTANCE_DEFAULT + val channel = NotificationChannel("failed", name, importance).apply { + description = descriptionText + } + // Register the channel with the system + val notificationManager: NotificationManager = + getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + notificationManager.createNotificationChannel(channel) + } + } override fun onDestroy() { try { unregisterReceiver(onDownloadComplete) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c38703a5..fe35e1c7e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -26,4 +26,5 @@ Can\'t Download this stream! Download is completed! Another Download is already in progress please wait till it\'s finished! + Download Failed! \ No newline at end of file