completed notification.
authorTrillGates <williamtrillgates@gmail.com>
Mon, 19 Jul 2021 11:50:41 +0000 (19:50 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Mon, 19 Jul 2021 11:50:41 +0000 (19:50 +0800)
app/src/main/java/com/ic/launcher/MainActivity.java
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

index 8aaf5e9..a30d9e3 100644 (file)
@@ -109,5 +109,4 @@ public class MainActivity extends AppCompatActivity {
         simpleStatusBar.initViewModel(this);
     }
 
-
 }
\ No newline at end of file
index eaa8abd..c7e7e01 100644 (file)
@@ -1,5 +1,6 @@
 package com.ic.launcher;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -88,8 +89,12 @@ public class NotificationActivity extends AppCompatActivity {
         String format = simpleDateFormat.format(date);
         timeTv.setText(format);
         itemView.setTag(category);
+        String type = notificationItem.getType();
+        itemView.setOnClickListener(item -> {
+            handleItemClick(category, notificationItem);
+        });
         //处理头像
-        int iconRes = getIconRes(notificationItem.getType());
+        int iconRes = getIconRes(type);
         leftIconIv.setImageResource(iconRes);
         if (integer == null) {
             itemCategoryCount.put(category, 1);
@@ -115,6 +120,39 @@ public class NotificationActivity extends AppCompatActivity {
         }
     }
 
+    private void handleItemClick(String category, NotificationItem notificationItem) {
+        //判断类型
+        //删除该类型的所有通知
+        Intent intent = new Intent();
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        switch (category) {
+            case CATEGORY_SMS:
+                //跳转到短信详情界面
+                intent.setAction("com.ic.sms.action.DETAIL");
+                intent.putExtra("detailNum", notificationItem.getTitle());
+                break;
+            case CATEGORY_TEMPERATURE:
+            case CATEGORY_BLOOD:
+                //跳转到记录里的体征警告界面
+                intent.setAction("com.ic.action.WARNING_MSG");
+                break;
+            case CATEGORY_PHONE:
+                //跳转到通话记录界面
+                intent.setAction("com.ic.action.PHONE_RECORD");
+                break;
+        }
+        startActivity(intent);
+//        notificationPresenter.removeNotificationByCategory(category);
+        finish();
+    }
+
+
+    public static final String CATEGORY_TEMPERATURE = "com.ic.temperature";
+    public static final String CATEGORY_BLOOD = "com.ic.blood";
+    public static final String CATEGORY_SMS = "com.ic.mms";
+    public static final String CATEGORY_PHONE = "com.ic.phone";
+
+
     public static final String TYPE_SMS = "sms";
     public static final String TYPE_HEART_RATE = "heart_rate";
     public static final String TYPE_BLOOD_PRESSURE = "blood_pressure";
index 45af6ce..168de45 100644 (file)
@@ -26,6 +26,7 @@ import java.util.concurrent.Executors;
 
 import static com.ic.launcher.utils.Constants.NOTIFICATIONS;
 
+
 public class MainPagePresenter extends BasePresenter {
 
     public static final String PATH = "settings";
@@ -65,18 +66,38 @@ public class MainPagePresenter extends BasePresenter {
         updateEnvTemp();
         updateHeartRate();
         observerContent(context);
-        checkNotification();
+        //checkNotification();
+        updateTime(null);
+        //注册广播,监听灭屏和亮屏
+        listenerScreenState();
     }
 
-    private void checkNotification() {
-        Cursor query = mContext.getContentResolver().query(Uri.parse(NOTIFICATIONS),
-                null, null, null, null);
-        if (query != null) {
-            if (query.moveToNext()) {
-                mContext.startActivity(new Intent(mContext, NotificationActivity.class));
-            }
-            query.close();
+    private final BroadcastReceiver mScreenStateReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            //灭屏
+            MainPagePresenter.getInstance(mContext).checkNotification();
         }
+    };
+
+    private void listenerScreenState() {
+        IntentFilter intentFilter = new IntentFilter();
+        intentFilter.addAction(Intent.ACTION_SCREEN_ON);
+        //intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
+        mContext.registerReceiver(mScreenStateReceiver, intentFilter);
+    }
+
+    public void checkNotification() {
+        executor.execute(() -> {
+            Cursor query = mContext.getContentResolver().query(Uri.parse(NOTIFICATIONS),
+                    null, null, null, null);
+            if (query != null) {
+                if (query.moveToNext()) {
+                    mContext.startActivity(new Intent(mContext, NotificationActivity.class));
+                }
+                query.close();
+            }
+        });
     }
 
     private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@@ -145,6 +166,7 @@ public class MainPagePresenter extends BasePresenter {
     @Override
     public void onClean() {
         super.onClean();
+        mContext.unregisterReceiver(mScreenStateReceiver);
         mContext.unregisterReceiver(mIntentReceiver);
     }
 
@@ -193,15 +215,6 @@ public class MainPagePresenter extends BasePresenter {
                         updateEnvTemp();
                     }
                 });
-        //监听警告地方
-        context.getContentResolver().registerContentObserver(Uri.parse(NOTIFICATIONS),
-                true, new ContentObserver(null) {
-                    @Override
-                    public void onChange(boolean selfChange) {
-                        //打开通知列表
-                        mContext.startActivity(new Intent(mContext, NotificationActivity.class));
-                    }
-                });
     }
 
     private void getValueByKey(String key) {
index da3e416..cb805d0 100644 (file)
@@ -72,11 +72,13 @@ public class NotificationPresenter extends BasePresenter {
                     notificationItem.setOrder(order);
                     long date = query.getLong(5);
                     notificationItem.setDate(date);
-                    ICLogger.d("notificationItem == > " + notificationItem.toString());
+                    ICLogger.d("notificationItem == > " +
+                            notificationItem.toString());
                     //设置数据
                     notificationItems.add(notificationItem);
                 }
                 notificationListValue.postValue(notificationItems);
+                //如果数量大于1,就显示通知界面
                 query.close();
             }
         });