Bug corrections:

- fast switching between tabs crash on getResources
 - closing app while SnackBar was visible crashed
 - changing list name then clicking upper left arrow did not save change
This commit is contained in:
2016-01-13 13:39:45 -05:00
parent 96b054cea1
commit 2c1fad07aa
5 changed files with 34 additions and 11 deletions

View File

@@ -26,7 +26,7 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
implements TaskListTouchHelper.TaskListTouchHelperAdapter {
public interface TaskListRecyclerViewAdapterListener {
void onNameChangeFocus(TaskList taskList);
void onEditTextLoseFocus(TaskList taskList);
void onClickDeleteButton(int position, long id);
void onItemMove(long fromTaskId, long toTaskId, int fromPosition, int toPosition);
void onStartDrag(RecyclerView.ViewHolder viewHolder);
@@ -75,7 +75,7 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
holder.mItem.setName(name);
update(holder.mItem, position);
mListener.onNameChangeFocus(holder.mItem);
mListener.onEditTextLoseFocus(holder.mItem);
}
}
});

View File

@@ -65,11 +65,6 @@ public class TaskDataAccess {
return newTask;
}
public void deleteTask(long taskId) {
database.delete(DatabaseHelper.TASKS_TABLE_NAME,
DatabaseHelper.COLUMN_ID + " = " + taskId, null);
}
public List<Task> getAllTasks(long id) {
List<Task> tasks = new ArrayList<>();
@@ -107,6 +102,14 @@ public class TaskDataAccess {
return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
}
public int deleteTask(long id) {
/*database.delete(DatabaseHelper.TASKS_TABLE_NAME,
DatabaseHelper.COLUMN_ID + " = " + taskId, null);*/
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.TASKS_COLUMN_DELETED, 1);
return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
}
private Task cursorToTask(Cursor cursor) {
Task task = new Task();
task.setId(cursor.getLong(0));

View File

@@ -13,6 +13,7 @@ import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
@@ -84,6 +85,7 @@ public class TaskListsFragment extends Fragment implements
@Override
public void onPause() {
clearFocus();
super.onPause();
taskListDataAccess.close();
}
@@ -91,6 +93,7 @@ public class TaskListsFragment extends Fragment implements
@Override
public void onResume() {
super.onResume();
clearFocus();
taskListDataAccess.open();
}
@@ -102,10 +105,11 @@ public class TaskListsFragment extends Fragment implements
int maxTaskLists = Integer.valueOf(maxTaskListsString);
if (taskListCount >= maxTaskLists) layout.setVisibility(View.GONE);
else layout.setVisibility(View.VISIBLE);
clearFocus();
}
@Override
public void onNameChangeFocus(TaskList taskList) {
public void onEditTextLoseFocus(TaskList taskList) {
taskListDataAccess.updateName(taskList.getId(), taskList.getName());
}
@@ -163,6 +167,18 @@ public class TaskListsFragment extends Fragment implements
toggleVisibleCreateNewTaskListLayout(mView);
}
/** Helper method to clear focus by giving it to the parent layout */
private void clearFocus() {
View view = getView();
if (view != null) {
view.requestFocus();
// Hide keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
public class GetTaskListsTask extends AsyncTask<TaskListDataAccess, Void, List<TaskList>> {
@Override
protected List<TaskList> doInBackground(TaskListDataAccess... params) {

View File

@@ -140,7 +140,8 @@ public class TasksFragment extends Fragment implements
// Update total tasks
int totalTasks = taskRecyclerViewAdapter.getItemCount();
TextView totalTasksView = (TextView) view.findViewById(R.id.total_task_count);
if (totalTasks == 0) totalTasksView.setText(getResources().getText(R.string.task_no_tasks));
// isAdded is to prevent an IllegalStateException when fast switching between tabs
if (totalTasks == 0 && isAdded()) totalTasksView.setText(getResources().getText(R.string.task_no_tasks));
else totalTasksView.setText(String.valueOf(totalTasks + " task" + (totalTasks > 1 ? "s" : "")));
// Update remaining tasks
@@ -161,8 +162,8 @@ public class TasksFragment extends Fragment implements
}
@Override
public void onPause() {
super.onPause();
public void onDestroy() {
super.onDestroy();
taskDataAccess.close();
}

View File

@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/new_task_list_parent_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:descendantFocusability="beforeDescendants"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"