Correct order handling

Today view has separate order
Some layout changes
Some code refactoring
This commit is contained in:
BONNEVILLE Geoffroy
2018-11-12 18:20:19 +01:00
parent 45d934dbb0
commit a3f7e08543
19 changed files with 234 additions and 120 deletions

View File

@@ -18,7 +18,7 @@
<PersistentState> <PersistentState>
<option name="values"> <option name="values">
<map> <map>
<entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/notification/ic_priority_high_black_24dp.xml" /> <entry key="url" value="jar:file:/C:/Program%20Files/Android/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/navigation/ic_refresh_black_24dp.xml" />
</map> </map>
</option> </option>
</PersistentState> </PersistentState>
@@ -28,8 +28,7 @@
</option> </option>
<option name="values"> <option name="values">
<map> <map>
<entry key="color" value="b5151a" /> <entry key="outputName" value="ic_refresh_black_24dp" />
<entry key="outputName" value="ic_priority_high_red_24dp" />
<entry key="sourceFile" value="C:\Users\GBE" /> <entry key="sourceFile" value="C:\Users\GBE" />
</map> </map>
</option> </option>

View File

@@ -30,7 +30,7 @@ public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerA
// Register the fragment when the item is instantiated // Register the fragment when the item is instantiated
@NonNull @NonNull
@Override @Override
public Object instantiateItem(ViewGroup container, int position) { public Object instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position); Fragment fragment = (Fragment) super.instantiateItem(container, position);
registeredFragments.put(position, fragment); registeredFragments.put(position, fragment);
return fragment; return fragment;
@@ -38,7 +38,7 @@ public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerA
// Unregister when the item is inactive // Unregister when the item is inactive
@Override @Override
public void destroyItem(ViewGroup container, int position, Object object) { public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
registeredFragments.remove(position); registeredFragments.remove(position);
super.destroyItem(container, position, object); super.destroyItem(container, position, object);
} }

View File

