同意
pull/9/head
pvqf6mep3 3 years ago
commit 4b67b6cfeb

@ -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 {

@ -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");
}
}

@ -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);
}
}

@ -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<SqlData> mDataList;
@ -144,6 +148,7 @@ public class SqlNote {
mOriginParent = 0;
mVersion = 0;
mTop = getmTop();
mStar = getmStar();
mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>();
}
@ -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() {

@ -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);

@ -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
*/

@ -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<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
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());

@ -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

@ -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;
}

@ -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()));

@ -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" />
<ImageView
android:id="@+id/iv_star_icon"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_gravity="top|right"
android:layout_marginRight="20sp" />
</FrameLayout>

@ -30,6 +30,10 @@
android:id="@+id/menu_cancel_top"
android:title="@string/menu_cancel_top"/>
<item
android:id="@+id/menu_set_star"
android:title="@string/menu_set_star"/>
<item
android:id="@+id/menu_delete"
android:title="@string/menu_delete"/>

@ -65,6 +65,8 @@
<string name="menu_remove_remind">删除提醒</string>
<string name="menu_set_top">置顶</string>
<string name="menu_cancel_top">取消置顶</string>
<string name="menu_set_star">星标</string>
<string name="menu_delete_star">删除星标</string>
<string name="menu_title_select_folder">选择文件夹</string>
<string name="menu_move_parent_folder">上一级文件夹</string>
<string name="info_note_enter_desktop">已添加到桌面</string>
@ -80,6 +82,7 @@
<string name="error_note_empty_for_clock">不能为空便签设置闹钟提醒</string>
<string name="error_note_empty_for_top">不能置顶空便签</string>
<string name="error_note_empty_for_send_to_desktop">不能将空便签发送到桌面</string>
<string name="error_delete_star_note">不能删除星标便签</string>
<string name="success_sdcard_export">导出成功</string>
<string name="failed_sdcard_export">导出失败</string>
<string name="format_exported_file_location">已将文本文件(%1$s)输出至SD卡(%2$s)目录</string>

@ -66,6 +66,8 @@
<string name="menu_remove_remind">刪除提醒</string>
<string name="menu_set_top">置顶</string>
<string name="menu_cancel_top">取消置顶</string>
<string name="menu_set_star">星标</string>
<string name="menu_delete_star">删除星标</string>
<string name="menu_title_select_folder">選擇文件夾</string>
<string name="menu_move_parent_folder">上一級文件夾</string>
<string name="info_note_enter_desktop">已添加到桌面</string>
@ -79,6 +81,7 @@
<string name="error_note_empty_for_top">不能置顶空便籤</string>
<string name="error_note_empty_for_clock">不能爲空便籤設置鬧鐘提醒</string>
<string name="error_note_empty_for_send_to_desktop">不能將空便籤發送到桌面</string>
<string name="error_delete_star_note">不能删除星标便签</string>
<string name="success_sdcard_export">導出成功</string>
<string name="failed_sdcard_export">導出失敗</string>
<string name="format_exported_file_location">已將文本文件(%1$s)導出至SD(%2$s)目錄</string>

@ -69,6 +69,8 @@
<string name="menu_remove_remind">Delete reminder</string>
<string name="menu_set_top">Top</string>
<string name="menu_cancel_top">Cancel Top</string>
<string name="menu_set_star">Star</string>
<string name="menu_delete_star">Delete Star</string>
<string name="menu_title_select_folder">Select folder</string>
<string name="menu_move_parent_folder">Parent folder</string>
<string name="info_note_enter_desktop">Note added to home</string>
@ -84,6 +86,7 @@
<string name="error_note_empty_for_clock">Sorry, can not set clock on empty note</string>
<string name="error_note_empty_for_top">Sorry, can not set top on empty note</string>
<string name="error_note_empty_for_send_to_desktop">Sorry, can not send and empty note to home</string>
<string name="error_delete_star_note">Sorry, can not delete star note</string>
<string name="success_sdcard_export">Export successful</string>
<string name="failed_sdcard_export">Export fail</string>
<string name="format_exported_file_location">Export text file (%1$s) to SD (%2$s) directory</string>

Loading…
Cancel
Save