mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
Never ask again is now a checkbox in the confirmation dialog
Next task text on confirmation dialog change New text when there are no tasks in a list Automatically open TaskList Activity when no task lists exist Confirmation on task list delete Code cleanup (new interfaces...)
This commit is contained in:
@@ -63,17 +63,23 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
|||||||
mSectionsPagerAdapter.notifyDataSetChanged();
|
mSectionsPagerAdapter.notifyDataSetChanged();
|
||||||
taskListDataAccess.close();
|
taskListDataAccess.close();
|
||||||
|
|
||||||
// Set up the ViewPager with the sections adapter.
|
if (taskLists.size() == 0) {
|
||||||
mViewPager = (ViewPager) findViewById(R.id.container);
|
Intent intent = new Intent(this, TaskListActivity.class);
|
||||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
// Set up the ViewPager with the sections adapter.
|
||||||
tabLayout.setupWithViewPager(mViewPager);
|
mViewPager = (ViewPager) findViewById(R.id.container);
|
||||||
|
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||||
|
|
||||||
// Hide or show new task floating button
|
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
tabLayout.setupWithViewPager(mViewPager);
|
||||||
if (taskLists.size() == 0) fab.hide();
|
|
||||||
else fab.show();
|
// Hide or show new task floating button
|
||||||
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
|
fab.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package com.wismna.geoffroy.donext.adapters;
|
package com.wismna.geoffroy.donext.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -11,7 +10,6 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.wismna.geoffroy.donext.R;
|
import com.wismna.geoffroy.donext.R;
|
||||||
import com.wismna.geoffroy.donext.dao.TaskList;
|
import com.wismna.geoffroy.donext.dao.TaskList;
|
||||||
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
|
|
||||||
import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
|
import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -25,16 +23,16 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
implements TaskListTouchHelper.TaskListTouchHelperAdapter {
|
implements TaskListTouchHelper.TaskListTouchHelperAdapter {
|
||||||
|
|
||||||
public interface TaskListRecyclerViewAdapterListener {
|
public interface TaskListRecyclerViewAdapterListener {
|
||||||
void notifyOnDeleteButtonClicked();
|
void onNameChangeFocus(TaskList taskList);
|
||||||
|
void onClickDeleteButton(int position, long id);
|
||||||
|
void onItemMove(long fromTaskId, long toTaskId, int fromPosition, int toPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<TaskList> mValues;
|
private final List<TaskList> mValues;
|
||||||
private Context mContext;
|
|
||||||
private TaskListRecyclerViewAdapterListener mListener;
|
private TaskListRecyclerViewAdapterListener mListener;
|
||||||
|
|
||||||
public TaskListRecyclerViewAdapter(List<TaskList> items, Context context, TaskListRecyclerViewAdapterListener listener) {
|
public TaskListRecyclerViewAdapter(List<TaskList> items, TaskListRecyclerViewAdapterListener listener) {
|
||||||
mValues = items;
|
mValues = items;
|
||||||
mContext = context;
|
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,17 +59,13 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
if (!hasFocus && !holder.mItem.getName().matches(name)) {
|
if (!hasFocus && !holder.mItem.getName().matches(name)) {
|
||||||
holder.mItem.setName(name);
|
holder.mItem.setName(name);
|
||||||
|
|
||||||
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(mContext);
|
|
||||||
taskListDataAccess.open();
|
|
||||||
|
|
||||||
update(holder.mItem, position);
|
update(holder.mItem, position);
|
||||||
taskListDataAccess.updateName(holder.mItem.getId(), holder.mItem.getName());
|
mListener.onNameChangeFocus(holder.mItem);
|
||||||
|
|
||||||
taskListDataAccess.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: add confirmation dialog
|
||||||
// Handle click on delete button
|
// Handle click on delete button
|
||||||
holder.mTaskDeleteButton.setOnClickListener(new View.OnClickListener() {
|
holder.mTaskDeleteButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -79,16 +73,8 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
// Disable the OnFocusChanged listener as it is pointless now
|
// Disable the OnFocusChanged listener as it is pointless now
|
||||||
holder.mTaskNameView.setOnFocusChangeListener(null);
|
holder.mTaskNameView.setOnFocusChangeListener(null);
|
||||||
|
|
||||||
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(mContext);
|
//remove(position);
|
||||||
taskListDataAccess.open();
|
mListener.onClickDeleteButton(position, holder.mItem.getId());
|
||||||
|
|
||||||
taskListDataAccess.deleteTaskList(holder.mItem.getId());
|
|
||||||
remove(position);
|
|
||||||
|
|
||||||
taskListDataAccess.close();
|
|
||||||
|
|
||||||
// Notify parent fragment that a task list was deleted
|
|
||||||
mListener.notifyOnDeleteButtonClicked();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -104,8 +90,8 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void remove(int position) {
|
public void remove(int position) {
|
||||||
mValues.remove(position);
|
|
||||||
notifyItemRemoved(position);
|
notifyItemRemoved(position);
|
||||||
|
mValues.remove(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(TaskList item, int position) {
|
public void update(TaskList item, int position) {
|
||||||
@@ -115,8 +101,6 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemMove(int fromPosition, int toPosition) {
|
public boolean onItemMove(int fromPosition, int toPosition) {
|
||||||
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(mContext);
|
|
||||||
taskListDataAccess.open();
|
|
||||||
long fromTaskId = mValues.get(fromPosition).getId();
|
long fromTaskId = mValues.get(fromPosition).getId();
|
||||||
long toTaskId = mValues.get(toPosition).getId();
|
long toTaskId = mValues.get(toPosition).getId();
|
||||||
|
|
||||||
@@ -131,13 +115,8 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
Collections.swap(mValues, i, i - 1);
|
Collections.swap(mValues, i, i - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mListener.onItemMove(fromTaskId, toTaskId, fromPosition, toPosition);
|
||||||
taskListDataAccess.updateOrder(fromTaskId, toPosition);
|
|
||||||
taskListDataAccess.updateOrder(toTaskId, fromPosition);
|
|
||||||
// Update the adapter on the fly
|
|
||||||
notifyItemMoved(fromPosition, toPosition);
|
notifyItemMoved(fromPosition, toPosition);
|
||||||
|
|
||||||
taskListDataAccess.close();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,16 +7,20 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.wismna.geoffroy.donext.R;
|
import com.wismna.geoffroy.donext.R;
|
||||||
|
|
||||||
public class ConfirmDialogFragment extends DialogFragment {
|
public class ConfirmDialogFragment extends DialogFragment {
|
||||||
public interface ConfirmDialogListener {
|
public interface ConfirmDialogListener {
|
||||||
void onConfirmDialogPositiveClick(DialogFragment dialog);
|
void onConfirmDialogClick(DialogFragment dialog, ButtonEvent event);
|
||||||
void onConfirmDialogNeutralClick(DialogFragment dialog);
|
|
||||||
void onConfirmDialogCancel(int position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ButtonEvent{
|
||||||
|
YES,
|
||||||
|
NO
|
||||||
|
}
|
||||||
private ConfirmDialogListener confirmDialogListener;
|
private ConfirmDialogListener confirmDialogListener;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
@@ -32,18 +36,20 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||||||
super.onCancel(dialog);
|
super.onCancel(dialog);
|
||||||
|
|
||||||
// Allows refreshing the first item of the adapter
|
// Allows refreshing the first item of the adapter
|
||||||
Bundle args = getArguments();
|
confirmDialogListener.onConfirmDialogClick(this, ButtonEvent.NO);
|
||||||
confirmDialogListener.onConfirmDialogCancel(args.getInt("ItemPosition"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
builder.setMessage(message)
|
|
||||||
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
|
View view = inflater.inflate(R.layout.fragment_task_confirmation, null);
|
||||||
|
builder.setView(view).setMessage(message)
|
||||||
.setPositiveButton(R.string.task_confirmation_yes_button, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.task_confirmation_yes_button, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
confirmDialogListener.onConfirmDialogPositiveClick(ConfirmDialogFragment.this);
|
confirmDialogListener.onConfirmDialogClick(ConfirmDialogFragment.this, ButtonEvent.YES);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.task_confirmation_no_button, new DialogInterface.OnClickListener() {
|
.setNegativeButton(R.string.task_confirmation_no_button, new DialogInterface.OnClickListener() {
|
||||||
@@ -51,10 +57,6 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||||||
// User cancelled the dialog
|
// User cancelled the dialog
|
||||||
ConfirmDialogFragment.this.getDialog().cancel();
|
ConfirmDialogFragment.this.getDialog().cancel();
|
||||||
}
|
}
|
||||||
}).setNeutralButton(R.string.task_confirmation_never_button, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
confirmDialogListener.onConfirmDialogNeutralClick(ConfirmDialogFragment.this);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@@ -27,7 +28,9 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* A fragment representing a list of Items.
|
* A fragment representing a list of Items.
|
||||||
*/
|
*/
|
||||||
public class TaskListsFragment extends Fragment implements TaskListRecyclerViewAdapter.TaskListRecyclerViewAdapterListener {
|
public class TaskListsFragment extends Fragment implements
|
||||||
|
TaskListRecyclerViewAdapter.TaskListRecyclerViewAdapterListener,
|
||||||
|
ConfirmDialogFragment.ConfirmDialogListener {
|
||||||
private TaskListRecyclerViewAdapter taskListRecyclerViewAdapter;
|
private TaskListRecyclerViewAdapter taskListRecyclerViewAdapter;
|
||||||
private TaskListDataAccess taskListDataAccess;
|
private TaskListDataAccess taskListDataAccess;
|
||||||
private View mView;
|
private View mView;
|
||||||
@@ -64,7 +67,6 @@ public class TaskListsFragment extends Fragment implements TaskListRecyclerViewA
|
|||||||
|
|
||||||
taskListDataAccess.open();
|
taskListDataAccess.open();
|
||||||
TaskList taskList = taskListDataAccess.createTaskList(text, position);
|
TaskList taskList = taskListDataAccess.createTaskList(text, position);
|
||||||
taskListDataAccess.close();
|
|
||||||
taskListRecyclerViewAdapter.add(taskList, position);
|
taskListRecyclerViewAdapter.add(taskList, position);
|
||||||
|
|
||||||
editText.setText("");
|
editText.setText("");
|
||||||
@@ -75,6 +77,18 @@ public class TaskListsFragment extends Fragment implements TaskListRecyclerViewA
|
|||||||
return mView;
|
return mView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
taskListDataAccess.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
taskListDataAccess.open();
|
||||||
|
}
|
||||||
|
|
||||||
private void toggleVisibleCreateNewTaskListLayout(View view) {
|
private void toggleVisibleCreateNewTaskListLayout(View view) {
|
||||||
LinearLayout layout = (LinearLayout) view.findViewById(R.id.new_task_list_layout);
|
LinearLayout layout = (LinearLayout) view.findViewById(R.id.new_task_list_layout);
|
||||||
int taskListCount = taskListRecyclerViewAdapter.getItemCount();
|
int taskListCount = taskListRecyclerViewAdapter.getItemCount();
|
||||||
@@ -86,7 +100,37 @@ public class TaskListsFragment extends Fragment implements TaskListRecyclerViewA
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyOnDeleteButtonClicked() {
|
public void onNameChangeFocus(TaskList taskList) {
|
||||||
|
taskListDataAccess.updateName(taskList.getId(), taskList.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClickDeleteButton(int position, long id) {
|
||||||
|
String title = getResources().getString(R.string.task_list_confirmation_delete);
|
||||||
|
ConfirmDialogFragment confirmDialogFragment =
|
||||||
|
ConfirmDialogFragment.newInstance(title, this);
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putInt("ItemPosition", position);
|
||||||
|
args.putLong("ItemId", id);
|
||||||
|
confirmDialogFragment.setArguments(args);
|
||||||
|
confirmDialogFragment.show(getFragmentManager(), title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemMove(long fromTaskId, long toTaskId, int fromPosition, int toPosition) {
|
||||||
|
taskListDataAccess.updateOrder(fromTaskId, toPosition);
|
||||||
|
taskListDataAccess.updateOrder(toTaskId, fromPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfirmDialogClick(DialogFragment dialog, ConfirmDialogFragment.ButtonEvent event) {
|
||||||
|
if (event == ConfirmDialogFragment.ButtonEvent.NO) return;
|
||||||
|
|
||||||
|
Bundle args = dialog.getArguments();
|
||||||
|
int position = args.getInt("ItemPosition");
|
||||||
|
long id = args.getLong("ItemId");
|
||||||
|
taskListRecyclerViewAdapter.remove(position);
|
||||||
|
taskListDataAccess.deleteTaskList(id);
|
||||||
toggleVisibleCreateNewTaskListLayout(mView);
|
toggleVisibleCreateNewTaskListLayout(mView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +148,7 @@ public class TaskListsFragment extends Fragment implements TaskListRecyclerViewA
|
|||||||
protected void onPostExecute(List<TaskList> taskLists) {
|
protected void onPostExecute(List<TaskList> taskLists) {
|
||||||
super.onPostExecute(taskLists);
|
super.onPostExecute(taskLists);
|
||||||
taskListRecyclerViewAdapter =
|
taskListRecyclerViewAdapter =
|
||||||
new TaskListRecyclerViewAdapter(taskLists, getContext(), TaskListsFragment.this);
|
new TaskListRecyclerViewAdapter(taskLists, TaskListsFragment.this);
|
||||||
|
|
||||||
// Set the adapter
|
// Set the adapter
|
||||||
Context context = mView.getContext();
|
Context context = mView.getContext();
|
||||||
|
@@ -16,6 +16,7 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
@@ -96,8 +97,6 @@ public class TasksFragment extends Fragment implements
|
|||||||
// Set total cycles
|
// Set total cycles
|
||||||
UpdateCycleCount();
|
UpdateCycleCount();
|
||||||
|
|
||||||
taskDataAccess.close();
|
|
||||||
|
|
||||||
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
||||||
ItemTouchHelper.Callback callback = new TaskTouchHelper(this);
|
ItemTouchHelper.Callback callback = new TaskTouchHelper(this);
|
||||||
ItemTouchHelper helper = new ItemTouchHelper(callback);
|
ItemTouchHelper helper = new ItemTouchHelper(callback);
|
||||||
@@ -141,21 +140,36 @@ public class TasksFragment extends Fragment implements
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
taskDataAccess.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
taskDataAccess.open();
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateCycleCount() {
|
private void UpdateCycleCount() {
|
||||||
|
int totalCycles = taskDataAccess.getTotalCycles(taskListId);
|
||||||
|
if (totalCycles == 0) return;
|
||||||
TextView totalCyclesView = (TextView) view.findViewById(R.id.total_task_cycles);
|
TextView totalCyclesView = (TextView) view.findViewById(R.id.total_task_cycles);
|
||||||
totalCyclesView.setText(String.valueOf(taskDataAccess.getTotalCycles(taskListId) + " cycles"));
|
totalCyclesView.setText(String.valueOf(totalCycles + " cycles"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTaskCount() {
|
private void UpdateTaskCount() {
|
||||||
int totalTasks = taskRecyclerViewAdapter.getItemCount();
|
int totalTasks = taskRecyclerViewAdapter.getItemCount();
|
||||||
TextView totalTasksView = (TextView) view.findViewById(R.id.total_task_count);
|
TextView totalTasksView = (TextView) view.findViewById(R.id.total_task_count);
|
||||||
totalTasksView.setText(String.valueOf(totalTasks + " tasks"));
|
if (totalTasks == 0) totalTasksView.setText(getResources().getText(R.string.task_no_tasks));
|
||||||
|
else totalTasksView.setText(String.valueOf(totalTasks + " tasks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateRemainingTaskCount() {
|
private void UpdateRemainingTaskCount() {
|
||||||
TextView remainingTasksView = (TextView) view.findViewById(R.id.remaining_task_count);
|
TextView remainingTasksView = (TextView) view.findViewById(R.id.remaining_task_count);
|
||||||
NoScrollingLayoutManager layoutManager = (NoScrollingLayoutManager) recyclerView.getLayoutManager();
|
NoScrollingLayoutManager layoutManager = (NoScrollingLayoutManager) recyclerView.getLayoutManager();
|
||||||
int remainingTaskCount = taskRecyclerViewAdapter.getItemCount() - layoutManager.findLastCompletelyVisibleItemPosition() - 1;
|
int remainingTaskCount = taskRecyclerViewAdapter.getItemCount() - layoutManager.findLastVisibleItemPosition() - 1;
|
||||||
if (remainingTaskCount == 0)
|
if (remainingTaskCount == 0)
|
||||||
remainingTasksView.setText("");
|
remainingTasksView.setText("");
|
||||||
else
|
else
|
||||||
@@ -219,7 +233,6 @@ public class TasksFragment extends Fragment implements
|
|||||||
// When clicked on undo, do not write to DB
|
// When clicked on undo, do not write to DB
|
||||||
if (event == DISMISS_EVENT_ACTION) return;
|
if (event == DISMISS_EVENT_ACTION) return;
|
||||||
|
|
||||||
taskDataAccess.open();
|
|
||||||
// Commit the changes to DB
|
// Commit the changes to DB
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
@@ -237,7 +250,6 @@ public class TasksFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateCycleCount();
|
UpdateCycleCount();
|
||||||
taskDataAccess.close();
|
|
||||||
|
|
||||||
UpdateTaskCount();
|
UpdateTaskCount();
|
||||||
UpdateRemainingTaskCount();
|
UpdateRemainingTaskCount();
|
||||||
@@ -246,43 +258,38 @@ public class TasksFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfirmDialogPositiveClick(DialogFragment dialog) {
|
public void onConfirmDialogClick(DialogFragment dialog, ConfirmDialogFragment.ButtonEvent event) {
|
||||||
Bundle args = dialog.getArguments();
|
Bundle args = dialog.getArguments();
|
||||||
int itemPosition = args.getInt("ItemPosition");
|
int itemPosition = args.getInt("ItemPosition");
|
||||||
int direction = args.getInt("Direction");
|
int direction = args.getInt("Direction");
|
||||||
|
|
||||||
PerformTaskAction(itemPosition, direction);
|
// Handle never ask again checkbox
|
||||||
}
|
CheckBox neverAskAgainCheckBox = (CheckBox) dialog.getDialog().findViewById(R.id.task_confirmation_never);
|
||||||
|
if (neverAskAgainCheckBox.isChecked()) {
|
||||||
|
|
||||||
@Override
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
public void onConfirmDialogNeutralClick(DialogFragment dialog) {
|
SharedPreferences.Editor editor = sharedPref.edit();
|
||||||
Bundle args = dialog.getArguments();
|
|
||||||
int itemPosition = args.getInt("ItemPosition");
|
|
||||||
int direction = args.getInt("Direction");
|
|
||||||
|
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
// Set system settings
|
||||||
SharedPreferences.Editor editor = sharedPref.edit();
|
switch (direction) {
|
||||||
|
case ItemTouchHelper.LEFT:
|
||||||
// Set system settings
|
editor.putBoolean("pref_conf_done", false);
|
||||||
switch (direction)
|
break;
|
||||||
{
|
case ItemTouchHelper.RIGHT:
|
||||||
case ItemTouchHelper.LEFT:
|
editor.putBoolean("pref_conf_next", false);
|
||||||
editor.putBoolean("pref_conf_done", false);
|
break;
|
||||||
break;
|
case -1:
|
||||||
case ItemTouchHelper.RIGHT:
|
editor.putBoolean("pref_conf_del", false);
|
||||||
editor.putBoolean("pref_conf_next", false);
|
break;
|
||||||
break;
|
}
|
||||||
case -1:
|
editor.apply();
|
||||||
editor.putBoolean("pref_conf_del", false);
|
}
|
||||||
break;
|
if (event == ConfirmDialogFragment.ButtonEvent.YES) {
|
||||||
|
PerformTaskAction(itemPosition, direction);
|
||||||
|
}
|
||||||
|
else if(event == ConfirmDialogFragment.ButtonEvent.NO) {
|
||||||
|
taskRecyclerViewAdapter.notifyItemChanged(itemPosition);
|
||||||
}
|
}
|
||||||
editor.apply();
|
|
||||||
PerformTaskAction(itemPosition, direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfirmDialogCancel(int position) {
|
|
||||||
taskRecyclerViewAdapter.notifyItemChanged(position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -302,15 +309,12 @@ public class TasksFragment extends Fragment implements
|
|||||||
TaskList taskList = (TaskList) listSpinner.getSelectedItem();
|
TaskList taskList = (TaskList) listSpinner.getSelectedItem();
|
||||||
|
|
||||||
// Add the task to the database
|
// Add the task to the database
|
||||||
taskDataAccess.open();
|
|
||||||
Task newTask = taskDataAccess.createOrUpdateTask(id,
|
Task newTask = taskDataAccess.createOrUpdateTask(id,
|
||||||
nameText.getText().toString(),
|
nameText.getText().toString(),
|
||||||
descText.getText().toString(),
|
descText.getText().toString(),
|
||||||
priorityRadio.getText().toString(),
|
priorityRadio.getText().toString(),
|
||||||
taskList.getId());
|
taskList.getId());
|
||||||
|
|
||||||
taskDataAccess.close();
|
|
||||||
|
|
||||||
|
|
||||||
Bundle args = dialog.getArguments();
|
Bundle args = dialog.getArguments();
|
||||||
// Should never happen because we will have to be on this tab to open the dialog
|
// Should never happen because we will have to be on this tab to open the dialog
|
||||||
@@ -373,12 +377,12 @@ public class TasksFragment extends Fragment implements
|
|||||||
{
|
{
|
||||||
// Mark item as Done
|
// Mark item as Done
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT:
|
||||||
title = "Mark task as done?";
|
title = getResources().getString(R.string.task_confirmation_done_text);
|
||||||
showDialog = sharedPref.getBoolean("pref_conf_done", true);
|
showDialog = sharedPref.getBoolean("pref_conf_done", true);
|
||||||
break;
|
break;
|
||||||
// Increase task cycle count
|
// Increase task cycle count
|
||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT:
|
||||||
title = "Go to next task?";
|
title = getResources().getString(R.string.task_confirmation_next_text);
|
||||||
showDialog = sharedPref.getBoolean("pref_conf_next", true);
|
showDialog = sharedPref.getBoolean("pref_conf_next", true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
5
DoNExt/app/src/main/res/drawable/task_select.xml
Normal file
5
DoNExt/app/src/main/res/drawable/task_select.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:drawable="@android:color/darker_gray" android:state_pressed="false" android:state_selected="true" />
|
||||||
|
<item android:drawable="@android:color/white" android:state_selected="false" />
|
||||||
|
</selector>
|
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/task_confirmation_never"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="@string/task_confirmation_never_button" />
|
||||||
|
</LinearLayout>
|
@@ -3,7 +3,8 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/task_select" >
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/total_task_cycles"
|
android:id="@+id/total_task_cycles"
|
||||||
android:layout_width="100dp"
|
android:layout_width="100dp"
|
||||||
@@ -12,10 +13,9 @@
|
|||||||
android:layout_alignParentStart="true"/>
|
android:layout_alignParentStart="true"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/total_task_count"
|
android:id="@+id/total_task_count"
|
||||||
android:layout_width="100dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_centerHorizontal="true" />
|
||||||
android:layout_alignParentEnd="true" />
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/task_list_view"
|
android:id="@+id/task_list_view"
|
||||||
android:name="com.wismna.geoffroy.donext.activities.TaskFragment"
|
android:name="com.wismna.geoffroy.donext.activities.TaskFragment"
|
||||||
|
@@ -12,6 +12,8 @@
|
|||||||
<string name="task_list_new_list_hint">New list name</string>
|
<string name="task_list_new_list_hint">New list name</string>
|
||||||
<string name="task_list_new_list_create">Create</string>
|
<string name="task_list_new_list_create">Create</string>
|
||||||
<string name="task_list_delete">Delete</string>
|
<string name="task_list_delete">Delete</string>
|
||||||
|
<string name="task_list_confirmation_delete">Delete task list?</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Strings related to new task dialog -->
|
<!-- Strings related to new task dialog -->
|
||||||
<string name="new_task_list">List</string>
|
<string name="new_task_list">List</string>
|
||||||
@@ -27,11 +29,11 @@
|
|||||||
|
|
||||||
<!-- Strings related to task details activity -->
|
<!-- Strings related to task details activity -->
|
||||||
<string name="task_details_activity_title">Details</string>
|
<string name="task_details_activity_title">Details</string>
|
||||||
|
<string name="task_no_tasks">Yeah! No more tasks!</string>
|
||||||
|
|
||||||
<!-- Strings related to the confirmation dialog -->
|
<!-- Strings related to the confirmation dialog -->
|
||||||
<string name="task_confirmation_done_text">Mark task as Done?</string>
|
<string name="task_confirmation_done_text">Mark task as Done?</string>
|
||||||
<string name="task_confirmation_next_text">Go to next task?</string>
|
<string name="task_confirmation_next_text">NEXT, do this one later?</string>
|
||||||
<string name="task_confirmation_delete_text">Delete this task?</string>
|
<string name="task_confirmation_delete_text">Delete this task?</string>
|
||||||
<string name="task_confirmation_done_button">Done</string>
|
<string name="task_confirmation_done_button">Done</string>
|
||||||
<string name="task_confirmation_next_button">Next</string>
|
<string name="task_confirmation_next_button">Next</string>
|
||||||
|
Reference in New Issue
Block a user