@@ -1,5 +1,6 @@
package com.wismna.geoffroy.donext.adapters; package com.wismna.geoffroy.donext.adapters;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
@@ -40,15 +41,16 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
mListener = listener; mListener = listener;
} }
@NonNull
@Override @Override
public TaskViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public TaskViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()) View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_tasklist, parent, false); .inflate(R.layout.fragment_tasklist, parent, false);
return new TaskViewHolder(view); return new TaskViewHolder(view);
} }
@Override @Override
public void onBindViewHolder(final TaskViewHolder holder, int position) { public void onBindViewHolder(@NonNull final TaskViewHolder holder, int position) {
holder.mItem = mValues.get(position); holder.mItem = mValues.get(position);
holder.mTaskCountView.setText(String.valueOf(mValues.get(position).getTaskCount())); holder.mTaskCountView.setText(String.valueOf(mValues.get(position).getTaskCount()));
holder.mTaskNameView.setText(mValues.get(position).getName()); holder.mTaskNameView.setText(mValues.get(position).getName());
@@ -151,6 +153,7 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
mTaskDeleteButton = view.findViewById(R.id.task_list_delete); mTaskDeleteButton = view.findViewById(R.id.task_list_delete);
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return super.toString() + " '" + mTaskNameView.getText() + "'"; return super.toString() + " '" + mTaskNameView.getText() + "'";

View File

@@ -1,5 +1,7 @@
package com.wismna.geoffroy.donext.dao; package com.wismna.geoffroy.donext.dao;
import android.support.annotation.NonNull;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
/** /**
@@ -14,6 +16,8 @@ public class Task {
private int cycle; private int cycle;
private int done; private int done;
private int deleted; private int deleted;
private int order;
private int todayOrder;
private long taskList; private long taskList;
private String taskListName; private String taskListName;
private LocalDate dueDate; private LocalDate dueDate;
@@ -113,11 +117,26 @@ public class Task {
} }
} }
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
public int getTodayOrder() {
return todayOrder;
}
public void setTodayOrder(int todayOrder) {
this.todayOrder = todayOrder;
}
public boolean isToday() { public boolean isToday() {
return todayDate != null && todayDate.isEqual(LocalDate.now()); return todayDate != null && todayDate.isEqual(LocalDate.now());
} }
// Will be used by the ArrayAdapter in the ListView // Will be used by the ArrayAdapter in the ListView
@NonNull
@Override @Override
public String toString() { public String toString() {
return name; return name;

View File

@@ -1,5 +1,7 @@
package com.wismna.geoffroy.donext.dao; package com.wismna.geoffroy.donext.dao;
import android.support.annotation.NonNull;
/** /**
* Created by geoffroy on 15-11-25. * Created by geoffroy on 15-11-25.
* Data access object class that represents a Task List * Data access object class that represents a Task List
@@ -33,6 +35,7 @@ public class TaskList {
this.taskCount = taskCount; this.taskCount = taskCount;
} }
@NonNull
@Override @Override
public String toString() { public String toString() {
return name; return name;

View File

@@ -9,7 +9,7 @@ import android.database.sqlite.SQLiteOpenHelper;
* Database helper class that contains table and column names as well as handles database creation * Database helper class that contains table and column names as well as handles database creation
*/ */
class DatabaseHelper extends SQLiteOpenHelper { class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 5; private static final int DATABASE_VERSION = 6;
private static final String DATABASE_NAME = "donext.db"; private static final String DATABASE_NAME = "donext.db";
static final String COLUMN_ID = "_id"; static final String COLUMN_ID = "_id";
static final String COLUMN_ORDER = "displayorder"; static final String COLUMN_ORDER = "displayorder";
@@ -36,6 +36,7 @@ class DatabaseHelper extends SQLiteOpenHelper {
static final String TASKS_COLUMN_LIST = "list"; static final String TASKS_COLUMN_LIST = "list";
static final String TASKS_COLUMN_DUEDATE = "duedate"; static final String TASKS_COLUMN_DUEDATE = "duedate";
static final String TASKS_COLUMN_TODAYDATE = "todaydate"; static final String TASKS_COLUMN_TODAYDATE = "todaydate";
static final String TASKS_COLUMN_TODAYORDER = "todayorder";
private static final String TASKS_TABLE_CREATE = private static final String TASKS_TABLE_CREATE =
"CREATE TABLE " + TASKS_TABLE_NAME + " (" + "CREATE TABLE " + TASKS_TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
@@ -46,6 +47,7 @@ class DatabaseHelper extends SQLiteOpenHelper {
TASKS_COLUMN_DONE + " INTEGER DEFAULT 0, " + TASKS_COLUMN_DONE + " INTEGER DEFAULT 0, " +
TASKS_COLUMN_DELETED + " INTEGER DEFAULT 0, " + TASKS_COLUMN_DELETED + " INTEGER DEFAULT 0, " +
COLUMN_ORDER + " INTEGER, " + COLUMN_ORDER + " INTEGER, " +
TASKS_COLUMN_TODAYORDER + " INTEGER, " +
TASKS_COLUMN_LIST + " INTEGER NOT NULL " + TASKS_COLUMN_LIST + " INTEGER NOT NULL " +
"REFERENCES " + TASKLIST_TABLE_NAME + "(" + COLUMN_ID + "), " + "REFERENCES " + TASKLIST_TABLE_NAME + "(" + COLUMN_ID + "), " +
TASKS_COLUMN_DUEDATE + " DATE, " + TASKS_COLUMN_DUEDATE + " DATE, " +
@@ -73,7 +75,7 @@ class DatabaseHelper extends SQLiteOpenHelper {
// Fall-through is intended // Fall-through is intended
switch (oldVersion) { switch (oldVersion) {
case 1: case 1:
// Add new Order column // Add new Task List Order column
db.execSQL("ALTER TABLE " + TASKLIST_TABLE_NAME + " ADD COLUMN " + COLUMN_ORDER + " INTEGER"); db.execSQL("ALTER TABLE " + TASKLIST_TABLE_NAME + " ADD COLUMN " + COLUMN_ORDER + " INTEGER");
case 2: case 2:
// Add new Visible column // Add new Visible column
@@ -88,6 +90,10 @@ class DatabaseHelper extends SQLiteOpenHelper {
case 4: case 4:
db.execSQL("DROP VIEW " + TASKS_VIEW_TODAY_NAME); db.execSQL("DROP VIEW " + TASKS_VIEW_TODAY_NAME);
db.execSQL(TASKS_VIEW_TODAY_CREATE); db.execSQL(TASKS_VIEW_TODAY_CREATE);
case 5:
// Add new Task Order column
//db.execSQL("ALTER TABLE " + TASKS_TABLE_NAME + " ADD COLUMN " + COLUMN_ORDER + " INTEGER");
db.execSQL("ALTER TABLE " + TASKS_TABLE_NAME + " ADD COLUMN " + TASKS_COLUMN_TODAYORDER + " INTEGER");
} }
} }
} }

View File

@@ -3,7 +3,6 @@ package com.wismna.geoffroy.donext.database;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.wismna.geoffroy.donext.dao.Task; import com.wismna.geoffroy.donext.dao.Task;
@@ -30,7 +29,8 @@ public class TaskDataAccess implements AutoCloseable {
DatabaseHelper.TASKS_COLUMN_DESC, DatabaseHelper.TASKS_COLUMN_PRIORITY, DatabaseHelper.TASKS_COLUMN_DESC, DatabaseHelper.TASKS_COLUMN_PRIORITY,
DatabaseHelper.TASKS_COLUMN_CYCLE, DatabaseHelper.TASKS_COLUMN_DONE, DatabaseHelper.TASKS_COLUMN_CYCLE, DatabaseHelper.TASKS_COLUMN_DONE,
DatabaseHelper.TASKS_COLUMN_DELETED, DatabaseHelper.TASKS_COLUMN_LIST, DatabaseHelper.TASKS_COLUMN_DELETED, DatabaseHelper.TASKS_COLUMN_LIST,
DatabaseHelper.TASKS_COLUMN_DUEDATE, DatabaseHelper.TASKS_COLUMN_TODAYDATE}; DatabaseHelper.TASKS_COLUMN_DUEDATE, DatabaseHelper.TASKS_COLUMN_TODAYDATE,
DatabaseHelper.COLUMN_ORDER, DatabaseHelper.TASKS_COLUMN_TODAYORDER};
public TaskDataAccess(Context context) { public TaskDataAccess(Context context) {
this(context, MODE.READ); this(context, MODE.READ);
@@ -59,6 +59,7 @@ public class TaskDataAccess implements AutoCloseable {
values.put(DatabaseHelper.TASKS_COLUMN_LIST, taskList); values.put(DatabaseHelper.TASKS_COLUMN_LIST, taskList);
values.put(DatabaseHelper.TASKS_COLUMN_DUEDATE, dueDate); values.put(DatabaseHelper.TASKS_COLUMN_DUEDATE, dueDate);
values.put(DatabaseHelper.TASKS_COLUMN_TODAYDATE, isTodayList? LocalDate.now().toString() : ""); values.put(DatabaseHelper.TASKS_COLUMN_TODAYDATE, isTodayList? LocalDate.now().toString() : "");
values.put(DatabaseHelper.COLUMN_ORDER, getMaxOrder(taskList) + 1);
long insertId; long insertId;
if (id == 0) if (id == 0)
insertId = database.insert(DatabaseHelper.TASKS_TABLE_NAME, null, values); insertId = database.insert(DatabaseHelper.TASKS_TABLE_NAME, null, values);
@@ -66,18 +67,20 @@ public class TaskDataAccess implements AutoCloseable {
database.update(DatabaseHelper.TASKS_TABLE_NAME, values, DatabaseHelper.COLUMN_ID + " == " + id, null); database.update(DatabaseHelper.TASKS_TABLE_NAME, values, DatabaseHelper.COLUMN_ID + " == " + id, null);
insertId = id; insertId = id;
} }
Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, Task newTask;
try (Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME,
taskColumns, DatabaseHelper.COLUMN_ID + " = " + insertId, null, taskColumns, DatabaseHelper.COLUMN_ID + " = " + insertId, null,
null, null, null); null, null, null)) {
cursor.moveToFirst(); cursor.moveToFirst();
Task newTask = cursorToTask(cursor); newTask = cursorToTask(cursor);
cursor.close(); }
return newTask; return newTask;
} }
public void updateTodayTasks(long id, boolean isTodayList){ public void updateTodayTasks(long id, boolean isTodayList, int position){
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.TASKS_COLUMN_TODAYDATE, isTodayList? LocalDate.now().toString() : ""); contentValues.put(DatabaseHelper.TASKS_COLUMN_TODAYDATE, isTodayList? LocalDate.now().toString() : "");
contentValues.put(DatabaseHelper.TASKS_COLUMN_TODAYORDER, isTodayList? position : 0);
database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues,
DatabaseHelper.COLUMN_ID + " == " + id, null); DatabaseHelper.COLUMN_ID + " == " + id, null);
} }
@@ -114,14 +117,32 @@ public class TaskDataAccess implements AutoCloseable {
} }
public List<Task> getAllTasksFromList(long id, boolean isHistory) { public List<Task> getAllTasksFromList(long id, boolean isHistory) {
// REMOVE THIS
/*ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.COLUMN_ORDER, 0);
database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues,
null, null);*/
// --
int history = isHistory ? 1 : 0; int history = isHistory ? 1 : 0;
Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns, Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns,
DatabaseHelper.TASKS_COLUMN_LIST + " = " + id + DatabaseHelper.TASKS_COLUMN_LIST + " = " + id +
" AND (" + DatabaseHelper.TASKS_COLUMN_DONE + " = " + history + " AND (" + DatabaseHelper.TASKS_COLUMN_DONE + " = " + history +
(isHistory ? " OR " : " AND ") + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + history + ")", (isHistory ? " OR " : " AND ") + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + history + ")",
null, null, null, null, null, null,
DatabaseHelper.TASKS_COLUMN_PRIORITY + " DESC"); DatabaseHelper.COLUMN_ORDER);
return getTasksFromCursor(cursor); List<Task> tasks = getTasksFromCursor(cursor);
// Update orders for database migration
int count = tasks.size();
if (getMaxOrder(id) == 0 && count > 1) {
for (int i = 1; i < count; i++) {
update(tasks.get(i).getId(), DatabaseHelper.COLUMN_ORDER, i);
tasks.get(i).setOrder(i);
}
}
return tasks;
} }
public List<Task> getTodayTasks() { public List<Task> getTodayTasks() {
@@ -129,20 +150,28 @@ public class TaskDataAccess implements AutoCloseable {
DatabaseHelper.TASKS_COLUMN_DONE + " = 0" + DatabaseHelper.TASKS_COLUMN_DONE + " = 0" +
" AND " + DatabaseHelper.TASKS_COLUMN_DELETED + " = 0", " AND " + DatabaseHelper.TASKS_COLUMN_DELETED + " = 0",
null, null, null, null, null, null,
DatabaseHelper.TASKS_COLUMN_CYCLE + ", " + DatabaseHelper.COLUMN_ID + " DESC"); DatabaseHelper.TASKS_COLUMN_TODAYORDER);
return getTasksFromCursor(cursor); return getTasksFromCursor(cursor);
} }
public void setDone(long id) { public void increaseCycle(Task task, boolean isToday) {
String orderColumn = isToday ? DatabaseHelper.TASKS_COLUMN_TODAYORDER : DatabaseHelper.COLUMN_ORDER;
updateRemainingRowsOrder(task.getId(), orderColumn);
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.TASKS_COLUMN_CYCLE, task.getCycle());
contentValues.put(orderColumn, getMaxOrder(task.getTaskListId()) + 1);
database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues,
DatabaseHelper.COLUMN_ID + " == " + task.getId(), null);
}
public void setDone(long id, boolean isToday) {
update(id, DatabaseHelper.TASKS_COLUMN_DONE, 1); update(id, DatabaseHelper.TASKS_COLUMN_DONE, 1);
updateRemainingRowsOrder(id, isToday ? DatabaseHelper.TASKS_COLUMN_TODAYORDER : DatabaseHelper.COLUMN_ORDER);
} }
public void increaseCycle(int newCycle, long id) { public void deleteTask(long id, boolean isToday) {
update(id, DatabaseHelper.TASKS_COLUMN_CYCLE, newCycle);
}
public void deleteTask(long id) {
update(id, DatabaseHelper.TASKS_COLUMN_DELETED, 1); update(id, DatabaseHelper.TASKS_COLUMN_DELETED, 1);
updateRemainingRowsOrder(id, isToday ? DatabaseHelper.TASKS_COLUMN_TODAYORDER : DatabaseHelper.COLUMN_ORDER);
} }
private void update(long id, String column, Object value) { private void update(long id, String column, Object value) {
@@ -164,6 +193,8 @@ public class TaskDataAccess implements AutoCloseable {
task.setTaskList(cursor.getLong(7)); task.setTaskList(cursor.getLong(7));
task.setDueDate(cursor.getString(8)); task.setDueDate(cursor.getString(8));
task.setTodayDate(cursor.getString(9)); task.setTodayDate(cursor.getString(9));
task.setOrder(cursor.getInt(10));
task.setTodayOrder(cursor.getInt(11));
return task; return task;
} }
@@ -180,4 +211,25 @@ public class TaskDataAccess implements AutoCloseable {
cursor.close(); cursor.close();
return tasks; return tasks;
} }
private int getMaxOrder(long listId) {
try (Cursor maxOrderCursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, new String[]{"MAX(" + DatabaseHelper.COLUMN_ORDER + ")"},
DatabaseHelper.TASKS_COLUMN_LIST + " = " + listId, null, null, null, null)) {
maxOrderCursor.moveToFirst();
return maxOrderCursor.getInt(0);
}
}
private void updateRemainingRowsOrder(long id, String orderColumn) {
try (Cursor cursor = database.rawQuery("UPDATE " + DatabaseHelper.TASKS_TABLE_NAME +
" SET " + orderColumn + " = " + orderColumn + " - 1" +
" WHERE " + orderColumn + " > " +
"(SELECT " + orderColumn +
" FROM " + DatabaseHelper.TASKS_TABLE_NAME +
" WHERE " + DatabaseHelper.COLUMN_ID + " = " + id + ")",
null)) {
cursor.moveToFirst();
}
}
} }

