Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update androidx core #4707

Merged
merged 3 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/src/main/java/com/github/libretube/extensions/Bundle.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
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

inline fun <reified T : Parcelable> Bundle.parcelable(key: String?): T? {
return BundleCompat.getParcelable(this, key, T::class.java)
}

@OptIn(BuildCompat.PrereleaseSdkCheck::class)
inline fun <reified T : Serializable> 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")
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/com/github/libretube/extensions/Intent.kt
Original file line number Diff line number Diff line change
@@ -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 <reified T : Parcelable> Intent.parcelableExtra(name: String?): T? {
return IntentCompat.getParcelableExtra(this, name, T::class.java)
}

@OptIn(BuildCompat.PrereleaseSdkCheck::class)
inline fun <reified T : Serializable> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!!!)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down