app: upgrade to android 12

Add preliminary compat for android 12 [API 31]. More changes may be
needed as time goes on, but its close enough to platform stability
to the point where its needed.
This commit is contained in:
OxygenCobalt 2021-07-29 10:49:18 -06:00
parent cd0167405e
commit ec4ca16658
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
3 changed files with 20 additions and 25 deletions

View file

@ -4,7 +4,7 @@ apply plugin: "kotlin-kapt"
apply plugin: "androidx.navigation.safeargs.kotlin"
android {
compileSdkVersion 30
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
@ -13,7 +13,7 @@ android {
versionCode 7
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 31
buildFeatures {
dataBinding true

View file

@ -31,17 +31,11 @@ class PlaybackNotification private constructor(
mediaToken: MediaSessionCompat.Token
) : NotificationCompat.Builder(context, CHANNEL_ID), PlaybackStateManager.Callback {
init {
val mainActivityIntent = PendingIntent.getActivity(
context, REQUEST_CODE,
Intent(context, MainActivity::class.java),
PendingIntent.FLAG_UPDATE_CURRENT
)
setSmallIcon(R.drawable.ic_song)
setCategory(NotificationCompat.CATEGORY_SERVICE)
setShowWhen(false)
setSilent(true)
setContentIntent(mainActivityIntent)
setContentIntent(newPendingIntent(context, Intent(context, MainActivity::class.java)))
setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
addAction(buildLoopAction(context, LoopMode.NONE))
@ -158,15 +152,23 @@ class PlaybackNotification private constructor(
): NotificationCompat.Action {
val action = NotificationCompat.Action.Builder(
iconRes, actionName,
PendingIntent.getBroadcast(
context, REQUEST_CODE,
Intent(actionName), PendingIntent.FLAG_UPDATE_CURRENT,
)
newPendingIntent(context, Intent(actionName))
)
return action.build()
}
private fun newPendingIntent(context: Context, intent: Intent): PendingIntent {
return PendingIntent.getBroadcast(
context, REQUEST_CODE, intent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_IMMUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
)
}
companion object {
const val CHANNEL_ID = "CHANNEL_AUXIO_PLAYBACK"
const val NOTIFICATION_ID = 0xA0A0

View file

@ -5,7 +5,6 @@ import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Point
import android.graphics.drawable.AnimatedVectorDrawable
import android.graphics.drawable.Drawable
import android.os.Build
@ -235,25 +234,19 @@ fun Activity.isIrregularLandscape(): Boolean {
* @return If the system bars are on the bottom, false if no.
*/
private fun isSystemBarOnBottom(activity: Activity): Boolean {
val realPoint = Point()
val metrics = DisplayMetrics()
var width = 0
var height = 0
var width: Int
var height: Int
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.display?.let { display ->
display.getRealSize(realPoint)
activity.windowManager.currentWindowMetrics.bounds.also {
width = it.width()
height = it.height()
}
}
} else {
@Suppress("DEPRECATION")
activity.getSystemServiceSafe(WindowManager::class).apply {
defaultDisplay.getRealSize(realPoint)
defaultDisplay.getMetrics(metrics)
width = metrics.widthPixels