From 728989695657af59d8c9e826d5df91ea441b3981 Mon Sep 17 00:00:00 2001 From: andrekir Date: Tue, 22 Oct 2024 12:13:34 -0300 Subject: [PATCH] refactor: remove `largeIcon` from notifications --- .../geeksville/mesh/service/MeshService.kt | 1 - .../mesh/service/MeshServiceNotifications.kt | 26 +------------------ 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 6ae6966ca..3f8f6a299 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -334,7 +334,6 @@ class MeshService : Service(), Logging { // Make sure we aren't using the notification first ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) - serviceNotifications.close() super.onDestroy() serviceJob.cancel() diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt index d603b0a35..961759a53 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt @@ -6,22 +6,18 @@ import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent -import android.graphics.Bitmap import android.graphics.Color import android.media.AudioAttributes import android.media.RingtoneManager import android.os.Build import androidx.annotation.RequiresApi -import androidx.appcompat.content.res.AppCompatResources import androidx.core.app.NotificationCompat -import androidx.core.graphics.drawable.toBitmapOrNull import com.geeksville.mesh.MainActivity import com.geeksville.mesh.R import com.geeksville.mesh.TelemetryProtos.LocalStats import com.geeksville.mesh.android.notificationManager import com.geeksville.mesh.database.entity.NodeEntity import com.geeksville.mesh.util.PendingIntentCompat -import java.io.Closeable import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -29,7 +25,7 @@ import java.util.Locale @Suppress("TooManyFunctions") class MeshServiceNotifications( private val context: Context -) : Closeable { +) { companion object { private const val FIFTEEN_MINUTES_IN_MILLIS = 15L * 60 * 1000 @@ -41,8 +37,6 @@ class MeshServiceNotifications( val notifyId = 101 private val messageNotifyId = 102 - private var largeIcon: Bitmap? = null - @RequiresApi(Build.VERSION_CODES.O) private fun createNotificationChannel(): String { val channelId = "my_service" @@ -193,13 +187,6 @@ class MeshServiceNotifications( ) } - /** - * Generate a bitmap from a vector drawable (even on old builds) - * https://stackoverflow.com/questions/33696488/getting-bitmap-from-vector-drawable/#51742167 - */ - private fun getBitmapFromVectorDrawable(drawableId: Int): Bitmap? = - AppCompatResources.getDrawable(context, drawableId)?.toBitmapOrNull() - private fun commonBuilder(channel: String): NotificationCompat.Builder { val builder = NotificationCompat.Builder(context, channel) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) @@ -211,11 +198,6 @@ class MeshServiceNotifications( // so punt and stay with just the bluetooth icon - see https://meshtastic.discourse.group/t/android-1-1-42-ready-for-alpha-testing/2399/3?u=geeksville builder.setSmallIcon(android.R.drawable.stat_sys_data_bluetooth) } else { - // Newer androids also support a 'large' icon - - // We delay making this bitmap until we know we need it - largeIcon = largeIcon ?: getBitmapFromVectorDrawable(R.mipmap.ic_launcher2) - builder.setSmallIcon( // vector form icons don't work reliably on older androids if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { @@ -224,7 +206,6 @@ class MeshServiceNotifications( R.drawable.app_icon } ) - .setLargeIcon(largeIcon) } return builder } @@ -307,9 +288,4 @@ class MeshServiceNotifications( } return newNodeSeenNotificationBuilder.build() } - - override fun close() { - largeIcon?.recycle() - largeIcon = null - } }