complted void message state update.
authorTrillGates <williamtrillgates@gmail.com>
Mon, 5 Apr 2021 10:15:30 +0000 (18:15 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Mon, 5 Apr 2021 10:15:30 +0000 (18:15 +0800)
app/src/main/java/com/enqualcomm/support/provider/FZDDatabaseHelper.java
app/src/main/java/com/enqualcomm/support/provider/FZDMessageProvider.java
app/src/main/java/com/ic/protocols/protocol_fzd.java

index efa59c8..a60554f 100644 (file)
@@ -27,7 +27,8 @@ public class FZDDatabaseHelper extends SQLiteOpenHelper {
     public static final String fUpdateTime = "update_time";
 
     //语音相关的表,字段有:id:ID,content:内容,type:类型,1表示语音,2表示文本,3表示图片
-    //state:状态,0表示未读,1表示已读,in_or_out:1表示来信,2表示发出去的内容,remote_num:对方的手机号码
+    //状态:应用端去处理(0表示未读,1表示已读,2表示未发送)协议处理的地方去修改(3表示发送中,4表示发送失败,5表示发送成功)
+    // in_or_out:1表示来信,2表示发出去的内容,remote_num:对方的手机号码
     //create_time:创建时间,update_time:更新时间
     public static final String tMessage = "message";
     public static final String mId = "_id";
index f81f7f6..300d51f 100644 (file)
@@ -56,7 +56,7 @@ public class FZDMessageProvider extends ContentProvider {
             //处理查询
             SQLiteDatabase readableDatabase = mDatabase.getReadableDatabase();
             return readableDatabase.query(FZDDatabaseHelper.tMessage, projection,
-                    selection, selectionArgs, sortOrder, null, null);
+                    selection, selectionArgs, null, null, sortOrder);
         }
         return null;
     }
@@ -92,13 +92,11 @@ public class FZDMessageProvider extends ContentProvider {
                         //发出通知
                         Objects.requireNonNull(getContext()).getContentResolver().notifyChange(sendNotify, null);
                     }
+                    ICLogger.d("notify item change..." + id);
                     //不管怎么样,都要通知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);
                 return parse;
             }
             return null;
index 46e2cd9..9f9aaa6 100644 (file)
@@ -99,8 +99,6 @@ public class protocol_fzd {
                 //fos.flush();
                 //fos.close();
                 //以上代码,验证成功,说明转换是对的
-                //更新数据库状态
-                //TODO:
                 //发送消息
                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
                 String cmd = cmdMap.get(CMD_TYPE.TK);
@@ -122,11 +120,26 @@ public class protocol_fzd {
                 //追加结尾
                 bos.write(CMDEND.getBytes());
                 mConnection.send(cmd, bos.toByteArray());
+                //更新数据库状态
+                ContentValues contentValues = new ContentValues();
+                contentValues.put("state", 5);
+                mRuntime.getContextProxy().getResolver().update(
+                        Uri.parse(FZDMessageProvider.MESSAGES),
+                        contentValues,
+                        "_id=?",
+                        new String[]{voiceId}
+                );
             } catch (Exception e) {
                 e.printStackTrace();
+                ContentValues contentValues = new ContentValues();
+                contentValues.put("state", 4);
+                mRuntime.getContextProxy().getResolver().update(
+                        Uri.parse(FZDMessageProvider.MESSAGES),
+                        contentValues,
+                        "_id=?",
+                        new String[]{voiceId}
+                );
             }
-            //TODO:
-            //更新状态
         }
     }
 
@@ -410,9 +423,17 @@ public class protocol_fzd {
             ICLogger.d("voice length == > " + bytes.length);
             String cmdStr = new String(bytes);
             String[] split = cmdStr.split(",");
-            ICLogger.d("split[0].length() == > " + split[0].length());
+            int cmdLength = split[0].length();
+            ICLogger.d("split[0].length() == > " + cmdLength);
             if (split[1].length() == 2) {
-                //TODO:更新发送状态
+                //更新发送状态
+                String value = cmdStr.substring(cmdLength, cmdLength + 1);
+                ICLogger.d("value is == > " + cmdLength);
+                if ("1".equals(value)) {
+                    //修改为发送成功
+                    //不知道ID,所以无法修改消息的状态
+                    //所以交互上,调用发送的方法,就当发送了。
+                }
                 return;
             }
             //处理数据