From e20e3914be8804a8db8f065c7d8d2392758c98cc Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Sun, 14 Jan 2018 01:51:39 +0100 Subject: [PATCH] Fix issues with notification Signed-off-by: Mario Danic --- app/build.gradle | 4 ++-- .../application/NextcloudTalkApplication.java | 3 +-- .../firebase/MagicFirebaseMessagingService.java | 16 ++++++++++++---- .../com/nextcloud/talk/utils/ColorUtils.java | 2 -- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c92272a171..8ce90ff9d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { targetSdkVersion 27 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - versionCode 14 - versionName "1.0.5" + versionCode 15 + versionName "1.0.6" // Enabling multidex support. multiDexEnabled true diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java index b7873680c4..6791d3f993 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.java @@ -91,8 +91,7 @@ public static NextcloudTalkApplication getSharedApplication() { //region private methods // Solution inspired by https://stackoverflow.com/questions/34936590/why-isnt-my-vector-drawable-scaling-as-expected private void useCompatVectorIfNeeded() { - int sdkInt = Build.VERSION.SDK_INT; - if (sdkInt == 21 || sdkInt == 22) { + if (Build.VERSION.SDK_INT < 23) { try { @SuppressLint("RestrictedApi") AppCompatDrawableManager drawableManager = AppCompatDrawableManager.get(); Class inflateDelegateClass = Class.forName("android.support.v7.widget.AppCompatDrawableManager$InflateDelegate"); diff --git a/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java b/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java index 3801a50ee9..0f6f014678 100644 --- a/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java +++ b/app/src/main/java/com/nextcloud/talk/services/firebase/MagicFirebaseMessagingService.java @@ -28,10 +28,11 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.drawable.BitmapDrawable; import android.media.RingtoneManager; import android.net.Uri; +import android.os.Build; import android.os.Bundle; -import android.support.v4.app.NotificationCompat; import android.util.Base64; import android.util.Log; @@ -43,6 +44,7 @@ import com.nextcloud.talk.api.models.json.push.DecryptedPushMessage; import com.nextcloud.talk.api.models.json.push.PushMessage; import com.nextcloud.talk.models.SignatureVerification; +import com.nextcloud.talk.utils.ColorUtils; import com.nextcloud.talk.utils.NotificationUtils; import com.nextcloud.talk.utils.PushUtils; import com.nextcloud.talk.utils.bundle.BundleBuilder; @@ -130,11 +132,9 @@ public void onMessageReceived(RemoteMessage remoteMessage) { largeIcon = BitmapFactory.decodeResource(getResources(), smallIcon); CRC32 crc32 = new CRC32(); - - NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) + Notification.Builder notificationBuilder = new Notification.Builder(this) .setLargeIcon(largeIcon) .setSmallIcon(smallIcon) - .setColor(getColor(R.color.colorPrimary)) .setCategory(category) .setPriority(priority) .setWhen(Calendar.getInstance().getTimeInMillis()) @@ -144,6 +144,14 @@ public void onMessageReceived(RemoteMessage remoteMessage) { .setSound(soundUri) .setAutoCancel(true); + if (Build.VERSION.SDK_INT >= 23) { + notificationBuilder.setColor(getResources().getColor(R.color.colorPrimary)); + } else { + BitmapDrawable tintedDrawable = (BitmapDrawable) ColorUtils.getTintedDrawable(getResources(), smallIcon, + R.color.colorPrimary); + notificationBuilder.setLargeIcon(tintedDrawable.getBitmap()); + } + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { String groupName = String.format(getResources().getString(R.string diff --git a/app/src/main/java/com/nextcloud/talk/utils/ColorUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ColorUtils.java index 7e4ab45804..d9483f9137 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ColorUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ColorUtils.java @@ -27,8 +27,6 @@ import android.support.annotation.DrawableRes; public class ColorUtils { - public static String colorSeed = "ballast butte permute doxy graham rummage grateful songbook pledge escapade"; - public static Drawable getTintedDrawable(Resources res, @DrawableRes int drawableResId, @ColorRes int colorResId) { Drawable drawable = res.getDrawable(drawableResId); int color = res.getColor(colorResId);