View File

@@ -3,7 +3,6 @@ package com.wismna.geoffroy.donext.database;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.wismna.geoffroy.donext.dao.TaskList; import com.wismna.geoffroy.donext.dao.TaskList;

View File

@@ -12,6 +12,8 @@ import android.view.View;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import java.util.Objects;
public class ConfirmDialogFragment extends DialogFragment { public class ConfirmDialogFragment extends DialogFragment {
interface ConfirmDialogListener { interface ConfirmDialogListener {
void onConfirmDialogClick(DialogFragment dialog, ButtonEvent event); void onConfirmDialogClick(DialogFragment dialog, ButtonEvent event);
@@ -41,7 +43,7 @@ public class ConfirmDialogFragment extends DialogFragment {
@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(Objects.requireNonNull(getActivity()));
Bundle args = getArguments(); Bundle args = getArguments();
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();

View File

@@ -25,6 +25,8 @@ import android.widget.FrameLayout;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import java.util.Objects;
/** /**
* Created by wismna on 2017-03-21. * Created by wismna on 2017-03-21.
* Sub-class this class to create a dynamic fragment that will act as a Dialog in large layouts and * Sub-class this class to create a dynamic fragment that will act as a Dialog in large layouts and
@@ -104,7 +106,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear(); menu.clear();
getActivity().getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu); Objects.requireNonNull(getActivity()).getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu);
} }
@Override @Override
@@ -146,7 +148,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
// Hide the keyboard if present // Hide the keyboard if present
if (view != null) { if (view != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) Objects.requireNonNull(getActivity()).getSystemService(Activity.INPUT_METHOD_SERVICE);
assert imm != null; assert imm != null;
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
} }
@@ -199,7 +201,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*/ /** Helper function to get a View, without having to worry about the fact that is a Dialog or not*/
protected <T extends View> T findViewById(int id) { protected <T extends View> T findViewById(int id) {
if (getShowsDialog()) return getDialog().findViewById(id); if (getShowsDialog()) return getDialog().findViewById(id);
return getView().findViewById(id); return Objects.requireNonNull(getView()).findViewById(id);
} }
@@ -210,8 +212,8 @@ public abstract class DynamicDialogFragment extends DialogFragment {
view.requestFocus(); view.requestFocus();
// Hide keyboard // Hide keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager inputMethodManager = (InputMethodManager) Objects.requireNonNull(getContext()).getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); Objects.requireNonNull(inputMethodManager).hideSoftInputFromWindow(view.getWindowToken(), 0);
} }
} }

View File

@@ -23,6 +23,7 @@ import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* A fragment representing a list of Items. * A fragment representing a list of Items.
@@ -151,7 +152,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
args.putInt("ItemPosition", position); args.putInt("ItemPosition", position);
args.putLong("ItemId", id); args.putLong("ItemId", id);
confirmDialogFragment.setArguments(args); confirmDialogFragment.setArguments(args);
confirmDialogFragment.show(getFragmentManager(), title); confirmDialogFragment.show(Objects.requireNonNull(getFragmentManager()), title);
} }
else deleteTaskList(position, id); else deleteTaskList(position, id);
} }

