import org.threeten.bp.format.DateTimeFormatter;
import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
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);
}
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;
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;
}
});
}
+
+ 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);
+ }
+ }
}