From 43ecdd3aacfb37b55f3b2f0c3d34156bb42c0c34 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 7 Sep 2023 19:19:01 +0530 Subject: [PATCH 1/3] chore: Update AndroidX Core --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9fc45cf03d..750b2c4745 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] appcompat = "1.6.1" -core = "1.10.1" +core = "1.12.0" gradle = "8.1.1" lifecycle = "2.6.2" constraintlayout = "2.1.4" From d808a48529a2f8230e41ae12b6832bc8155d2ba4 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 7 Sep 2023 19:28:52 +0530 Subject: [PATCH 2/3] fix: Handle PendingIntentCompat changes --- .../github/libretube/helpers/PlayerHelper.kt | 2 +- .../libretube/util/NowPlayingNotification.kt | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index 61ef89222b..fa1387efc0 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -346,7 +346,7 @@ object PlayerHelper { private fun getPendingIntent(activity: Activity, event: PlayerEvent): PendingIntent { val intent = Intent(getIntentAction(activity)).putExtra(CONTROL_TYPE, event) - return PendingIntentCompat.getBroadcast(activity, event.ordinal, intent, 0, false) + return PendingIntentCompat.getBroadcast(activity, event.ordinal, intent, 0, false)!! } private fun getRemoteAction( diff --git a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt index 1df0e6c261..4c7c4a8e5f 100644 --- a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt +++ b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt @@ -2,7 +2,6 @@ package com.github.libretube.util import android.app.NotificationManager import android.app.PendingIntent -import android.app.PendingIntent.FLAG_UPDATE_CURRENT import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -74,7 +73,7 @@ class NowPlayingNotification( } } - private fun createCurrentContentIntent(): PendingIntent { + private fun createCurrentContentIntent(): PendingIntent? { // starts a new MainActivity Intent when the player notification is clicked // it doesn't start a completely new MainActivity because the MainActivity's launchMode // is set to "singleTop" in the AndroidManifest (important!!!) @@ -85,11 +84,12 @@ class NowPlayingNotification( addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) } } - return PendingIntentCompat.getActivity(context, 0, intent, FLAG_UPDATE_CURRENT, false) + return PendingIntentCompat + .getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, false) } - private fun createDeleteIntent(): PendingIntent { - val intent = Intent(STOP).setPackage(context.packageName) + private fun createIntent(action: String): PendingIntent? { + val intent = Intent(action).setPackage(context.packageName) return PendingIntentCompat .getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT, false) } @@ -141,10 +141,8 @@ class NowPlayingNotification( drawableRes: Int, actionName: String ): NotificationCompat.Action { - val intent = Intent(actionName).setPackage(context.packageName) - val pendingIntent = PendingIntentCompat - .getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT, false) - return NotificationCompat.Action.Builder(drawableRes, actionName, pendingIntent).build() + return NotificationCompat.Action.Builder(drawableRes, actionName, createIntent(actionName)) + .build() } private fun createMediaSessionAction( @@ -351,7 +349,7 @@ class NowPlayingNotification( notificationBuilder = NotificationCompat.Builder(context, PLAYER_CHANNEL_ID) .setSmallIcon(R.drawable.ic_launcher_lockscreen) .setContentIntent(createCurrentContentIntent()) - .setDeleteIntent(createDeleteIntent()) + .setDeleteIntent(createIntent(STOP)) .setStyle( MediaStyle() .setMediaSession(mediaSession.sessionToken) From ba2b918ebcf6012e47c4c1b2b5cf8ec9f52b6747 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 7 Sep 2023 19:31:59 +0530 Subject: [PATCH 3/3] refactor: Remove BuildCompat calls --- app/src/main/java/com/github/libretube/extensions/Bundle.kt | 6 ++---- app/src/main/java/com/github/libretube/extensions/Intent.kt | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/github/libretube/extensions/Bundle.kt b/app/src/main/java/com/github/libretube/extensions/Bundle.kt index 776f79c880..52ca984c2d 100644 --- a/app/src/main/java/com/github/libretube/extensions/Bundle.kt +++ b/app/src/main/java/com/github/libretube/extensions/Bundle.kt @@ -1,9 +1,8 @@ package com.github.libretube.extensions +import android.os.Build import android.os.Bundle import android.os.Parcelable -import androidx.annotation.OptIn -import androidx.core.os.BuildCompat import androidx.core.os.BundleCompat import java.io.Serializable @@ -11,9 +10,8 @@ inline fun Bundle.parcelable(key: String?): T? { return BundleCompat.getParcelable(this, key, T::class.java) } -@OptIn(BuildCompat.PrereleaseSdkCheck::class) inline fun Bundle.serializable(key: String): T? { - return if (BuildCompat.isAtLeastU()) { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { getSerializable(key, T::class.java) } else { @Suppress("DEPRECATION") diff --git a/app/src/main/java/com/github/libretube/extensions/Intent.kt b/app/src/main/java/com/github/libretube/extensions/Intent.kt index 5118ada142..b2b3011e81 100644 --- a/app/src/main/java/com/github/libretube/extensions/Intent.kt +++ b/app/src/main/java/com/github/libretube/extensions/Intent.kt @@ -1,19 +1,17 @@ package com.github.libretube.extensions import android.content.Intent +import android.os.Build import android.os.Parcelable -import androidx.annotation.OptIn import androidx.core.content.IntentCompat -import androidx.core.os.BuildCompat import java.io.Serializable inline fun Intent.parcelableExtra(name: String?): T? { return IntentCompat.getParcelableExtra(this, name, T::class.java) } -@OptIn(BuildCompat.PrereleaseSdkCheck::class) inline fun Intent.serializableExtra(name: String?): T? { - return if (BuildCompat.isAtLeastU()) { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { getSerializableExtra(name, T::class.java) } else { @Suppress("DEPRECATION")