View File

@@ -416,8 +416,7 @@ public class TasksFragment extends Fragment implements
break; break;
case -1: case -1:
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
assert manager != null; DialogFragment dialog = (DialogFragment) Objects.requireNonNull(manager).findFragmentByTag(getString(R.string.action_edit_task));
DialogFragment dialog = (DialogFragment) manager.findFragmentByTag(getString(R.string.action_edit_task));
if (dialog != null) dialog.dismiss(); if (dialog != null) dialog.dismiss();
action = resources.getString(R.string.snackabar_action_deleted); action = resources.getString(R.string.snackabar_action_deleted);
break; break;
@@ -460,15 +459,16 @@ public class TasksFragment extends Fragment implements
switch (direction) { switch (direction) {
// Mark item as Done // Mark item as Done
case ItemTouchHelper.LEFT: case ItemTouchHelper.LEFT:
taskDataAccess.setDone(itemId); taskDataAccess.setDone(itemId, isTodayView);
break; break;
// Increase task cycle count // Increase task cycle count
case ItemTouchHelper.RIGHT: case ItemTouchHelper.RIGHT:
taskDataAccess.increaseCycle(task.getCycle(), itemId); taskDataAccess.increaseCycle(task, isTodayView);
taskRecyclerViewAdapter.notifyItemChanged(taskRecyclerViewAdapter.getItemCount() - 1);
break; break;
case -1: case -1:
// Delete the task // Delete the task
taskDataAccess.deleteTask(itemId); taskDataAccess.deleteTask(itemId, isTodayView);
} }
} }
} }

