修改了title和snippet的逻辑

pull/32/head
包尔俊 3 weeks ago
parent 70197d0faa
commit 1b7d196fe6

BIN
.gitignore vendored

Binary file not shown.

@ -1068,6 +1068,8 @@ public class NotesRepository {
}
ContentValues values = new ContentValues();
// 同时更新 TITLE 和 SNIPPET保持一致性
values.put(NoteColumns.TITLE, newName);
values.put(NoteColumns.SNIPPET, newName);
values.put(NoteColumns.LOCAL_MODIFIED, 1);

@ -433,10 +433,8 @@ public class WorkingNote {
public void setTitle(String title) {
mTitle = title;
mNote.setNoteValue(NoteColumns.TITLE, mTitle);
// 对于文件夹类型,同时设置 snippet 字段以保持兼容性
if (mType == Notes.TYPE_FOLDER) {
mNote.setNoteValue(NoteColumns.SNIPPET, mTitle);
}
// 同步设置SNIPPET字段以保持兼容性
mNote.setNoteValue(NoteColumns.SNIPPET, mTitle);
}
public String getTitle() {

@ -49,12 +49,14 @@ public class FoldersListAdapter extends CursorAdapter {
// 数据库查询投影,指定需要从笔记表中获取的列
public static final String [] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
NoteColumns.SNIPPET,
NoteColumns.TITLE
};
// 列索引常量,用于从查询结果中获取对应列的数据
public static final int ID_COLUMN = 0;
public static final int NAME_COLUMN = 1;
public static final int SNIPPET_COLUMN = 1;
public static final int TITLE_COLUMN = 2;
/**
*
@ -96,9 +98,19 @@ public class FoldersListAdapter extends CursorAdapter {
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof FolderListItem) {
// 如果是根文件夹,显示特殊文本;否则显示文件夹名称
String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
((FolderListItem) view).bind(folderName);
if (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) {
((FolderListItem) view).bind(context.getString(R.string.menu_move_parent_folder));
} else {
// 优先使用TITLEfallback到SNIPPET
String folderName = "";
if (cursor.getColumnCount() > TITLE_COLUMN) {
folderName = cursor.getString(TITLE_COLUMN);
}
if (folderName == null || folderName.trim().isEmpty()) {
folderName = cursor.getString(SNIPPET_COLUMN);
}
((FolderListItem) view).bind(folderName);
}
}
}
@ -111,8 +123,18 @@ public class FoldersListAdapter extends CursorAdapter {
*/
public String getFolderName(Context context, int position) {
Cursor cursor = (Cursor) getItem(position);
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
if (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) {
return context.getString(R.string.menu_move_parent_folder);
}
// 优先使用TITLEfallback到SNIPPET
String folderName = "";
if (cursor.getColumnCount() > TITLE_COLUMN) {
folderName = cursor.getString(TITLE_COLUMN);
}
if (folderName == null || folderName.trim().isEmpty()) {
folderName = cursor.getString(SNIPPET_COLUMN);
}
return folderName;
}
/**

@ -246,7 +246,16 @@ public class FolderListViewModel extends AndroidViewModel {
while (cursor.moveToNext()) {
Map<String, Object> folder = new HashMap<>();
long id = cursor.getLong(cursor.getColumnIndexOrThrow(NoteColumns.ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(NoteColumns.SNIPPET));
// 优先使用TITLEfallback到SNIPPET
String name = "";
int titleIndex = cursor.getColumnIndex(NoteColumns.TITLE);
if (titleIndex != -1) {
name = cursor.getString(titleIndex);
}
if (name == null || name.trim().isEmpty()) {
name = cursor.getString(cursor.getColumnIndexOrThrow(NoteColumns.SNIPPET));
}
// 尝试获取parent_id可能列名不对
int parentIdIndex = cursor.getColumnIndex(NoteColumns.PARENT_ID);
@ -265,6 +274,7 @@ public class FolderListViewModel extends AndroidViewModel {
android.util.Log.d(TAG, "Folder data: id=" + id + ", name=" + name + ", parentId=" + parentId + ", noteCount=" + noteCount);
folder.put(NoteColumns.ID, id);
folder.put(NoteColumns.TITLE, name);
folder.put(NoteColumns.SNIPPET, name);
folder.put(NoteColumns.PARENT_ID, parentId);
folder.put(NoteColumns.NOTES_COUNT, noteCount);

@ -36,12 +36,14 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET
NoteColumns.SNIPPET,
NoteColumns.TITLE
};
public static final int COLUMN_ID = 0;
public static final int COLUMN_BG_COLOR_ID = 1;
public static final int COLUMN_SNIPPET = 2;
public static final int COLUMN_TITLE = 3;
private static final String TAG = "NoteWidgetProvider";
@ -87,7 +89,11 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
c.close();
return;
}
snippet = c.getString(COLUMN_SNIPPET);
// 优先使用TITLEfallback到SNIPPET
snippet = c.getColumnCount() > COLUMN_TITLE ? c.getString(COLUMN_TITLE) : "";
if (snippet == null || snippet.trim().isEmpty()) {
snippet = c.getString(COLUMN_SNIPPET);
}
bgId = c.getInt(COLUMN_BG_COLOR_ID);
intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
intent.setAction(Intent.ACTION_VIEW);

Loading…
Cancel
Save