From 13544b513d8846a3f73e4d4706849e40a7a99da6 Mon Sep 17 00:00:00 2001 From: JackyMa <2433069615@qq.com> Date: Tue, 2 Nov 2021 00:29:15 +0800 Subject: [PATCH] StarNote --- src/java/net/micode/notes/data/Notes.java | 2 + .../notes/data/NotesDatabaseHelper.java | 13 +++- .../net/micode/notes/data/NotesProvider.java | 64 ++++++++++++++++++- .../net/micode/notes/gtask/data/SqlNote.java | 14 +++- src/java/net/micode/notes/model/Note.java | 4 ++ .../net/micode/notes/model/WorkingNote.java | 34 +++++++++- src/java/net/micode/notes/tool/DataUtils.java | 17 ++++- .../net/micode/notes/ui/NoteEditActivity.java | 26 +++++++- .../net/micode/notes/ui/NoteItemData.java | 12 ++++ .../net/micode/notes/ui/NotesListItem.java | 8 +++ src/res/layout/note_item.xml | 10 ++- src/res/menu/note_edit.xml | 4 ++ src/res/values-zh-rCN/strings.xml | 3 + src/res/values-zh-rTW/strings.xml | 3 + src/res/values/strings.xml | 3 + 15 files changed, 208 insertions(+), 9 deletions(-) diff --git a/src/java/net/micode/notes/data/Notes.java b/src/java/net/micode/notes/data/Notes.java index 59013366..1db29017 100644 --- a/src/java/net/micode/notes/data/Notes.java +++ b/src/java/net/micode/notes/data/Notes.java @@ -167,6 +167,8 @@ public class Notes { public static final String VERSION = "version"; public static final String TOP = "top"; + + public static final String STAR = "star"; } public interface DataColumns { diff --git a/src/java/net/micode/notes/data/NotesDatabaseHelper.java b/src/java/net/micode/notes/data/NotesDatabaseHelper.java index 1c60af80..f5ce9566 100644 --- a/src/java/net/micode/notes/data/NotesDatabaseHelper.java +++ b/src/java/net/micode/notes/data/NotesDatabaseHelper.java @@ -61,7 +61,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT 1," + NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," + - NoteColumns.TOP + " INTEGER NOT NULL DEFAULT 0" + + NoteColumns.TOP + " INTEGER NOT NULL DEFAULT 0," + + NoteColumns.STAR + " INTEGER NOT NULL DEFAULT 0" + ")"; private static final String CREATE_DATA_TABLE_SQL = @@ -328,6 +329,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { oldVersion++; } + if (oldVersion == 5) { + upgradeToV6(db); + oldVersion++; + } + if (reCreateTriggers) { reCreateNoteTableTriggers(db); reCreateDataTableTriggers(db); @@ -370,4 +376,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.TOP + " INTEGER NOT NULL DEFAULT 0"); } + + private void upgradeToV6(SQLiteDatabase db) { + db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.STAR + + " INTEGER NOT NULL DEFAULT 0"); + } } diff --git a/src/java/net/micode/notes/data/NotesProvider.java b/src/java/net/micode/notes/data/NotesProvider.java index edb0a606..eb70c58d 100644 --- a/src/java/net/micode/notes/data/NotesProvider.java +++ b/src/java/net/micode/notes/data/NotesProvider.java @@ -33,12 +33,13 @@ import net.micode.notes.R; import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.NotesDatabaseHelper.TABLE; +import net.micode.notes.gtask.data.SqlNote; public class NotesProvider extends ContentProvider { private static final UriMatcher mMatcher; - private NotesDatabaseHelper mHelper; + private static NotesDatabaseHelper mHelper; private static final String TAG = "NotesProvider"; @@ -302,4 +303,65 @@ public class NotesProvider extends ContentProvider { return null; } + public static boolean isStarNote(Long id) { + SQLiteDatabase db; + db = mHelper.getReadableDatabase(); + Cursor cursor = null; + cursor = db.query(NotesDatabaseHelper.TABLE.NOTE, null, null, null, null, null, null); + //判断游标是否为空 + if (cursor.moveToFirst()) { + //遍历游标 + for (int index = 1; index < cursor.getCount(); index++) { + cursor.moveToNext(); + if (cursor.getLong(SqlNote.ID_COLUMN) == id && !cursor.getString(SqlNote.STAR_COLUMN).equals("0")) { + cursor.close(); + return true; + } + } + } + cursor.close(); + return false; + } + + public static boolean isStarFolder(long NoteId, long FolderId, boolean setStar){ + if(setStar){ + return true; + } + SQLiteDatabase db; + db = mHelper.getWritableDatabase(); + Cursor cursor = null; + cursor = db.query(NotesDatabaseHelper.TABLE.NOTE, null, null, null, null, null, null); + //判断游标是否为空 + if (cursor.moveToFirst()) { + //遍历游标 + for (int index = 1; index < cursor.getCount(); index++) { + cursor.moveToNext(); + if (cursor.getLong(SqlNote.ID_COLUMN) == NoteId && !setStar){ + continue; + } + if (cursor.getLong(1) == FolderId){ + if (cursor.getString(SqlNote.STAR_COLUMN).equals("1")){ + cursor.close(); + return true; + } + } + } + } + cursor.close(); + return false; + } + + public static void setStarFolder(long FolderId, boolean isStarFolder){ + SQLiteDatabase db; + db = mHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + if(isStarFolder){ + values.put(NoteColumns.STAR,"1"); + } else{ + values.put(NoteColumns.STAR,"0"); + } + String condition = NoteColumns.ID + " = ?"; + String[] args = {String.valueOf(FolderId)}; + db.update(NotesDatabaseHelper.TABLE.NOTE, values, condition, args); + } } diff --git a/src/java/net/micode/notes/gtask/data/SqlNote.java b/src/java/net/micode/notes/gtask/data/SqlNote.java index 5fb6489d..6c8c5e18 100644 --- a/src/java/net/micode/notes/gtask/data/SqlNote.java +++ b/src/java/net/micode/notes/gtask/data/SqlNote.java @@ -49,7 +49,7 @@ public class SqlNote { NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE, NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID, NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID, - NoteColumns.VERSION,NoteColumns.TOP + NoteColumns.VERSION,NoteColumns.TOP,NoteColumns.STAR, }; public static final int ID_COLUMN = 0; @@ -88,6 +88,8 @@ public class SqlNote { public static final int Top_COLUMN = 17; + public static final int STAR_COLUMN = 18; + private Context mContext; private ContentResolver mContentResolver; @@ -122,6 +124,8 @@ public class SqlNote { private String mTop; + private String mStar; + private ContentValues mDiffNoteValues; private ArrayList mDataList; @@ -144,6 +148,7 @@ public class SqlNote { mOriginParent = 0; mVersion = 0; mTop = getmTop(); + mStar = getmStar(); mDiffNoteValues = new ContentValues(); mDataList = new ArrayList(); } @@ -158,6 +163,7 @@ public class SqlNote { loadDataContent(); mDiffNoteValues = new ContentValues(); mTop = getmTop(); + mStar = getmStar(); } public SqlNote(Context context, long id) { @@ -170,12 +176,17 @@ public class SqlNote { loadDataContent(); mDiffNoteValues = new ContentValues(); mTop = getmTop(); + mStar = getmStar(); } public String getmTop(){ return mTop; } + public String getmStar(){ + return mStar; + } + private void loadFromCursor(long id) { Cursor c = null; try { @@ -209,6 +220,7 @@ public class SqlNote { mWidgetType = c.getInt(WIDGET_TYPE_COLUMN); mVersion = c.getLong(VERSION_COLUMN); mTop = c.getString(Top_COLUMN); + mStar = c.getString(STAR_COLUMN); } private void loadDataContent() { diff --git a/src/java/net/micode/notes/model/Note.java b/src/java/net/micode/notes/model/Note.java index 08b99f3f..8bfbfd57 100644 --- a/src/java/net/micode/notes/model/Note.java +++ b/src/java/net/micode/notes/model/Note.java @@ -81,6 +81,10 @@ public class Note { mNoteDiffValues.put(key, value); } + public void setStarValue(String key, String value) { + mNoteDiffValues.put(key, value); + } + public void setTextData(String key, String value) { mNoteData.setTextData(key, value); diff --git a/src/java/net/micode/notes/model/WorkingNote.java b/src/java/net/micode/notes/model/WorkingNote.java index e33dbd74..d886280d 100644 --- a/src/java/net/micode/notes/model/WorkingNote.java +++ b/src/java/net/micode/notes/model/WorkingNote.java @@ -29,6 +29,7 @@ import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.TextNote; +import net.micode.notes.data.NotesProvider; import net.micode.notes.tool.ResourceParser.NoteBgResources; @@ -62,6 +63,8 @@ public class WorkingNote { private String mTop = "0"; + private String mStar = "0"; + private NoteSettingChangedListener mNoteSettingStatusListener; public static final String[] DATA_PROJECTION = new String[] { @@ -81,7 +84,8 @@ public class WorkingNote { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.MODIFIED_DATE, - NoteColumns.TOP + NoteColumns.TOP, + NoteColumns.STAR, }; private static final int DATA_ID_COLUMN = 0; @@ -106,6 +110,8 @@ public class WorkingNote { private static final int NOTE_TOP_COLUMN = 6; + private static final int NOTE_STAR_COLUMN = 7; + // New note construct private WorkingNote(Context context, long folderId) { mContext = context; @@ -118,6 +124,7 @@ public class WorkingNote { mMode = 0; mWidgetType = Notes.TYPE_WIDGET_INVALIDE; mTop = String.valueOf(getTopId()); + mStar = String.valueOf(getStarId()); } // Existing note construct @@ -144,6 +151,7 @@ public class WorkingNote { mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN); mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN); mTop = cursor.getString(NOTE_TOP_COLUMN); + mStar = cursor.getString(NOTE_STAR_COLUMN); } cursor.close(); } else { @@ -248,6 +256,17 @@ public class WorkingNote { } } + public void setStar(String Star){ + if (!mStar.equals(Star)){ + mStar = Star; + mNote.setStarValue(NoteColumns.STAR,mStar); + NotesProvider.setStarFolder(mFolderId, NotesProvider.isStarFolder(mNoteId, mFolderId,Star.equals("1"))); + if (mNoteSettingStatusListener != null) { + mNoteSettingStatusListener.onStarChanged(Star); + } + } + } + public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { @@ -326,6 +345,14 @@ public class WorkingNote { } } + public int getStarId() { + if (mStar.equals("1")) { + return 1; + } else { + return 0; + } + } + public String getContent() { return mContent; } @@ -381,6 +408,11 @@ public class WorkingNote { */ void onTopChanged(String Top); + /** + * Called when user set star + */ + void onStarChanged(String Star); + /** * Called when user set clock */ diff --git a/src/java/net/micode/notes/tool/DataUtils.java b/src/java/net/micode/notes/tool/DataUtils.java index 2a14982e..89fc9a82 100644 --- a/src/java/net/micode/notes/tool/DataUtils.java +++ b/src/java/net/micode/notes/tool/DataUtils.java @@ -16,6 +16,7 @@ package net.micode.notes.tool; +import android.app.Activity; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; import android.content.ContentResolver; @@ -25,14 +26,23 @@ import android.content.OperationApplicationException; import android.database.Cursor; import android.os.RemoteException; import android.util.Log; +import android.database.sqlite.SQLiteDatabase; +import android.widget.Toast; +import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.CallNote; import net.micode.notes.data.Notes.NoteColumns; +import net.micode.notes.data.NotesDatabaseHelper; +import net.micode.notes.data.NotesProvider; +import net.micode.notes.gtask.data.SqlNote; +import net.micode.notes.model.Note; +import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; import java.util.ArrayList; import java.util.HashSet; +import java.util.TreeSet; public class DataUtils { @@ -46,13 +56,18 @@ public class DataUtils { Log.d(TAG, "no id is in the hashset"); return true; } - ArrayList operationList = new ArrayList(); for (long id : ids) { if(id == Notes.ID_ROOT_FOLDER) { Log.e(TAG, "Don't delete system folder root"); continue; } + /** + * if can delete + */ + if (NotesProvider.isStarNote(id)){ + continue; + } ContentProviderOperation.Builder builder = ContentProviderOperation .newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id)); operationList.add(builder.build()); diff --git a/src/java/net/micode/notes/ui/NoteEditActivity.java b/src/java/net/micode/notes/ui/NoteEditActivity.java index 827fcb26..821ddc26 100644 --- a/src/java/net/micode/notes/ui/NoteEditActivity.java +++ b/src/java/net/micode/notes/ui/NoteEditActivity.java @@ -510,6 +510,9 @@ public class NoteEditActivity extends Activity implements OnClickListener, } else if(mWorkingNote.getTopId() == 0){ menu.findItem(R.id.menu_cancel_top).setVisible(false); } + if (mWorkingNote.getStarId() == 1){ + menu.findItem(R.id.menu_set_star).setTitle(R.string.menu_delete_star); + } if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_normal_mode); } else { @@ -531,9 +534,15 @@ public class NoteEditActivity extends Activity implements OnClickListener, break; case R.id.menu_set_top: mWorkingNote.setTop((mWorkingNote.getTopId())==1 ? "0" : "1"); + finish(); break; case R.id.menu_cancel_top: mWorkingNote.setTop((mWorkingNote.getTopId())==0 ? "1" : "0"); + finish(); + break; + case R.id.menu_set_star: + mWorkingNote.setStar(mWorkingNote.getStarId()==1? "0" : "1"); + finish(); break; case R.id.menu_delete: AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -543,10 +552,13 @@ public class NoteEditActivity extends Activity implements OnClickListener, builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { - if(mWorkingNote.getTopId()==0) { + if(mWorkingNote.getStarId()==0) { + System.out.println(mWorkingNote.getStarId()); deleteCurrentNote(); + finish(); + System.out.println(mWorkingNote.getStarId()); } else{ - showToast(R.string.error_note_empty_for_top); + showToast(R.string.error_delete_star_note); } //finish(); } @@ -662,6 +674,16 @@ public class NoteEditActivity extends Activity implements OnClickListener, } } + public void onStarChanged(String Star){ + /** + * User could set clock to an unsaved note, so before setting the + * alert clock, we should save the note first + */ + if (!mWorkingNote.existInDatabase()) { + saveNote(); + } + } + public void onClockAlertChanged(long date, boolean set) { /** * User could set clock to an unsaved note, so before setting the diff --git a/src/java/net/micode/notes/ui/NoteItemData.java b/src/java/net/micode/notes/ui/NoteItemData.java index 1966e95b..a9a90702 100644 --- a/src/java/net/micode/notes/ui/NoteItemData.java +++ b/src/java/net/micode/notes/ui/NoteItemData.java @@ -41,6 +41,7 @@ public class NoteItemData { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.TOP, + NoteColumns.STAR, }; private static final int ID_COLUMN = 0; @@ -56,6 +57,7 @@ public class NoteItemData { private static final int WIDGET_ID_COLUMN = 10; private static final int WIDGET_TYPE_COLUMN = 11; private static final int TOP_ID_COLUMN = 12; + private static final int STAR_ID_COLUMN = 13; private long mId; private long mAlertDate; @@ -72,6 +74,7 @@ public class NoteItemData { private String mName; private String mPhoneNumber; private String mTop; + private String mStar; private boolean mIsLastItem; private boolean mIsFirstItem; @@ -95,6 +98,7 @@ public class NoteItemData { mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); mTop = cursor.getString(TOP_ID_COLUMN); + mStar = cursor.getString(STAR_ID_COLUMN); mPhoneNumber = ""; if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { @@ -146,6 +150,14 @@ public class NoteItemData { } } + public boolean isSTAR() { + if(mStar.equals("0")) { + return false; + }else { + return true; + } + } + public boolean isOneFollowingFolder() { return mIsOneNoteFollowingFolder; } diff --git a/src/java/net/micode/notes/ui/NotesListItem.java b/src/java/net/micode/notes/ui/NotesListItem.java index 56cbcd3c..f4691cb4 100644 --- a/src/java/net/micode/notes/ui/NotesListItem.java +++ b/src/java/net/micode/notes/ui/NotesListItem.java @@ -38,6 +38,7 @@ public class NotesListItem extends LinearLayout { private NoteItemData mItemData; private CheckBox mCheckBox; private ImageView mTop; + private ImageView mStar; public NotesListItem(Context context) { super(context); @@ -48,6 +49,7 @@ public class NotesListItem extends LinearLayout { mCallName = (TextView) findViewById(R.id.tv_name); mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); mTop = (ImageView) findViewById(R.id.iv_top_icon); + mStar =(ImageView) findViewById(R.id.iv_star_icon); } public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { @@ -99,6 +101,12 @@ public class NotesListItem extends LinearLayout { } else{ mTop.setVisibility((View.GONE)); } + if(data.isSTAR()){ + mStar.setImageResource(R.drawable.star); + mStar.setVisibility(View.VISIBLE); + } else{ + mStar.setVisibility(View.GONE); + } } mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); diff --git a/src/res/layout/note_item.xml b/src/res/layout/note_item.xml index 20ca3b5a..d8ad13ad 100644 --- a/src/res/layout/note_item.xml +++ b/src/res/layout/note_item.xml @@ -81,6 +81,12 @@ android:layout_width="17dp" android:layout_height="17dp" android:layout_gravity="top|right" - android:layout_marginRight="@dimen/text_font_size_medium" - /> + android:layout_marginRight="40sp" /> + + diff --git a/src/res/menu/note_edit.xml b/src/res/menu/note_edit.xml index 34ec9970..bc0ae544 100644 --- a/src/res/menu/note_edit.xml +++ b/src/res/menu/note_edit.xml @@ -30,6 +30,10 @@ android:id="@+id/menu_cancel_top" android:title="@string/menu_cancel_top"/> + + diff --git a/src/res/values-zh-rCN/strings.xml b/src/res/values-zh-rCN/strings.xml index 5cc894c6..2b2833ce 100644 --- a/src/res/values-zh-rCN/strings.xml +++ b/src/res/values-zh-rCN/strings.xml @@ -65,6 +65,8 @@ 删除提醒 置顶 取消置顶 + 星标 + 删除星标 选择文件夹 上一级文件夹 已添加到桌面 @@ -80,6 +82,7 @@ 不能为空便签设置闹钟提醒 不能置顶空便签 不能将空便签发送到桌面 + 不能删除星标便签 导出成功 导出失败 已将文本文件(%1$s)输出至SD卡(%2$s)目录 diff --git a/src/res/values-zh-rTW/strings.xml b/src/res/values-zh-rTW/strings.xml index 236bccdf..6cf6b4c4 100644 --- a/src/res/values-zh-rTW/strings.xml +++ b/src/res/values-zh-rTW/strings.xml @@ -66,6 +66,8 @@ 刪除提醒 置顶 取消置顶 + 星标 + 删除星标 選擇文件夾 上一級文件夾 已添加到桌面 @@ -79,6 +81,7 @@ 不能置顶空便籤 不能爲空便籤設置鬧鐘提醒 不能將空便籤發送到桌面 + 不能删除星标便签 導出成功 導出失敗 已將文本文件(%1$s)導出至SD(%2$s)目錄 diff --git a/src/res/values/strings.xml b/src/res/values/strings.xml index 93904896..c8b1e6d9 100644 --- a/src/res/values/strings.xml +++ b/src/res/values/strings.xml @@ -69,6 +69,8 @@ Delete reminder Top Cancel Top + Star + Delete Star Select folder Parent folder Note added to home @@ -84,6 +86,7 @@ Sorry, can not set clock on empty note Sorry, can not set top on empty note Sorry, can not send and empty note to home + Sorry, can not delete star note Export successful Export fail Export text file (%1$s) to SD (%2$s) directory