View File

@@ -21,6 +21,7 @@ import org.joda.time.LocalDate;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
* Created by bg45 on 2017-03-21. * Created by bg45 on 2017-03-21.
@@ -60,7 +61,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
private void setLayoutValues(List<Task> tasks) { private void setLayoutValues(List<Task> tasks) {
EditText editText = findViewById(R.id.today_search); EditText editText = findViewById(R.id.today_search);
final ListView listView = findViewById(R.id.today_tasks); final ListView listView = findViewById(R.id.today_tasks);
final TodayArrayAdapter adapter = new TodayArrayAdapter(getActivity(), tasks); final TodayArrayAdapter adapter = new TodayArrayAdapter(Objects.requireNonNull(getActivity()), tasks);
listView.setAdapter(adapter); listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
@@ -98,7 +99,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
protected void onPositiveButtonClick(View view) { protected void onPositiveButtonClick(View view) {
mListener.onTodayTaskDialogPositiveClick(view); mListener.onTodayTaskDialogPositiveClick(view);
// Only commit the updated tasks to DB // Only commit the updated tasks to DB
new UpdateTasks(this).execute(mUpdatedTasks.toArray(new Task[mUpdatedTasks.size()])); new UpdateTasks(this).execute(mUpdatedTasks.toArray(new Task[0]));
dismiss(); dismiss();
} }
@@ -142,15 +143,14 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
@Override @Override
protected Integer doInBackground(Task... params) { protected Integer doInBackground(Task... params) {
int elementsUpdated = 0; int position;
try (TaskDataAccess taskDataAccess = new TaskDataAccess(fragmentReference.get().getActivity(), TaskDataAccess.MODE.WRITE)) { try (TaskDataAccess taskDataAccess = new TaskDataAccess(fragmentReference.get().getActivity(), TaskDataAccess.MODE.WRITE)) {
for (Task task : for (position = 0; position < params.length; position ++) {
params) { Task task = params[position];
taskDataAccess.updateTodayTasks(task.getId(), task.isToday()); taskDataAccess.updateTodayTasks(task.getId(), task.isToday(), position);
elementsUpdated++;
} }
} }
return elementsUpdated; return position;
} }
@Override @Override

View File

@@ -1,6 +1,7 @@
package com.wismna.geoffroy.donext.helpers; package com.wismna.geoffroy.donext.helpers;
import android.graphics.Color; import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper; import android.support.v7.widget.helper.ItemTouchHelper;
@@ -22,12 +23,12 @@ public class TaskListTouchHelper extends ItemTouchHelper.SimpleCallback {
} }
@Override @Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition()); return mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
} }
@Override @Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
// No swipe moves // No swipe moves
} }
@@ -47,7 +48,7 @@ public class TaskListTouchHelper extends ItemTouchHelper.SimpleCallback {
} }
@Override @Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { public void clearView(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder); super.clearView(recyclerView, viewHolder);
viewHolder.itemView.setAlpha(1.0f); viewHolder.itemView.setAlpha(1.0f);

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#a6a5a5"
android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>

View File

@@ -1,18 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="75dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="70dp"
android:paddingTop="5dp" android:paddingTop="5dp"
android:orientation="horizontal" android:paddingBottom="5dp"
android:focusable="true" android:focusable="true"
android:background="?android:attr/selectableItemBackground" > android:background="?android:attr/selectableItemBackground" >
<TextView
android:id="@+id/task_cycle"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_gravity="center"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView <TextView
android:id="@+id/task_id" android:id="@+id/task_id"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -22,26 +15,40 @@
android:id="@+id/task_icon" android:id="@+id/task_icon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_gravity="center" android:layout_gravity="center"
android:contentDescription="@string/task_alarm"/> android:contentDescription="@string/task_alarm" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <TextView
android:id="@+id/task_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="?listPreferredItemHeight" android:layout_height="wrap_content"
android:orientation="vertical"> android:layout_toEndOf="@id/task_icon"
<TextView android:textSize="18sp"
android:id="@+id/task_name" android:textAppearance="?attr/textAppearanceListItem" />
android:layout_width="wrap_content" <ImageView
android:layout_height="wrap_content" android:id="@+id/task_cycle_icon"
android:textAppearance="?attr/textAppearanceListItem" /> android:layout_width="24dp"
<TextView android:layout_height="wrap_content"
android:id="@+id/task_description" android:layout_alignParentEnd="true"
android:layout_width="wrap_content" android:layout_marginEnd="5dp"
android:layout_height="wrap_content" android:src="@drawable/ic_refresh_black_24dp"
android:maxLines="2" android:contentDescription="@string/task_alarm" />
android:textColor="@color/colorPrimary" <TextView
android:textSize="14sp" android:id="@+id/task_cycle"
android:textAppearance="?attr/textAppearanceListItemSmall" /> android:layout_width="wrap_content"
</LinearLayout> android:layout_height="wrap_content"
</LinearLayout> android:layout_marginStart="10dp"
android:layout_toStartOf="@id/task_cycle_icon"
android:textColor="#FFA6A5A5"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView
android:id="@+id/task_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:maxLines="2"
android:textColor="@color/colorPrimary"
android:textSize="14sp"
android:layout_below="@id/task_name"
android:textAppearance="?attr/textAppearanceListItemSmall" />
</RelativeLayout>

View File

@@ -1,18 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="130dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="120dp"
android:paddingTop="5dp" android:paddingTop="5dp"
android:orientation="horizontal" android:paddingBottom="5dp"
android:focusable="true" android:focusable="true"
android:background="@color/colorPrimaryLight" > android:background="@color/colorPrimaryLight">
<TextView
android:id="@+id/task_cycle"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_gravity="center"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView <TextView
android:id="@+id/task_id" android:id="@+id/task_id"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -22,29 +15,43 @@
android:id="@+id/task_icon" android:id="@+id/task_icon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_gravity="center" android:layout_gravity="center"
android:contentDescription="@string/task_alarm"/> android:contentDescription="@string/task_alarm" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <TextView
android:id="@+id/task_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="120dp" android:layout_height="wrap_content"
android:orientation="vertical"> android:layout_toEndOf="@id/task_icon"
<TextView android:textSize="20sp"
android:id="@+id/task_name" android:textStyle="bold"
android:layout_width="wrap_content" android:textColor="@color/colorAccent"
android:layout_height="wrap_content" android:textAppearance="?attr/textAppearanceListItem" />
android:textSize="18sp" <ImageView
android:textStyle="bold" android:id="@+id/task_cycle_icon"
android:textColor="@color/colorAccent" android:layout_width="24dp"
android:textAppearance="?attr/textAppearanceListItem" /> android:layout_height="wrap_content"
<TextView android:layout_alignParentEnd="true"
android:id="@+id/task_description" android:layout_marginEnd="5dp"
android:layout_width="wrap_content" android:src="@drawable/ic_refresh_black_24dp"
android:layout_height="wrap_content" android:contentDescription="@string/task_alarm" />
android:layout_marginTop="10dp" <TextView
android:maxLines="4" android:id="@+id/task_cycle"
android:textSize="16sp" android:layout_width="wrap_content"
android:textAppearance="?attr/textAppearanceListItemSmall" /> android:layout_height="wrap_content"
</LinearLayout> android:layout_marginStart="10dp"
</LinearLayout> android:layout_toStartOf="@id/task_cycle_icon"
android:textColor="#FFA6A5A5"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView
android:id="@+id/task_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="30dp"
android:layout_below="@id/task_name"
android:maxLines="4"
android:textSize="16sp"
android:textAppearance="?attr/textAppearanceListItemSmall" />
</RelativeLayout>

View File

@@ -82,15 +82,17 @@
android:orientation="horizontal" android:orientation="horizontal"
android:focusable="true" android:focusable="true"
android:background="?android:attr/selectableItemBackground" > android:background="?android:attr/selectableItemBackground" >
<TextView
android:id="@+id/total_task_cycles"
android:layout_width="100dp"
android:layout_gravity="center"
android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/total_task_count" android:id="@+id/total_task_count"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"
android:layout_marginStart="30dp" />
<TextView
android:id="@+id/total_task_cycles"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginStart="20dp" />
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>

View File

@@ -1,3 +1,5 @@
Emphasis is made on the first task Emphasis is made on the first task
Correct task order handling
Order in Today view is different from order in Main view
Bug corrections Bug corrections
Design improvements Design improvements