Browse Source

Fix notification click

Infinite 3 years ago
parent
commit
ce1c441427

+ 3 - 1
app/src/main/AndroidManifest.xml

@@ -15,7 +15,9 @@
         <activity android:name=".activities.SplashActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
+                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
 
+                <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
@@ -25,7 +27,7 @@
 
         <service
             android:name=".services.NotificationService"
-            android:exported="true">
+            android:exported="false">
             <intent-filter>
                 <action android:name="com.google.firebase.MESSAGING_EVENT" />
             </intent-filter>

+ 7 - 23
app/src/main/java/club/thepenguins/android/services/NotificationService.java

@@ -14,7 +14,7 @@ import com.google.firebase.messaging.FirebaseMessagingService;
 import com.google.firebase.messaging.RemoteMessage;
 
 import club.thepenguins.android.R;
-import club.thepenguins.android.activities.MainActivity;
+import club.thepenguins.android.activities.SplashActivity;
 
 public class NotificationService extends FirebaseMessagingService {
 
@@ -46,10 +46,7 @@ public class NotificationService extends FirebaseMessagingService {
     public void showNotification(String title,
                                  String message) {
         Intent intent
-                = new Intent(this, MainActivity.class);
-        String channel_id = "notification_channel";
-
-        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                = new Intent(this, SplashActivity.class);
 
         PendingIntent pendingIntent
                 = PendingIntent.getActivity(
@@ -59,25 +56,12 @@ public class NotificationService extends FirebaseMessagingService {
 
         NotificationCompat.Builder builder
                 = new NotificationCompat
-                .Builder(getApplicationContext(),
-                channel_id)
+                .Builder(this,
+                "707")
                 .setSmallIcon(R.mipmap.ic_launcher)
-                .setVibrate(new long[]{1000, 1000, 1000,
-                        1000, 1000})
-                .setAutoCancel(true)
-                .setOnlyAlertOnce(true)
-                .setContentIntent(pendingIntent);
-
+                .setContentIntent(pendingIntent)
+                .setContent(getCustomDesign(title, message));
 
-        if (Build.VERSION.SDK_INT
-                >= Build.VERSION_CODES.JELLY_BEAN) {
-            builder = builder.setContent(
-                    getCustomDesign(title, message));
-        } else {
-            builder = builder.setContentTitle(title)
-                    .setContentText(message)
-                    .setSmallIcon(R.drawable.ic_launcher_background);
-        }
 
         NotificationManager notificationManager
                 = (NotificationManager) getSystemService(
@@ -86,7 +70,7 @@ public class NotificationService extends FirebaseMessagingService {
                 >= Build.VERSION_CODES.O) {
             NotificationChannel notificationChannel
                     = new NotificationChannel(
-                    channel_id, "web_app",
+                    "707", "New Posts",
                     NotificationManager.IMPORTANCE_HIGH);
             notificationManager.createNotificationChannel(
                     notificationChannel);

+ 2 - 2
app/src/main/res/values-night-v29/themes.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<resources xmlns:tools="http://schemas.android.com/tools">
+<resources>
 
     <style name="Theme.PenguinsRead" parent="Theme.MaterialComponents.DayNight.NoActionBar">
         <!-- Primary brand color. -->
@@ -7,7 +7,7 @@
         <item name="colorPrimaryVariant">@color/black</item>
         <item name="colorOnPrimary">@color/black</item>
         <!-- Secondary brand color. -->
-        <item name="colorSecondary">@color/white</item>
+        <item name="colorSecondary">@color/colorPrimary</item>
         <item name="colorSecondaryVariant">@color/white</item>
         <item name="colorOnSecondary">@color/colorPrimary</item>
         <item name="drawerArrowStyle">@style/DrawerIconNight</item>

+ 1 - 1
app/src/main/res/values-night/themes.xml

@@ -7,7 +7,7 @@
         <item name="colorPrimaryVariant">@color/black</item>
         <item name="colorOnPrimary">@color/black</item>
         <!-- Secondary brand color. -->
-        <item name="colorSecondary">@color/white</item>
+        <item name="colorSecondary">@color/colorPrimary</item>
         <item name="colorSecondaryVariant">@color/white</item>
         <item name="colorOnSecondary">@color/colorPrimary</item>
         <item name="drawerArrowStyle">@style/DrawerIconNight</item>

+ 1 - 1
app/src/main/res/values-v29/themes.xml

@@ -7,7 +7,7 @@
         <item name="colorPrimaryVariant">@color/black</item>
         <item name="colorOnPrimary">@color/black</item>
         <!-- Secondary brand color. -->
-        <item name="colorSecondary">@color/white</item>
+        <item name="colorSecondary">@color/colorPrimary</item>
         <item name="colorSecondaryVariant">@color/white</item>
         <item name="colorOnSecondary">@color/colorPrimary</item>
         <item name="android:forceDarkAllowed">false</item>

+ 1 - 1
app/src/main/res/values/themes.xml

@@ -7,7 +7,7 @@
         <item name="colorPrimaryVariant">@color/black</item>
         <item name="colorOnPrimary">@color/black</item>
         <!-- Secondary brand color. -->
-        <item name="colorSecondary">@color/white</item>
+        <item name="colorSecondary">@color/colorPrimary</item>
         <item name="colorSecondaryVariant">@color/white</item>
         <item name="colorOnSecondary">@color/colorPrimary</item>
         <item name="drawerArrowStyle">@style/DrawerIconDay</item>