diff --git a/src/.gradle/5.4.1/executionHistory/executionHistory.lock b/src/.gradle/5.4.1/executionHistory/executionHistory.lock index 0a249ac..fd24591 100644 Binary files a/src/.gradle/5.4.1/executionHistory/executionHistory.lock and b/src/.gradle/5.4.1/executionHistory/executionHistory.lock differ diff --git a/src/.gradle/5.4.1/fileHashes/fileHashes.lock b/src/.gradle/5.4.1/fileHashes/fileHashes.lock index fa80030..6dbc64f 100644 Binary files a/src/.gradle/5.4.1/fileHashes/fileHashes.lock and b/src/.gradle/5.4.1/fileHashes/fileHashes.lock differ diff --git a/src/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/src/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 50764ea..3c602af 100644 Binary files a/src/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/src/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/app/src/main/java/net/micode/notes/model/Note.java b/src/app/src/main/java/net/micode/notes/model/Note.java index d79a353..0aa447d 100644 --- a/src/app/src/main/java/net/micode/notes/model/Note.java +++ b/src/app/src/main/java/net/micode/notes/model/Note.java @@ -200,13 +200,14 @@ public class Note { mCallDataId = id; } - // + //插入通话记录数据 void setCallData(String key, String value) { mCallDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } + //插入文本数据 void setTextData(String key, String value) { mTextDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); @@ -215,7 +216,7 @@ public class Note { Uri pushIntoContentResolver(Context context, long noteId) { /** - * Check for safety + * 防止无效的id */ if (noteId <= 0) { throw new IllegalArgumentException(WRONGNOTEID + noteId); @@ -224,42 +225,57 @@ public class Note { ArrayList operationList = new ArrayList<>(); ContentProviderOperation.Builder builder = null; + //文本内容发生改变 if(mTextDataValues.size() > 0) { mTextDataValues.put(DataColumns.NOTE_ID, noteId); + //如果没有分配id号 if (mTextDataId == 0) { mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mTextDataValues); try { + //尝试分配id setTextDataId(Long.valueOf(uri.getPathSegments().get(1))); } catch (NumberFormatException e) { + //分配失败 Log.e(TAG, "Insert new text data fail with noteId" + noteId); + //清除内容 mTextDataValues.clear(); return null; } } else { + //已经有id号,执行下列操作 builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mTextDataId)); builder.withValues(mTextDataValues); + //加入修改内容 operationList.add(builder.build()); } + //清除已修改 mTextDataValues.clear(); } + //如果数据内容发生改变 if(mCallDataValues.size() > 0) { mCallDataValues.put(DataColumns.NOTE_ID, noteId); + if (mCallDataId == 0) { + //如果没有id号,执行下列操作 mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, mCallDataValues); + //尝试分配id try { setCallDataId(Long.valueOf(uri.getPathSegments().get(1))); } catch (NumberFormatException e) { + //失败,错误信息加入日志 Log.e(TAG, "Insert new call data fail with noteId" + noteId); + //清除已修改内容 mCallDataValues.clear(); return null; } } else { + //有id号,执行下列操作 builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId( Notes.CONTENT_DATA_URI, mCallDataId)); builder.withValues(mCallDataValues); @@ -269,9 +285,12 @@ public class Note { } if (!operationList.isEmpty()) { + //当前操作的便签不空,执行 try { ContentProviderResult[] results = context.getContentResolver().applyBatch( Notes.AUTHORITY, operationList); + //如果res无效,插入失败,返回null值 + //否则返回uri return (results == null || results.length == 0 || results[0] == null) ? null : ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId); } catch (RemoteException|OperationApplicationException e) { diff --git a/src/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/src/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index de47ddb..20f23ff 100644 --- a/src/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -77,7 +77,7 @@ import java.util.regex.Pattern; public class NoteEditActivity extends Activity implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { private class HeadViewHolder { - // + public TextView tvModified; public ImageView ivAlertIcon;