add message data update notify.
authorTrillGates <williamtrillgates@gmail.com>
Mon, 5 Apr 2021 07:53:51 +0000 (15:53 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Mon, 5 Apr 2021 07:53:51 +0000 (15:53 +0800)
app/src/main/java/com/enqualcomm/support/provider/FZDMessageProvider.java
app/src/main/java/com/ic/protocols/protocol_fzd.java

index 82e25d2..f81f7f6 100644 (file)
@@ -20,6 +20,8 @@ public class FZDMessageProvider extends ContentProvider {
     public static final String AUTHORITY = "com.ic.fzd.we-talk";
     public static final String MESSAGES = "content://" + AUTHORITY + "/" + PATH;
     public static final String MESSAGES_SEND = "content://" + AUTHORITY + ".send" + "/" + PATH;
+    //一个Item添加/更新的时候,可以通过这个来通知UI
+    public static final String MESSAGES_ITEM = "content://" + AUTHORITY + ".item" + "/" + PATH;
 
     private FZDDatabaseHelper mDatabase;
 
@@ -90,6 +92,10 @@ public class FZDMessageProvider extends ContentProvider {
                         //发出通知
                         Objects.requireNonNull(getContext()).getContentResolver().notifyChange(sendNotify, null);
                     }
+                    //不管怎么样,都要通知UI更新的
+                    Uri itemNotify = Uri.parse(MESSAGES_ITEM + "/" + id);
+                    Objects.requireNonNull(getContext()).getContentResolver().notifyChange(itemNotify, null);
+
                 }
                 ICLogger.d("notify other observer..." + parse);
                 Objects.requireNonNull(getContext()).getContentResolver().notifyChange(parse, null);
@@ -120,8 +126,17 @@ public class FZDMessageProvider extends ContentProvider {
         synchronized (mLock) {
             int match = sUriMatcher.match(uri);
             if (match == MATH_CODE_TABLE) {
-                //TODO:通知UI更新
-                //更新数据
+                //如果是状态变化的话通知UI监听的地方
+                //让UI查询一下新的状态
+                if (values != null) {
+                    Integer state = values.getAsInteger("state");
+                    //还要拿到Id
+                    if (getContext() != null &&
+                            state != null && "_id=?".equals(selection) && selectionArgs != null) {
+                        getContext().getContentResolver().notifyChange(
+                                Uri.parse(MESSAGES_ITEM + "/" + selectionArgs[0]), null);
+                    }
+                }
                 SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
                 return writableDatabase.update(FZDDatabaseHelper.tMessage, values, selection, selectionArgs);
             }
index 28661d4..46e2cd9 100644 (file)
@@ -7,7 +7,6 @@ import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
-import android.media.MediaPlayer;
 import android.net.Uri;
 import android.os.Environment;
 import android.os.RemoteCallbackList;
@@ -34,7 +33,6 @@ import com.enqualcomm.support.utils.regexUtil;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -414,7 +412,7 @@ public class protocol_fzd {
             String[] split = cmdStr.split(",");
             ICLogger.d("split[0].length() == > " + split[0].length());
             if (split[1].length() == 2) {
-                //更新发送状态
+                //TODO:更新发送状态
                 return;
             }
             //处理数据
@@ -430,15 +428,15 @@ public class protocol_fzd {
                     "receive_" + System.currentTimeMillis() + ".amr");
             //播放一下吧
             //后面上了UI可以注释掉
-            MediaPlayer mediaPlayer = new MediaPlayer();
-            try {
-                mediaPlayer.setDataSource(amrFilepath);
-                mediaPlayer.prepare();
-                ICLogger.d("playVoice.. ");
-                mediaPlayer.start();
-            } catch (IOException e) {
-                ICLogger.d("playVoice: ERROR ");
-            }
+            //MediaPlayer mediaPlayer = new MediaPlayer();
+            //try {
+            //    mediaPlayer.setDataSource(amrFilepath);
+            //    mediaPlayer.prepare();
+            //    ICLogger.d("playVoice.. ");
+            //    mediaPlayer.start();
+            //} catch (IOException e) {
+            //    ICLogger.d("playVoice: ERROR ");
+            //}
             //包存到数据库中,这是群聊的内容,没有联系人的
             ContentResolver resolver = mRuntime.getContextProxy().getResolver();
             ContentValues contentValues = new ContentValues();
@@ -457,6 +455,8 @@ public class protocol_fzd {
             resolver.insert(Uri.parse(FZDMessageProvider.MESSAGES), contentValues);
             //回复服务器状态
             mConnection.send(TK("1"));
+            //通知有消息到
+            //TODO:
         } catch (Exception e) {
             e.printStackTrace();
             //失败