~gardenapple/mitch

c7e39270afda67613be239d787197879a3c81c91 — gardenapple 14 days ago 69c15e1
Make sure the notification disappears on download cancel
M app/src/main/java/ua/gardenapple/itchupdater/files/DownloadFileListener.kt => app/src/main/java/ua/gardenapple/itchupdater/files/DownloadFileListener.kt +11 -0
@@ 1,5 1,7 @@
package ua.gardenapple.itchupdater.files

import android.app.Activity
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent


@@ 133,4 135,13 @@ abstract class DownloadFileListener {
                             progressPercent: Int?) {
        createProgressNotification(context, file, downloadId, uploadId, progressPercent)
    }

    /**
     * Quietly cancel download
     */
    protected fun onCancel(context: Context, downloadId: Int) {
        with(context.getSystemService(Activity.NOTIFICATION_SERVICE) as NotificationManager) {
            cancel(NOTIFICATION_TAG_DOWNLOAD, downloadId)
        }
    }
}

M app/src/main/java/ua/gardenapple/itchupdater/files/Downloader.kt => app/src/main/java/ua/gardenapple/itchupdater/files/Downloader.kt +2 -0
@@ 1,5 1,6 @@
package ua.gardenapple.itchupdater.files

import android.app.NotificationManager
import android.content.Context
import android.util.Log
import android.webkit.CookieManager


@@ 176,6 177,7 @@ object Downloader : DownloadFileListener() {
                    Downloader.onCompleted(applicationContext, file.name, uploadId, downloadId)
                }
            } catch (e: CancellationException) {
                Downloader.onCancel(applicationContext, downloadId)
                return@withContext Result.failure()
            } catch (e: Exception) {
                Log.e(LOGGING_TAG, "Caught while downloading", e)