|
|
|
|
@ -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 {
|
|
|
|
|
// 优先使用TITLE,fallback到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);
|
|
|
|
|
}
|
|
|
|
|
// 优先使用TITLE,fallback到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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|