diff --git a/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java b/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java index c83fb7a..f4b9d1d 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java @@ -92,8 +92,8 @@ public class TaskDataAccess implements AutoCloseable { " LEFT JOIN " + DatabaseHelper.TASKLIST_TABLE_NAME + " ON " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " + DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + - " WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 + - " AND " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + 0 + " WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_DONE + " = 0" + + " AND " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_DELETED + " = 0" , null); List tasks = new ArrayList<>(); @@ -126,8 +126,8 @@ public class TaskDataAccess implements AutoCloseable { public List getTodayTasks() { Cursor cursor = database.query(DatabaseHelper.TASKS_VIEW_TODAY_NAME, taskColumns, - DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 + - " AND " + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + 0, + DatabaseHelper.TASKS_COLUMN_DONE + " = 0" + + " AND " + DatabaseHelper.TASKS_COLUMN_DELETED + " = 0", null, null, null, DatabaseHelper.TASKS_COLUMN_CYCLE + ", " + DatabaseHelper.COLUMN_ID + " DESC"); return getTasksFromCursor(cursor); @@ -142,8 +142,6 @@ public class TaskDataAccess implements AutoCloseable { } public void deleteTask(long id) { - /*database.delete(DatabaseHelper.TASKS_TABLE_NAME, - DatabaseHelper.COLUMN_ID + " = " + taskId, null);*/ update(id, DatabaseHelper.TASKS_COLUMN_DELETED, 1); } diff --git a/app/src/main/java/com/wismna/geoffroy/donext/database/TaskListDataAccess.java b/app/src/main/java/com/wismna/geoffroy/donext/database/TaskListDataAccess.java index 290a1a3..f95792f 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/database/TaskListDataAccess.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/database/TaskListDataAccess.java @@ -61,12 +61,13 @@ public class TaskListDataAccess implements AutoCloseable { } public void deleteTaskList(long id) { - // Delete all related tasks - database.delete(DatabaseHelper.TASKS_TABLE_NAME, DatabaseHelper.TASKS_COLUMN_LIST - + " = " + id, null); - // Delete list - database.delete(DatabaseHelper.TASKLIST_TABLE_NAME, DatabaseHelper.COLUMN_ID + // Mark all tasks as deleted + ContentValues contentValues = new ContentValues(); + contentValues.put(DatabaseHelper.TASKS_COLUMN_DELETED, 1); + database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.TASKS_COLUMN_LIST + " = " + id, null); + // Hide list + update(id, DatabaseHelper.TASKLIST_COLUMN_VISIBLE, 0); } public void updateOrder(long id, int order) { @@ -77,21 +78,10 @@ public class TaskListDataAccess implements AutoCloseable { update(id, DatabaseHelper.TASKLIST_COLUMN_NAME, name); } - public TaskList getTaskListByName(String name) { - Cursor cursor = getTaskListByNameCursor(name); - TaskList taskList = null; - if (cursor.getCount() > 0) { - cursor.moveToFirst(); - taskList = cursorToTaskList(cursor); - cursor.close(); - } - return taskList; - } - - public List getAllTaskLists() { + public List getTaskLists(boolean showInvisible) { List taskLists = new ArrayList<>(); - Cursor cursor = getAllTaskListsCursor(); + Cursor cursor = showInvisible ? getInvisibleTaskListsCursor() : getVisibleTaskListsCursor(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { TaskList taskList = cursorToTaskList(cursor); @@ -113,18 +103,30 @@ public class TaskListDataAccess implements AutoCloseable { database.update(DatabaseHelper.TASKLIST_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null); } - private Cursor getTaskListByNameCursor(String name) { - return database.query(true, DatabaseHelper.TASKLIST_TABLE_NAME, taskListColumns, - DatabaseHelper.TASKLIST_COLUMN_NAME + " = '" + name.replace("'", "''") + "'", null, null, null, null, null); - } - private Cursor getAllTaskListsCursor() { + private Cursor getVisibleTaskListsCursor() { return database.rawQuery("SELECT *," + " (SELECT COUNT(*) " + " FROM " + DatabaseHelper.TASKS_TABLE_NAME + " WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " + DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + ") AS " + DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT + " FROM " + DatabaseHelper.TASKLIST_TABLE_NAME + - " WHERE " + DatabaseHelper.TASKLIST_COLUMN_VISIBLE + " = " + 1 + + " WHERE " + DatabaseHelper.TASKLIST_COLUMN_VISIBLE + " = 1" + + " ORDER BY " + DatabaseHelper.COLUMN_ORDER + " ASC ", + null); + } + + private Cursor getInvisibleTaskListsCursor() { + return database.rawQuery("SELECT *," + + " (SELECT COUNT(*) " + + " FROM " + DatabaseHelper.TASKS_TABLE_NAME + + " WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " + + DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + + " AND (" + DatabaseHelper.TASKS_COLUMN_DELETED + " = 1" + + " OR " + DatabaseHelper.TASKS_COLUMN_DONE + " = 1)" + + ") AS " + DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT + + " FROM " + DatabaseHelper.TASKLIST_TABLE_NAME + + " WHERE " + DatabaseHelper.TASKLIST_COLUMN_VISIBLE + " = 0" + + " OR " + DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT + " > 0" + " ORDER BY " + DatabaseHelper.COLUMN_ORDER + " ASC ", null); } @@ -133,8 +135,6 @@ public class TaskListDataAccess implements AutoCloseable { TaskList taskList = new TaskList(); taskList.setId(cursor.getLong(0)); taskList.setName(cursor.getString(1)); - //taskList.setOrder(cursor.getInt(2)); - //taskList.setVisible(cursor.getInt(3)); // Get "false" count column if it exists if (cursor.getColumnCount() == 5) taskList.setTaskCount(cursor.getLong(4)); diff --git a/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java b/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java index 8123fef..f3af2fc 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java @@ -77,7 +77,6 @@ public abstract class DynamicDialogFragment extends DialogFragment { public void onClick(DialogInterface dialog, int id) { // Send the negative button event back to the host activity // Canceled creation, nothing to do - //dialog.cancel(); onNegativeButtonClick(); } }); @@ -188,7 +187,7 @@ public abstract class DynamicDialogFragment extends DialogFragment { } /** Helper function to get a View, without having to worry about the fact that is a Dialog or not*/ - protected View findViewById(int id) { + protected T findViewById(int id) { if (getShowsDialog()) return getDialog().findViewById(id); return getView().findViewById(id); } diff --git a/app/src/main/java/com/wismna/geoffroy/donext/fragments/MainFragment.java b/app/src/main/java/com/wismna/geoffroy/donext/fragments/MainFragment.java index a4ed6c1..5e16d96 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/fragments/MainFragment.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/fragments/MainFragment.java @@ -22,6 +22,7 @@ import android.widget.ArrayAdapter; import android.widget.ListView; import com.wismna.geoffroy.donext.R; +import com.wismna.geoffroy.donext.activities.HistoryActivity; import com.wismna.geoffroy.donext.adapters.SectionsPagerAdapter; import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter; import com.wismna.geoffroy.donext.dao.Task; @@ -100,12 +101,12 @@ public class MainFragment extends Fragment implements updateTaskLists(activity); } - private void updateTaskLists(AppCompatActivity activity) - { + private void updateTaskLists(AppCompatActivity activity) { + boolean isHistoryActivity = activity instanceof HistoryActivity; // Access database to retrieve Tabs List taskLists; try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(activity)) { - taskLists = taskListDataAccess.getAllTaskLists(); + taskLists = taskListDataAccess.getTaskLists(isHistoryActivity); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. @@ -138,7 +139,7 @@ public class MainFragment extends Fragment implements tabLayout = mView.findViewById(R.id.tabs); // Hide the tabs if there is only one task list - tabLayout.setVisibility(taskLists.size() == 1 ? View.GONE : View.VISIBLE); + tabLayout.setVisibility(taskLists.size() == 1 && !isHistoryActivity ? View.GONE : View.VISIBLE); tabLayout.setupWithViewPager(mViewPager); // Handles scroll detection (only available for SDK version >=23) @@ -156,7 +157,7 @@ public class MainFragment extends Fragment implements else { ListView listView = mView.findViewById(R.id.list); // Hide the list if there is only one task list - listView.setVisibility(taskLists.size() == 1 ? View.GONE : View.VISIBLE); + listView.setVisibility(taskLists.size() == 1 && !isHistoryActivity ? View.GONE : View.VISIBLE); //listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskLists)); listView.setAdapter(new ArrayAdapter<>(activity, R.layout.list_tasklist_item, taskLists)); //listView.setSelection(lastOpenedList); diff --git a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java index 12fd63e..489437a 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java @@ -1,5 +1,6 @@ package com.wismna.geoffroy.donext.fragments; +import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; @@ -14,8 +15,10 @@ import android.widget.Spinner; import android.widget.TextView; import com.wismna.geoffroy.donext.R; +import com.wismna.geoffroy.donext.activities.HistoryActivity; import com.wismna.geoffroy.donext.dao.Task; import com.wismna.geoffroy.donext.dao.TaskList; +import com.wismna.geoffroy.donext.widgets.InterceptTouchRelativeLayout; import org.joda.time.LocalDate; @@ -67,7 +70,14 @@ public class TaskFormDialogFragment extends DynamicDialogFragment { super.onStart(); // Set Task Form specific information at that point because we are sure that the view is // entirely inflated (with the content fragment) - setTaskValues(); + Activity activity = getActivity(); + assert activity != null; + if (activity instanceof HistoryActivity) { + InterceptTouchRelativeLayout layout = findViewById(R.id.new_task_layout); + layout.setInterceptTouchEvents(true); + } + + setTaskValues(activity); } @Override @@ -94,12 +104,12 @@ public class TaskFormDialogFragment extends DynamicDialogFragment { dismiss(); } - private void setTaskValues() { + private void setTaskValues(Activity activity) { // Populate spinner with task lists - Spinner spinner = (Spinner) findViewById(R.id.new_task_list); + Spinner spinner = findViewById(R.id.new_task_list); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter adapter = new ArrayAdapter<>( - getActivity(), android.R.layout.simple_spinner_item, taskLists); + activity, android.R.layout.simple_spinner_item, taskLists); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); @@ -110,16 +120,16 @@ public class TaskFormDialogFragment extends DynamicDialogFragment { int id = args.getInt("list"); spinner.setSelection(id); - CheckBox checkBox = (CheckBox) findViewById(R.id.new_task_today); - TextView todayLabel = (TextView) findViewById(R.id.new_task_today_label); + CheckBox checkBox = findViewById(R.id.new_task_today); + TextView todayLabel = findViewById(R.id.new_task_today_label); boolean isTodayActive = args.getBoolean("today"); checkBox.setVisibility(isTodayActive ? View.VISIBLE : View.GONE); todayLabel.setVisibility(isTodayActive ? View.VISIBLE : View.GONE); // Get date picker - final DatePicker dueDatePicker = (DatePicker) findViewById(R.id.new_task_due_date); + final DatePicker dueDatePicker = findViewById(R.id.new_task_due_date); // Handle due date spinner depending on check box - CheckBox setDueDate = (CheckBox) findViewById(R.id.new_task_due_date_set); + CheckBox setDueDate = findViewById(R.id.new_task_due_date_set); setDueDate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -128,8 +138,8 @@ public class TaskFormDialogFragment extends DynamicDialogFragment { }); // Handle priority changes - final TextView tooltip = (TextView) findViewById(R.id.new_task_priority_tooltip); - SeekBar seekBar = (SeekBar) findViewById(R.id.new_task_priority); + final TextView tooltip = findViewById(R.id.new_task_priority_tooltip); + SeekBar seekBar = findViewById(R.id.new_task_priority); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { @@ -150,9 +160,9 @@ public class TaskFormDialogFragment extends DynamicDialogFragment { // Set other properties if they exist if (task != null) { - EditText titleText = (EditText) findViewById(R.id.new_task_name); + EditText titleText = findViewById(R.id.new_task_name); titleText.setText(task.getName()); - EditText descText = (EditText) findViewById(R.id.new_task_description); + EditText descText = findViewById(R.id.new_task_description); descText.setText(task.getDescription()); seekBar.setProgress(task.getPriority()); diff --git a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsDialogFragment.java b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsDialogFragment.java index 349cfe4..e138807 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsDialogFragment.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsDialogFragment.java @@ -73,11 +73,11 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements @Override public void onStart() { super.onStart(); - Button createTaskListButton = (Button) findViewById(R.id.new_task_list_button); + Button createTaskListButton = findViewById(R.id.new_task_list_button); createTaskListButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - EditText editText = (EditText) findViewById(R.id.new_task_list_name); + EditText editText = findViewById(R.id.new_task_list_name); String text = editText.getText().toString(); if (text.matches("")) { editText.setError(getResources().getString(R.string.task_list_new_list_error)); @@ -126,7 +126,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements } private void toggleVisibleCreateNewTaskListLayout() { - LinearLayout layout = (LinearLayout) findViewById(R.id.new_task_list_layout); + LinearLayout layout = findViewById(R.id.new_task_list_layout); int taskListCount = taskListRecyclerViewAdapter.getItemCount(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "5"); @@ -220,7 +220,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements @Override protected List doInBackground(TaskListDataAccess... params) { TaskListDataAccess taskListDataAccess = params[0]; - return taskListDataAccess.getAllTaskLists(); + return taskListDataAccess.getTaskLists(false); } @Override @@ -233,7 +233,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements // Set the adapter Context context = fragment.getContext(); - RecyclerView recyclerView = (RecyclerView) fragment.findViewById(R.id.task_lists_view); + RecyclerView recyclerView = fragment.findViewById(R.id.task_lists_view); recyclerView.setLayoutManager(new LinearLayoutManager(context)); recyclerView.setAdapter(fragment.taskListRecyclerViewAdapter); diff --git a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java index ebc7918..f258dc1 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java @@ -89,12 +89,11 @@ public class TasksFragment extends Fragment implements if (getArguments() != null) { taskListId = getArguments().getLong(TASK_LIST_ID); - Activity parentActivity = getActivity(); - if (parentActivity instanceof HistoryActivity) isHistory = true; - if (parentActivity instanceof TodayActivity) isTodayView = true; - // TODO: this does not work! No tasks are shown - mAdapter = (MainFragment)getParentFragment(); } + Activity parentActivity = getActivity(); + if (parentActivity instanceof HistoryActivity) isHistory = true; + if (parentActivity instanceof TodayActivity) isTodayView = true; + mAdapter = (MainFragment)getParentFragment(); } @Override @@ -118,7 +117,6 @@ public class TasksFragment extends Fragment implements } recyclerView.setAdapter(taskRecyclerViewAdapter); - // TODO: check that this works if (!isHistory) { // Set ItemTouch helper in RecyclerView to handle swipe move on elements ItemTouchHelper.Callback callback = new TaskTouchHelper(this, @@ -156,7 +154,7 @@ public class TasksFragment extends Fragment implements } else { try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(getActivity())) { - taskLists = taskListDataAccess.getAllTaskLists(); + taskLists = taskListDataAccess.getTaskLists(isHistory); } for (TaskList taskList : taskLists) { @@ -173,7 +171,7 @@ public class TasksFragment extends Fragment implements taskDialogFragment.setArguments(args); // Open the fragment as a dialog or as full-screen depending on screen size - String title = getString(R.string.action_edit_task); + String title = getString(isHistory ? R.string.action_view_task : R.string.action_edit_task); assert manager != null; taskDialogFragment.showFragment(manager, title, isLargeLayout); } @@ -219,7 +217,6 @@ public class TasksFragment extends Fragment implements if (remainingTaskCount == 0) remainingTasksView.setText(""); else remainingTasksView.setText(resources.getQuantityString(R.plurals.task_remaining, remainingTaskCount, remainingTaskCount)); - //recyclerView.getViewTreeObserver().removeOnPreDrawListener(this); return true; } }); diff --git a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormDialogFragment.java b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormDialogFragment.java index 4743652..ae11dc2 100644 --- a/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormDialogFragment.java +++ b/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormDialogFragment.java @@ -55,8 +55,8 @@ public class TodayFormDialogFragment extends DynamicDialogFragment { } private void setLayoutValues(List tasks) { - EditText editText = (EditText) findViewById(R.id.today_search); - final ListView listView = (ListView) findViewById(R.id.today_tasks); + EditText editText = findViewById(R.id.today_search); + final ListView listView = findViewById(R.id.today_tasks); final TodayArrayAdapter adapter = new TodayArrayAdapter(getActivity(), tasks); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { diff --git a/app/src/main/java/com/wismna/geoffroy/donext/widgets/InterceptTouchRelativeLayout.java b/app/src/main/java/com/wismna/geoffroy/donext/widgets/InterceptTouchRelativeLayout.java new file mode 100644 index 0000000..0e311de --- /dev/null +++ b/app/src/main/java/com/wismna/geoffroy/donext/widgets/InterceptTouchRelativeLayout.java @@ -0,0 +1,28 @@ +package com.wismna.geoffroy.donext.widgets; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.widget.RelativeLayout; + +/** + * Created by GBE on 22/12/2017. + * This class extends RelativeLayout to intercept touch event (and disable them) + */ + +public class InterceptTouchRelativeLayout extends RelativeLayout { + private boolean interceptTouchEvents = false; + + public InterceptTouchRelativeLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public void setInterceptTouchEvents(boolean interceptTouchEvents) { + this.interceptTouchEvents = interceptTouchEvents; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + return interceptTouchEvents || super.onInterceptTouchEvent(ev); + } +} diff --git a/app/src/main/res/layout/content_task_form.xml b/app/src/main/res/layout/content_task_form.xml index 7bca1a3..1b4f80a 100644 --- a/app/src/main/res/layout/content_task_form.xml +++ b/app/src/main/res/layout/content_task_form.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/background_light"> - - + \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index cfb03de..38d49a1 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -62,4 +62,5 @@ Historique OK Historique + Tâche \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f03c98c..505a4b3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -83,5 +83,6 @@ History + Task