fixed notification toast cover alarm.
authorTrillGates <williamtrillgates@gmail.com>
Tue, 31 Aug 2021 08:29:14 +0000 (16:29 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Tue, 31 Aug 2021 08:29:14 +0000 (16:29 +0800)
app/release/ICLoopPageLauncher_V37_202108272032_release.apk [moved from app/release/ICLoopPageLauncher_V36_202108232006_release.apk with 57% similarity]
app/release/output-metadata.json
app/src/main/AndroidManifest.xml
app/src/main/java/com/ic/launcher/NotificationActivity.java
app/src/main/java/com/ic/launcher/presenter/MainPagePresenter.java
app/src/main/java/com/ic/launcher/presenter/NotificationPresenter.java
app/version_code.properties

similarity index 57%
rename from app/release/ICLoopPageLauncher_V36_202108232006_release.apk
rename to app/release/ICLoopPageLauncher_V37_202108272032_release.apk
index e4ba618..0e14f89 100644 (file)
Binary files a/app/release/ICLoopPageLauncher_V36_202108232006_release.apk and b/app/release/ICLoopPageLauncher_V37_202108272032_release.apk differ
index 7788ef2..8a31a50 100644 (file)
@@ -12,7 +12,7 @@
       "filters": [],
       "versionCode": 1,
       "versionName": "1.0",
-      "outputFile": "ICLoopPageLauncher_V36_202108232006_release.apk"
+      "outputFile": "ICLoopPageLauncher_V37_202108272032_release.apk"
     }
   ]
 }
\ No newline at end of file
index 6ed0195..5856bdc 100644 (file)
@@ -41,6 +41,7 @@
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <action android:name="android.intent.action.VIEW" />
+
                 <category android:name="android.intent.category.HOME" />
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="android.intent.category.MONKEY" />
@@ -49,7 +50,7 @@
         </activity>
         <activity
             android:name=".NotificationActivity"
-            android:launchMode="singleTop"
+            android:launchMode="singleTask"
             android:theme="@style/ICNotification" />
     </application>
 
index 0319ab1..6839ccd 100644 (file)
@@ -125,6 +125,7 @@ public class NotificationActivity extends AppCompatActivity {
         //删除该类型的所有通知
         Intent intent = new Intent();
         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        String title = notificationItem.getTitle();
         switch (category) {
             case CATEGORY_SMS:
                 //跳转到短信详情界面
@@ -135,6 +136,7 @@ public class NotificationActivity extends AppCompatActivity {
             case CATEGORY_BLOOD:
                 //跳转到记录里的体征警告界面
                 intent.setAction("com.ic.action.WARNING_MSG");
+                title = null;
                 break;
             case CATEGORY_PHONE:
                 //跳转到通话记录界面
@@ -142,7 +144,7 @@ public class NotificationActivity extends AppCompatActivity {
                 break;
         }
         startActivity(intent);
-//        notificationPresenter.removeNotificationByCategory(category);
+        notificationPresenter.removeNotificationByCategory(category, title);
         finish();
     }
 
index f7f8bdc..5047a17 100644 (file)
@@ -23,6 +23,7 @@ import org.threeten.bp.ZoneId;
 import org.threeten.bp.format.DateTimeFormatter;
 
 import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -74,14 +75,30 @@ public class MainPagePresenter extends BasePresenter {
     private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
-            //灭屏
-            MainPagePresenter.getInstance(mContext).checkNotification();
+            //如果顶部有闹钟,就不要显示通知UI。
+            String topActivity = getTopActivity();
+            if (!"com.ic.alarm.AlarmRingActivity".equals(topActivity)) {
+                MainPagePresenter.getInstance(mContext).checkNotification();
+            }
         }
     };
 
+    private String getTopActivity() {
+        String className = null;
+        ActivityManager mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+        List<ActivityManager.RunningTaskInfo> list = mActivityManager.getRunningTasks(1);
+        if (!list.isEmpty() && list.get(0) != null && list.get(0).topActivity != null) {
+            className = list.get(0).topActivity.getClassName();
+        }
+        return className;
+    }
+
+    public static final String NOTIFICATION_CHECK = "com.ic.notification.action.CHECK";
+
     private void listenerScreenState() {
         IntentFilter intentFilter = new IntentFilter();
         intentFilter.addAction(Intent.ACTION_SCREEN_ON);
+        intentFilter.addAction(NOTIFICATION_CHECK);
         //intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
         mContext.registerReceiver(mScreenStateReceiver, intentFilter);
     }
index 563980e..f08a3ce 100644 (file)
@@ -1,9 +1,11 @@
 package com.ic.launcher.presenter;
 
 import android.content.ContentResolver;
+import android.content.ContentValues;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
+import android.text.TextUtils;
 
 import androidx.lifecycle.MutableLiveData;
 
@@ -13,10 +15,15 @@ import com.ic.launcher.utils.Constants;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
+import static com.ic.launcher.NotificationActivity.CATEGORY_PHONE;
+import static com.ic.launcher.NotificationActivity.CATEGORY_SMS;
+
 public class NotificationPresenter extends BasePresenter {
     private final Context mContext;
     private final ExecutorService executorService;
@@ -85,4 +92,56 @@ public class NotificationPresenter extends BasePresenter {
             }
         });
     }
+
+    public void removeNotificationByCategory(String category, String title) {
+        executorService.execute(() -> {
+            int delete;
+            if (TextUtils.isEmpty(title)) {
+                delete = contentResolver.delete(Uri.parse(Constants.NOTIFICATIONS),
+                        "category=?",
+                        new String[]{category});
+            } else {
+                delete = contentResolver.delete(Uri.parse(Constants.NOTIFICATIONS),
+                        "category=? and title=?",
+                        new String[]{category, title});
+            }
+            ICLogger.d("deleted == > " + delete);
+        });
+        //根据类型修改顶部的值
+        //如果是短信
+        Map<String, Integer> tempMap = new HashMap<>();
+        List<NotificationItem> value = notificationListValue.getValue();
+        for (int i = 0; i < value.size(); i++) {
+            NotificationItem notificationItem = value.get(i);
+            String itemCategory = notificationItem.getCategory();
+            Integer integer = tempMap.get(itemCategory);
+            if (integer == null) {
+                integer = 0;
+            }
+            integer++;
+            tempMap.put(itemCategory, integer);
+        }
+        Integer smsCount = tempMap.get(CATEGORY_SMS);
+        if (smsCount == null || smsCount <= 1) {
+            //如果短信的个数为0,就清除顶部的通知
+            //删除短信图标
+            //干掉短信未读的记录
+            ContentValues contentValues = new ContentValues();
+            //分类是心率的包名
+            contentValues.put("s_key", "sms_unread");
+            //1表示有,0表示没有
+            contentValues.put("s_value", 0);
+            contentResolver.insert(Uri.parse(Constants.SETTINGS), contentValues);
+        }
+        //删除未接电话的标记
+        Integer phoneCount = tempMap.get(CATEGORY_PHONE);
+        if (phoneCount == null || phoneCount <= 1) {
+            ContentValues contentValues = new ContentValues();
+            //分类是心率的包名
+            contentValues.put("s_key", "has_missed_phone");
+            //1表示有,0表示没有
+            contentValues.put("s_value", 0);
+            contentResolver.insert(Uri.parse(Constants.SETTINGS), contentValues);
+        }
+    }
 }
index 32ccda2..ebc8c89 100644 (file)
@@ -1,2 +1,2 @@
-#Mon Aug 23 20:06:49 CST 2021
-VERSION_CODE=36
+#Fri Aug 27 20:32:00 CST 2021
+VERSION_CODE=37