|
|
|
|
@ -0,0 +1,505 @@
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.AsyncQueryHandler;
|
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
|
import android.content.ContentValues;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.ActionMode;
|
|
|
|
|
import android.view.GestureDetector;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class TodoListActivity extends Activity implements View.OnClickListener {
|
|
|
|
|
// 手势检测相关变量
|
|
|
|
|
private GestureDetector mGestureDetector;
|
|
|
|
|
private static final int SWIPE_MIN_DISTANCE = 120;
|
|
|
|
|
private static final int SWIPE_MAX_OFF_PATH = 250;
|
|
|
|
|
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
|
|
|
|
|
|
|
|
|
|
// 界面元素
|
|
|
|
|
private TextView mNotesTab;
|
|
|
|
|
private TextView mTodoTab;
|
|
|
|
|
private TextView mEmptyHint;
|
|
|
|
|
private ListView mIncompleteList;
|
|
|
|
|
private ListView mCompleteList;
|
|
|
|
|
private View mDivider;
|
|
|
|
|
private LinearLayout mCompleteSection;
|
|
|
|
|
private Button mAddTodoButton;
|
|
|
|
|
|
|
|
|
|
// 数据适配器
|
|
|
|
|
private TodoAdapter mIncompleteAdapter;
|
|
|
|
|
private TodoAdapter mCompleteAdapter;
|
|
|
|
|
|
|
|
|
|
// 数据列表
|
|
|
|
|
private List<TodoItem> mIncompleteItems;
|
|
|
|
|
private List<TodoItem> mCompleteItems;
|
|
|
|
|
|
|
|
|
|
// 内容解析器和异步查询处理器
|
|
|
|
|
private ContentResolver mContentResolver;
|
|
|
|
|
private BackgroundQueryHandler mBackgroundQueryHandler;
|
|
|
|
|
|
|
|
|
|
// 请求码
|
|
|
|
|
private static final int REQUEST_CODE_NEW_TODO = 100;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.todo_list);
|
|
|
|
|
|
|
|
|
|
initResources();
|
|
|
|
|
initGestureDetector();
|
|
|
|
|
initData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onStart() {
|
|
|
|
|
super.onStart();
|
|
|
|
|
startAsyncTodoQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_NEW_TODO) {
|
|
|
|
|
// 刷新代办事项列表
|
|
|
|
|
startAsyncTodoQuery();
|
|
|
|
|
}
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initResources() {
|
|
|
|
|
mContentResolver = getContentResolver();
|
|
|
|
|
mBackgroundQueryHandler = new BackgroundQueryHandler(mContentResolver);
|
|
|
|
|
|
|
|
|
|
// 初始化界面元素
|
|
|
|
|
mEmptyHint = (TextView) findViewById(R.id.todo_empty_hint);
|
|
|
|
|
mIncompleteList = (ListView) findViewById(R.id.todo_incomplete_list);
|
|
|
|
|
mCompleteList = (ListView) findViewById(R.id.todo_complete_list);
|
|
|
|
|
mDivider = findViewById(R.id.todo_divider);
|
|
|
|
|
mCompleteSection = (LinearLayout) findViewById(R.id.todo_complete_section);
|
|
|
|
|
mAddTodoButton = (Button) findViewById(R.id.btn_add_todo);
|
|
|
|
|
|
|
|
|
|
// 初始化界面切换栏
|
|
|
|
|
mNotesTab = (TextView) findViewById(R.id.notes_tab);
|
|
|
|
|
mTodoTab = (TextView) findViewById(R.id.todo_tab);
|
|
|
|
|
|
|
|
|
|
// 设置点击事件
|
|
|
|
|
mNotesTab.setOnClickListener(this);
|
|
|
|
|
mTodoTab.setOnClickListener(this);
|
|
|
|
|
mAddTodoButton.setOnClickListener(this);
|
|
|
|
|
|
|
|
|
|
// 初始化数据适配器
|
|
|
|
|
mIncompleteItems = new ArrayList<>();
|
|
|
|
|
mCompleteItems = new ArrayList<>();
|
|
|
|
|
mIncompleteAdapter = new TodoAdapter(mIncompleteItems, false);
|
|
|
|
|
mCompleteAdapter = new TodoAdapter(mCompleteItems, true);
|
|
|
|
|
mIncompleteList.setAdapter(mIncompleteAdapter);
|
|
|
|
|
mCompleteList.setAdapter(mCompleteAdapter);
|
|
|
|
|
|
|
|
|
|
// 设置列表点击事件
|
|
|
|
|
mIncompleteList.setOnItemClickListener((parent, view, position, id) -> {
|
|
|
|
|
if (mIsMultiSelectMode) {
|
|
|
|
|
// 多选模式下,切换选中状态
|
|
|
|
|
TodoItem item = mIncompleteItems.get(position);
|
|
|
|
|
item.isSelected = !item.isSelected;
|
|
|
|
|
mIncompleteAdapter.notifyDataSetChanged();
|
|
|
|
|
updateSelectedItems();
|
|
|
|
|
} else {
|
|
|
|
|
// 非多选模式下,进入编辑模式
|
|
|
|
|
TodoItem item = mIncompleteItems.get(position);
|
|
|
|
|
Intent intent = new Intent(TodoListActivity.this, TodoEditActivity.class);
|
|
|
|
|
intent.putExtra("todo_id", item.id);
|
|
|
|
|
startActivityForResult(intent, REQUEST_CODE_NEW_TODO);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mCompleteList.setOnItemClickListener((parent, view, position, id) -> {
|
|
|
|
|
if (mIsMultiSelectMode) {
|
|
|
|
|
// 多选模式下,切换选中状态
|
|
|
|
|
TodoItem item = mCompleteItems.get(position);
|
|
|
|
|
item.isSelected = !item.isSelected;
|
|
|
|
|
mCompleteAdapter.notifyDataSetChanged();
|
|
|
|
|
updateSelectedItems();
|
|
|
|
|
} else {
|
|
|
|
|
// 非多选模式下,进入编辑模式
|
|
|
|
|
TodoItem item = mCompleteItems.get(position);
|
|
|
|
|
Intent intent = new Intent(TodoListActivity.this, TodoEditActivity.class);
|
|
|
|
|
intent.putExtra("todo_id", item.id);
|
|
|
|
|
startActivityForResult(intent, REQUEST_CODE_NEW_TODO);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 设置列表长按事件
|
|
|
|
|
mIncompleteList.setOnItemLongClickListener((parent, view, position, id) -> {
|
|
|
|
|
startMultiSelectMode();
|
|
|
|
|
TodoItem item = mIncompleteItems.get(position);
|
|
|
|
|
item.isSelected = true;
|
|
|
|
|
mIncompleteAdapter.notifyDataSetChanged();
|
|
|
|
|
updateSelectedItems();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
mCompleteList.setOnItemLongClickListener((parent, view, position, id) -> {
|
|
|
|
|
startMultiSelectMode();
|
|
|
|
|
TodoItem item = mCompleteItems.get(position);
|
|
|
|
|
item.isSelected = true;
|
|
|
|
|
mCompleteAdapter.notifyDataSetChanged();
|
|
|
|
|
updateSelectedItems();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initGestureDetector() {
|
|
|
|
|
// 初始化手势检测器
|
|
|
|
|
mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
|
|
|
|
try {
|
|
|
|
|
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
|
|
|
|
|
return false;
|
|
|
|
|
// 左滑手势:从代办界面切换回便签界面
|
|
|
|
|
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
|
|
|
|
|
Intent intent = new Intent(TodoListActivity.this, NotesListActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// 异常处理
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 为整个界面添加手势监听
|
|
|
|
|
findViewById(R.id.todo_incomplete_section).setOnTouchListener((v, event) -> mGestureDetector.onTouchEvent(event));
|
|
|
|
|
findViewById(R.id.todo_complete_section).setOnTouchListener((v, event) -> mGestureDetector.onTouchEvent(event));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initData() {
|
|
|
|
|
// 初始化数据,这里可以添加一些示例数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (v.getId() == R.id.notes_tab) {
|
|
|
|
|
// 切换到便签界面
|
|
|
|
|
Intent intent = new Intent(TodoListActivity.this, NotesListActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
|
|
|
|
|
} else if (v.getId() == R.id.todo_tab) {
|
|
|
|
|
// 已经在代办界面,不需要切换
|
|
|
|
|
} else if (v.getId() == R.id.btn_add_todo) {
|
|
|
|
|
// 跳转到新建代办事项界面
|
|
|
|
|
Intent newTodoIntent = new Intent(TodoListActivity.this, TodoEditActivity.class);
|
|
|
|
|
startActivityForResult(newTodoIntent, REQUEST_CODE_NEW_TODO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startAsyncTodoQuery() {
|
|
|
|
|
// 查询未完成的代办事项
|
|
|
|
|
String selection = NoteColumns.TYPE + "=" + Notes.TYPE_TODO + " AND " + NoteColumns.DATA1 + "=" + Notes.TextNote.STATUS_INCOMPLETE;
|
|
|
|
|
mBackgroundQueryHandler.startQuery(0, null, Notes.CONTENT_NOTE_URI,
|
|
|
|
|
new String[]{NoteColumns.ID, NoteColumns.SNIPPET}, selection, null,
|
|
|
|
|
NoteColumns.CREATED_DATE + " ASC");
|
|
|
|
|
|
|
|
|
|
// 查询已完成的代办事项
|
|
|
|
|
selection = NoteColumns.TYPE + "=" + Notes.TYPE_TODO + " AND " + NoteColumns.DATA1 + "=" + Notes.TextNote.STATUS_COMPLETED;
|
|
|
|
|
mBackgroundQueryHandler.startQuery(1, null, Notes.CONTENT_NOTE_URI,
|
|
|
|
|
new String[]{NoteColumns.ID, NoteColumns.SNIPPET}, selection, null,
|
|
|
|
|
NoteColumns.CREATED_DATE + " ASC");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateUI() {
|
|
|
|
|
// 更新未完成列表
|
|
|
|
|
if (mIncompleteItems.isEmpty()) {
|
|
|
|
|
mEmptyHint.setVisibility(View.VISIBLE);
|
|
|
|
|
mIncompleteList.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
mEmptyHint.setVisibility(View.GONE);
|
|
|
|
|
mIncompleteList.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
mIncompleteAdapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
|
|
// 更新已完成列表
|
|
|
|
|
if (mCompleteItems.isEmpty()) {
|
|
|
|
|
mDivider.setVisibility(View.GONE);
|
|
|
|
|
mCompleteSection.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
mDivider.setVisibility(View.VISIBLE);
|
|
|
|
|
mCompleteSection.setVisibility(View.VISIBLE);
|
|
|
|
|
}
|
|
|
|
|
mCompleteAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 代办事项数据类
|
|
|
|
|
private static class TodoItem {
|
|
|
|
|
long id;
|
|
|
|
|
String content;
|
|
|
|
|
boolean isCompleted;
|
|
|
|
|
boolean isSelected;
|
|
|
|
|
|
|
|
|
|
TodoItem(long id, String content, boolean isCompleted) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
this.content = content;
|
|
|
|
|
this.isCompleted = isCompleted;
|
|
|
|
|
this.isSelected = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 多选模式相关变量
|
|
|
|
|
private boolean mIsMultiSelectMode = false;
|
|
|
|
|
private ArrayList<Long> mSelectedIds = new ArrayList<>();
|
|
|
|
|
private ActionMode mActionMode;
|
|
|
|
|
|
|
|
|
|
// 代办事项适配器
|
|
|
|
|
private class TodoAdapter extends BaseAdapter {
|
|
|
|
|
private List<TodoItem> mItems;
|
|
|
|
|
private boolean mIsCompletedSection;
|
|
|
|
|
|
|
|
|
|
TodoAdapter(List<TodoItem> items, boolean isCompletedSection) {
|
|
|
|
|
mItems = items;
|
|
|
|
|
mIsCompletedSection = isCompletedSection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getCount() {
|
|
|
|
|
return mItems.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object getItem(int position) {
|
|
|
|
|
return mItems.get(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long getItemId(int position) {
|
|
|
|
|
return mItems.get(position).id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
|
ViewHolder holder;
|
|
|
|
|
if (convertView == null) {
|
|
|
|
|
convertView = LayoutInflater.from(TodoListActivity.this).inflate(R.layout.todo_item, null);
|
|
|
|
|
holder = new ViewHolder();
|
|
|
|
|
holder.checkbox = convertView.findViewById(R.id.todo_item_checkbox);
|
|
|
|
|
holder.selectbox = convertView.findViewById(R.id.todo_item_selectbox);
|
|
|
|
|
holder.content = convertView.findViewById(R.id.todo_item_content);
|
|
|
|
|
convertView.setTag(holder);
|
|
|
|
|
} else {
|
|
|
|
|
holder = (ViewHolder) convertView.getTag();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TodoItem item = mItems.get(position);
|
|
|
|
|
holder.content.setText(item.content);
|
|
|
|
|
|
|
|
|
|
if (mIsMultiSelectMode) {
|
|
|
|
|
// 多选模式下,显示方框选择框,隐藏圆形选择框
|
|
|
|
|
holder.checkbox.setVisibility(View.GONE);
|
|
|
|
|
holder.selectbox.setVisibility(View.VISIBLE);
|
|
|
|
|
holder.selectbox.setChecked(item.isSelected);
|
|
|
|
|
|
|
|
|
|
// 设置方框选择框点击事件
|
|
|
|
|
holder.selectbox.setTag(item);
|
|
|
|
|
holder.selectbox.setOnClickListener(v -> {
|
|
|
|
|
CheckBox checkBox = (CheckBox) v;
|
|
|
|
|
TodoItem todoItem = (TodoItem) checkBox.getTag();
|
|
|
|
|
todoItem.isSelected = checkBox.isChecked();
|
|
|
|
|
updateSelectedItems();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 非多选模式下,显示圆形选择框,隐藏方框选择框
|
|
|
|
|
holder.checkbox.setVisibility(View.VISIBLE);
|
|
|
|
|
holder.selectbox.setVisibility(View.GONE);
|
|
|
|
|
holder.checkbox.setChecked(item.isCompleted);
|
|
|
|
|
|
|
|
|
|
// 设置文本颜色
|
|
|
|
|
if (item.isCompleted) {
|
|
|
|
|
holder.content.setTextColor(getResources().getColor(android.R.color.darker_gray));
|
|
|
|
|
} else {
|
|
|
|
|
holder.content.setTextColor(getResources().getColor(android.R.color.black));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置圆形选择框点击事件
|
|
|
|
|
holder.checkbox.setTag(item);
|
|
|
|
|
holder.checkbox.setOnClickListener(v -> {
|
|
|
|
|
CheckBox checkBox = (CheckBox) v;
|
|
|
|
|
TodoItem todoItem = (TodoItem) checkBox.getTag();
|
|
|
|
|
todoItem.isCompleted = checkBox.isChecked();
|
|
|
|
|
updateTodoStatus(todoItem);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return convertView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置选中状态
|
|
|
|
|
public void setSelected(int position, boolean selected) {
|
|
|
|
|
if (position >= 0 && position < mItems.size()) {
|
|
|
|
|
mItems.get(position).isSelected = selected;
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取选中的项目
|
|
|
|
|
public ArrayList<Long> getSelectedIds() {
|
|
|
|
|
ArrayList<Long> selectedIds = new ArrayList<>();
|
|
|
|
|
for (TodoItem item : mItems) {
|
|
|
|
|
if (item.isSelected) {
|
|
|
|
|
selectedIds.add(item.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return selectedIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清除所有选中状态
|
|
|
|
|
public void clearSelection() {
|
|
|
|
|
for (TodoItem item : mItems) {
|
|
|
|
|
item.isSelected = false;
|
|
|
|
|
}
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class ViewHolder {
|
|
|
|
|
CheckBox checkbox; // 圆形选择框,用于标记完成状态
|
|
|
|
|
CheckBox selectbox; // 方框选择框,用于多选模式
|
|
|
|
|
TextView content;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新代办事项状态
|
|
|
|
|
private void updateTodoStatus(TodoItem item) {
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
values.put(NoteColumns.DATA1, item.isCompleted ? Notes.TextNote.STATUS_COMPLETED : Notes.TextNote.STATUS_INCOMPLETE);
|
|
|
|
|
values.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
|
|
|
|
|
|
|
|
|
|
mContentResolver.update(Notes.CONTENT_NOTE_URI, values,
|
|
|
|
|
NoteColumns.ID + "=?", new String[]{String.valueOf(item.id)});
|
|
|
|
|
|
|
|
|
|
// 刷新列表
|
|
|
|
|
startAsyncTodoQuery();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 开始多选模式
|
|
|
|
|
private void startMultiSelectMode() {
|
|
|
|
|
if (!mIsMultiSelectMode) {
|
|
|
|
|
mIsMultiSelectMode = true;
|
|
|
|
|
mActionMode = startActionMode(new ActionMode.Callback() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
// 这里使用已有的note_list_options菜单
|
|
|
|
|
getMenuInflater().inflate(R.menu.note_list_options, menu);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
|
if (item.getItemId() == R.id.delete) {
|
|
|
|
|
batchDelete();
|
|
|
|
|
mode.finish();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
|
mIsMultiSelectMode = false;
|
|
|
|
|
mSelectedIds.clear();
|
|
|
|
|
mIncompleteAdapter.clearSelection();
|
|
|
|
|
mCompleteAdapter.clearSelection();
|
|
|
|
|
mActionMode = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新选中的项目
|
|
|
|
|
private void updateSelectedItems() {
|
|
|
|
|
mSelectedIds.clear();
|
|
|
|
|
mSelectedIds.addAll(mIncompleteAdapter.getSelectedIds());
|
|
|
|
|
mSelectedIds.addAll(mCompleteAdapter.getSelectedIds());
|
|
|
|
|
|
|
|
|
|
if (mActionMode != null) {
|
|
|
|
|
if (mSelectedIds.isEmpty()) {
|
|
|
|
|
mActionMode.finish();
|
|
|
|
|
} else {
|
|
|
|
|
// 使用占位符字符串,后续可以在strings.xml中添加
|
|
|
|
|
mActionMode.setTitle("已选择 " + mSelectedIds.size() + " 项");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量删除选中的项目
|
|
|
|
|
private void batchDelete() {
|
|
|
|
|
if (!mSelectedIds.isEmpty()) {
|
|
|
|
|
for (long id : mSelectedIds) {
|
|
|
|
|
mContentResolver.delete(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
NoteColumns.ID + "=?", new String[]{String.valueOf(id)});
|
|
|
|
|
}
|
|
|
|
|
// 刷新列表
|
|
|
|
|
startAsyncTodoQuery();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 异步查询处理器
|
|
|
|
|
private class BackgroundQueryHandler extends AsyncQueryHandler {
|
|
|
|
|
BackgroundQueryHandler(ContentResolver contentResolver) {
|
|
|
|
|
super(contentResolver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
try {
|
|
|
|
|
if (token == 0) {
|
|
|
|
|
// 处理未完成代办事项
|
|
|
|
|
mIncompleteItems.clear();
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
long id = cursor.getLong(0);
|
|
|
|
|
String content = cursor.getString(1);
|
|
|
|
|
mIncompleteItems.add(new TodoItem(id, content, false));
|
|
|
|
|
}
|
|
|
|
|
} else if (token == 1) {
|
|
|
|
|
// 处理已完成代办事项
|
|
|
|
|
mCompleteItems.clear();
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
long id = cursor.getLong(0);
|
|
|
|
|
String content = cursor.getString(1);
|
|
|
|
|
mCompleteItems.add(new TodoItem(id, content, true));
|
|
|
|
|
}
|
|
|
|
|
// 更新UI
|
|
|
|
|
updateUI();
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|