add notification provider.
authorTrillGates <williamtrillgates@gmail.com>
Sat, 17 Jul 2021 03:32:05 +0000 (11:32 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Sat, 17 Jul 2021 03:32:05 +0000 (11:32 +0800)
app/src/main/AndroidManifest.xml
app/src/main/java/com/enqualcomm/support/provider/ICDatabaseHelper.java
app/src/main/java/com/enqualcomm/support/provider/ICMembersProvider.java
app/src/main/java/com/enqualcomm/support/provider/ICNotificationProvider.java [new file with mode: 0644]
app/src/main/java/com/ic/protocols/protocol_s123.java

index 7543e1e..fd6be1a 100644 (file)
             android:authorities="com.ic.web.sms"
             android:exported="true" />
 
+        <provider
+            android:name=".provider.ICNotificationProvider"
+            android:authorities="com.ic.notification"
+            android:exported="true" />
 
     </application>
 
index 97add4b..3a734e8 100644 (file)
@@ -234,6 +234,24 @@ public class ICDatabaseHelper extends SQLiteOpenHelper {
                 " date)";
         ICLogger.d(createWarningMsg);
         db.execSQL(createWarningMsg);
+        //创建通知表
+        String createNotification = "create table " +
+                tb_notification +
+                " (" +
+                notification_id +
+                " integer primary key autoincrement, " +
+                notification_title +
+                " text, " +
+                notification_type +
+                " integer, " +
+                notification_order +
+                " integer, " +
+                notification_date +
+                " date, " +
+                notification_create_time +
+                " date)";
+        ICLogger.d(createNotification);
+        db.execSQL(createNotification);
     }
 
     //闹钟数据库
@@ -247,7 +265,6 @@ public class ICDatabaseHelper extends SQLiteOpenHelper {
     public static final String alarm_name = "name";
     public static final String alarm_later = "alarm_later";
 
-
     //云短信数据库
     public static final String tb_web_sms = "web_sms";
     public static final String web_sms_id = "_id";
@@ -268,8 +285,18 @@ public class ICDatabaseHelper extends SQLiteOpenHelper {
     public static final String warning_msg_create_time = "create_time";
 
 
+    //通知数据库
+    public static final String tb_notification = "notification";
+    public static final String notification_id = "_id";
+    public static final String notification_title = "title";
+    public static final String notification_date = "date";
+    public static final String notification_type = "type";
+    public static final String notification_order = "`order`";
+    public static final String notification_create_time = "create_time";
+
     @Override
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
         //升级数据库
+
     }
 }
index 9093cc0..f3df2a3 100644 (file)
@@ -97,6 +97,9 @@ public class ICMembersProvider extends ContentProvider {
         if (match == MATH_CODE_TABLE) {
             SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
             int delete = writableDatabase.delete(ICDatabaseHelper.tMembers, selection, selectionArgs);
+            if (delete > 0 && getContext() != null) {
+                getContext().getContentResolver().notifyChange(uri, null);
+            }
             return delete;
         }
         return 0;
@@ -111,7 +114,9 @@ public class ICMembersProvider extends ContentProvider {
         if (match == MATH_CODE_TABLE) {
             SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
             int update = writableDatabase.update(ICDatabaseHelper.tMembers, values, selection, selectionArgs);
-            writableDatabase.close();
+            if (update > 0 && getContext() != null) {
+                getContext().getContentResolver().notifyChange(uri, null);
+            }
             return update;
         }
         return 0;
diff --git a/app/src/main/java/com/enqualcomm/support/provider/ICNotificationProvider.java b/app/src/main/java/com/enqualcomm/support/provider/ICNotificationProvider.java
new file mode 100644 (file)
index 0000000..7acdab0
--- /dev/null
@@ -0,0 +1,109 @@
+package com.enqualcomm.support.provider;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+public class ICNotificationProvider extends ContentProvider {
+
+    public static final String PATH = "notification";
+    public static final String AUTHORITY = "com.ic.notification";
+    public static final String MEMBERS = "content://" + AUTHORITY + "/" + PATH;
+
+    private static final int MATH_CODE_TABLE = 1;
+    private static final UriMatcher sUriMatcher;
+
+    static {
+        sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+        sUriMatcher.addURI(AUTHORITY, PATH, MATH_CODE_TABLE);
+    }
+
+    private ICDatabaseHelper mDatabase;
+
+    @Override
+    public boolean onCreate() {
+        mDatabase = new ICDatabaseHelper(getContext());
+        return false;
+    }
+
+    @Nullable
+    @Override
+    public Cursor query(@NonNull Uri uri, @Nullable String[] projection,
+                        @Nullable String selection, @Nullable String[] selectionArgs,
+                        @Nullable String sortOrder) {
+        //匹配规则
+        int match = sUriMatcher.match(uri);
+        SQLiteDatabase readableDatabase = mDatabase.getReadableDatabase();
+        if (match == MATH_CODE_TABLE) {
+            return readableDatabase.query(ICDatabaseHelper.tb_notification,
+                    projection,
+                    selection,
+                    selectionArgs,
+                    null, null, sortOrder);
+        }
+        return null;
+    }
+
+    @Nullable
+    @Override
+    public String getType(@NonNull Uri uri) {
+        return null;
+    }
+
+    @Nullable
+    @Override
+    public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
+        int match = sUriMatcher.match(uri);
+        if (match == MATH_CODE_TABLE) {
+            SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
+            //判断是否有存在吧,确保唯一,删除再添加吧,否则也是添加不进去的
+            writableDatabase.delete(ICDatabaseHelper.tb_notification,
+                    ICDatabaseHelper.notification_id + "=?", new String[]{
+                            values.getAsString(ICDatabaseHelper.notification_id)
+                    });
+            long insert = writableDatabase.insert(ICDatabaseHelper.tb_notification,
+                    null, values);
+            getContext().getContentResolver().notifyChange(uri, null);
+            return Uri.parse(AUTHORITY + "/" + PATH + "/" + insert);
+        }
+        return null;
+    }
+
+    @Override
+    public int delete(@NonNull Uri uri, @Nullable String selection,
+                      @Nullable String[] selectionArgs) {
+        int match = sUriMatcher.match(uri);
+        if (match == MATH_CODE_TABLE) {
+            SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
+            int delete = writableDatabase.delete(ICDatabaseHelper.tb_notification,
+                    selection, selectionArgs);
+            if (delete > 0 && getContext() != null) {
+                getContext().getContentResolver().notifyChange(uri, null);
+            }
+            return delete;
+        }
+        return 0;
+    }
+
+    @Override
+    public int update(@NonNull Uri uri, @Nullable ContentValues values,
+                      @Nullable String selection, @Nullable String[] selectionArgs) {
+        int match = sUriMatcher.match(uri);
+        if (match == MATH_CODE_TABLE) {
+            SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
+            int update = writableDatabase.update(ICDatabaseHelper.tb_notification,
+                    values, selection, selectionArgs);
+            if (update > 0 && getContext() != null) {
+                getContext().getContentResolver().notifyChange(uri, null);
+            }
+            return update;
+        }
+        return 0;
+    }
+
+}
index 6047119..f422817 100644 (file)
@@ -201,7 +201,7 @@ public class protocol_s123 {
     private static HashMap<CMD_TYPE, String> cmdMap;
 
     static {
-        cmdMap = new HashMap<CMD_TYPE, String>();
+        cmdMap = new HashMap<>();
         cmdMap.put(CMD_TYPE.AP00, "AP00");
         cmdMap.put(CMD_TYPE.BP00, "BP00");
         cmdMap.put(CMD_TYPE.AP01, "AP01");