Skip to content

Commit

Permalink
Update notification icon
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyster committed Mar 6, 2020
1 parent 643ccbe commit 4be6f32
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/com/juick/android/service/FCMReceiverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -33,6 +34,7 @@
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

Expand Down Expand Up @@ -121,18 +123,26 @@ public static void showNotification(final String msgStr) {

PendingIntent contentIntent = PendingIntent.getActivity(App.getInstance(),
getId(jmsg), createNewEventIntent(msgStr), PendingIntent.FLAG_UPDATE_CURRENT);
final NotificationCompat.Builder notificationBuilder = Build.VERSION.SDK_INT < 26 ?
new NotificationCompat.Builder(App.getInstance()) :
final NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(App.getInstance(), channelId);
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true).setWhen(0)
.setContentIntent(contentIntent)
.setGroup("messages")
.setColor(App.getInstance().getResources().getColor(R.color.colorAccent))
.setGroupSummary(true);

notificationBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(jmsg.getBody()));
if (jmsg.getUser().getUid() > 0) {
notificationBuilder.addAction(Build.VERSION.SDK_INT <= 19 ?
R.drawable.ic_ab_reply2 : R.drawable.ic_ab_reply,
App.getInstance().getString(R.string.reply), PendingIntent.getActivity(App.getInstance(),
getId(jmsg), createNewEventIntent(msgStr),
PendingIntent.FLAG_UPDATE_CURRENT));
}
handler.post(() -> {
GlideApp.with(App.getInstance()).asBitmap()
.load(jmsg.getUser().getAvatar())
Expand All @@ -147,15 +157,12 @@ public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap>
}
FCMReceiverService.notify(jmsg, notificationBuilder);
}

@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
FCMReceiverService.notify(jmsg, notificationBuilder);
}
});
if (jmsg.getUser().getUid() > 0) {
notificationBuilder.addAction(Build.VERSION.SDK_INT <= 19 ?
R.drawable.ic_ab_reply2 : R.drawable.ic_ab_reply,
App.getInstance().getString(R.string.reply), PendingIntent.getActivity(App.getInstance(),
getId(jmsg), createNewEventIntent(msgStr),
PendingIntent.FLAG_UPDATE_CURRENT));
}
notify(jmsg, notificationBuilder);
});
}
} catch (Exception e) {
Expand Down
Binary file modified src/main/res/drawable-hdpi/ic_notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/drawable-mdpi/ic_notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/drawable-xhdpi/ic_notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/drawable-xxhdpi/ic_notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/res/drawable-xxxhdpi/ic_notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/res/drawable/ic_notification.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#f8f8f8</color>
<color name="colorAccent">#006699</color>
<color name="colorAccent">#3c77aa</color>
<color name="colorSecondary">#fdfdff</color>
<color name="colorText">#222222</color>
<color name="colorPrimaryDark">#888888</color>
Expand Down

0 comments on commit 4be6f32

Please sign in to comment.