fix pause button duplication

This commit is contained in:
LuftVerbot 2023-06-04 11:55:01 +02:00
parent 283576336a
commit 64d737433f

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.data.download.anime package eu.kanade.tachiyomi.data.download.anime
import android.annotation.SuppressLint
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Context import android.content.Context
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
@ -77,6 +78,7 @@ internal class AnimeDownloadNotifier(private val context: Context) {
* *
* @param download download object containing download information. * @param download download object containing download information.
*/ */
@SuppressLint("RestrictedApi")
fun onProgressChange(download: AnimeDownload) { fun onProgressChange(download: AnimeDownload) {
val notificationId = download.episode.id.hashCode() val notificationId = download.episode.id.hashCode()
@ -112,18 +114,19 @@ internal class AnimeDownloadNotifier(private val context: Context) {
} }
setOngoing(true) setOngoing(true)
show(notificationId)
}
// Add pause action if not already added // Add pause action if not already added
if (!paused) { val pauseActionAdded = progressNotificationBuilder.mActions.any { it.icon == R.drawable.ic_pause_24dp }
addAction( if (!paused && !pauseActionAdded) {
progressNotificationBuilder.addAction(
R.drawable.ic_pause_24dp, R.drawable.ic_pause_24dp,
context.getString(R.string.action_pause), context.getString(R.string.action_pause),
NotificationReceiver.pauseAnimeDownloadsPendingBroadcast(context), NotificationReceiver.pauseAnimeDownloadsPendingBroadcast(context),
) )
paused = true paused = true
} }
show(notificationId)
}
} }
/** /**