mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
New Today list via settings
Code cleanup WIP Today tasks
This commit is contained in:
@@ -8,8 +8,8 @@ android {
|
|||||||
applicationId "com.wismna.geoffroy.donext"
|
applicationId "com.wismna.geoffroy.donext"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 13
|
versionCode 14
|
||||||
versionName "1.2.0"
|
versionName "1.3.0"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@@ -63,10 +63,16 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
|||||||
// primary sections of the activity.
|
// primary sections of the activity.
|
||||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
|
|
||||||
|
SharedPreferences sharedPref =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
||||||
|
|
||||||
// Access database to retrieve Tabs
|
// Access database to retrieve Tabs
|
||||||
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(this);
|
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(this);
|
||||||
taskListDataAccess.open();
|
taskListDataAccess.open();
|
||||||
|
|
||||||
|
// Handle Today list
|
||||||
|
handleTodayList(sharedPref, taskListDataAccess);
|
||||||
|
|
||||||
taskLists = taskListDataAccess.getAllTaskLists();
|
taskLists = taskListDataAccess.getAllTaskLists();
|
||||||
mSectionsPagerAdapter.notifyDataSetChanged();
|
mSectionsPagerAdapter.notifyDataSetChanged();
|
||||||
taskListDataAccess.close();
|
taskListDataAccess.close();
|
||||||
@@ -81,8 +87,6 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
|||||||
mViewPager = (ViewPager) findViewById(R.id.container);
|
mViewPager = (ViewPager) findViewById(R.id.container);
|
||||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||||
// Open last opened tab
|
// Open last opened tab
|
||||||
SharedPreferences sharedPref =
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
|
||||||
mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0));
|
mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0));
|
||||||
|
|
||||||
View tabs = findViewById(R.id.tabs);
|
View tabs = findViewById(R.id.tabs);
|
||||||
@@ -256,6 +260,25 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleTodayList(SharedPreferences sharedPref, TaskListDataAccess taskListDataAccess) {
|
||||||
|
String todayListName = getString(R.string.task_list_today);
|
||||||
|
TaskList todayList = taskListDataAccess.getTaskListByName(todayListName);
|
||||||
|
if (sharedPref.getBoolean("pref_conf_today_enable", false)) {
|
||||||
|
// Get or create the Today list
|
||||||
|
if (todayList == null) {
|
||||||
|
// TODO: set order correctly
|
||||||
|
todayList = taskListDataAccess.createTaskList(todayListName, 0);
|
||||||
|
}
|
||||||
|
if (!todayList.isVisible()) taskListDataAccess.updateVisibility(todayList.getId(), true);
|
||||||
|
// Mark all tasks with an earlier do date as done
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (todayList != null){
|
||||||
|
taskListDataAccess.updateVisibility(todayList.getId(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||||
* one of the sections/tabs/pages.
|
* one of the sections/tabs/pages.
|
||||||
|
@@ -17,6 +17,7 @@ import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link RecyclerView.Adapter} that can display a {@link TaskList}.
|
* {@link RecyclerView.Adapter} that can display a {@link TaskList}.
|
||||||
@@ -34,10 +35,14 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
|
|
||||||
private final List<TaskList> mValues;
|
private final List<TaskList> mValues;
|
||||||
private TaskListRecyclerViewAdapterListener mListener;
|
private TaskListRecyclerViewAdapterListener mListener;
|
||||||
|
private String mReservedTaskListName;
|
||||||
|
|
||||||
public TaskListRecyclerViewAdapter(List<TaskList> items, TaskListRecyclerViewAdapterListener listener) {
|
public TaskListRecyclerViewAdapter(List<TaskList> items,
|
||||||
|
TaskListRecyclerViewAdapterListener listener,
|
||||||
|
String reservedTaskListName) {
|
||||||
mValues = items;
|
mValues = items;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
|
mReservedTaskListName = reservedTaskListName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -53,6 +58,7 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
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());
|
||||||
|
|
||||||
|
|
||||||
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
|
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
@@ -64,8 +70,10 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Boolean isReservedName = Objects.equals(holder.mItem.getName(), mReservedTaskListName);
|
||||||
|
holder.mTaskNameView.setEnabled(!isReservedName);
|
||||||
// Handle inline name change
|
// Handle inline name change
|
||||||
holder.mTaskNameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
if (!isReservedName) holder.mTaskNameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFocusChange(View v, boolean hasFocus) {
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
EditText editText = (EditText) v;
|
EditText editText = (EditText) v;
|
||||||
@@ -80,8 +88,9 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
holder.mTaskDeleteButton.setEnabled(!isReservedName);
|
||||||
// Handle click on delete button
|
// Handle click on delete button
|
||||||
holder.mTaskDeleteButton.setOnClickListener(new View.OnClickListener() {
|
if (!isReservedName) holder.mTaskDeleteButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// Disable the OnFocusChanged listener as it is now pointless and harmful
|
// Disable the OnFocusChanged listener as it is now pointless and harmful
|
||||||
@@ -134,15 +143,15 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
public final View mView;
|
final View mView;
|
||||||
public final ImageView handleView;
|
final ImageView handleView;
|
||||||
public final TextView mTaskCountView;
|
final TextView mTaskCountView;
|
||||||
public final TextView mTaskNameView;
|
final TextView mTaskNameView;
|
||||||
public final Button mTaskDeleteButton;
|
final Button mTaskDeleteButton;
|
||||||
public TaskList mItem;
|
TaskList mItem;
|
||||||
|
|
||||||
public ViewHolder(View view) {
|
ViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
mView = view;
|
mView = view;
|
||||||
handleView = (ImageView) itemView.findViewById(R.id.handle);
|
handleView = (ImageView) itemView.findViewById(R.id.handle);
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
package com.wismna.geoffroy.donext.dao;
|
package com.wismna.geoffroy.donext.dao;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by geoffroy on 15-11-25.
|
* Created by geoffroy on 15-11-25.
|
||||||
* Data access object class that represents a Task
|
* Data access object class that represents a Task
|
||||||
@@ -14,6 +17,7 @@ public class Task {
|
|||||||
private int deleted;
|
private int deleted;
|
||||||
private long taskList;
|
private long taskList;
|
||||||
private String taskListName;
|
private String taskListName;
|
||||||
|
private Date dueDate;
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -87,6 +91,14 @@ public class Task {
|
|||||||
this.taskListName = taskListName;
|
this.taskListName = taskListName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDueDate(String dueDate) {
|
||||||
|
this.dueDate = Date.valueOf(dueDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDueDate() {
|
||||||
|
return dueDate;
|
||||||
|
}
|
||||||
|
|
||||||
// Will be used by the ArrayAdapter in the ListView
|
// Will be used by the ArrayAdapter in the ListView
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@@ -9,6 +9,7 @@ public class TaskList {
|
|||||||
private String name;
|
private String name;
|
||||||
private long taskCount;
|
private long taskCount;
|
||||||
private int order;
|
private int order;
|
||||||
|
private Boolean visible;
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -42,8 +43,15 @@ public class TaskList {
|
|||||||
this.order = order;
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setVisible(int visible) {
|
||||||
|
this.visible = visible != 0;
|
||||||
|
}
|
||||||
|
public Boolean isVisible() {
|
||||||
|
return visible;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,43 +8,48 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||||||
* Created by geoffroy on 15-11-25.
|
* Created by geoffroy on 15-11-25.
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
class DatabaseHelper extends SQLiteOpenHelper {
|
||||||
private static final int DATABASE_VERSION = 2;
|
private static final int DATABASE_VERSION = 3;
|
||||||
private static final String DATABASE_NAME = "donext.db";
|
private static final String DATABASE_NAME = "donext.db";
|
||||||
public static final String COLUMN_ID = "_id";
|
static final String COLUMN_ID = "_id";
|
||||||
public static final String COLUMN_ORDER = "displayorder";
|
static final String COLUMN_ORDER = "displayorder";
|
||||||
|
|
||||||
public static final String TASKLIST_TABLE_NAME = "tasklist";
|
static final String TASKLIST_TABLE_NAME = "tasklist";
|
||||||
public static final String TASKLIST_COLUMN_NAME = "name";
|
static final String TASKLIST_COLUMN_NAME = "name";
|
||||||
public static final String TASKLIST_COLUMN_TASK_COUNT = "taskcount";
|
static final String TASKLIST_COLUMN_TASK_COUNT = "taskcount";
|
||||||
|
static final String TASKLIST_COLUMN_VISIBLE = "visible";
|
||||||
private static final String TASKLIST_TABLE_CREATE =
|
private static final String TASKLIST_TABLE_CREATE =
|
||||||
"CREATE TABLE " + TASKLIST_TABLE_NAME + " (" +
|
"CREATE TABLE " + TASKLIST_TABLE_NAME + " (" +
|
||||||
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
||||||
TASKLIST_COLUMN_NAME + " TEXT NOT NULL, " +
|
TASKLIST_COLUMN_NAME + " TEXT NOT NULL, " +
|
||||||
COLUMN_ORDER + " INTEGER);";
|
COLUMN_ORDER + " INTEGER, " +
|
||||||
|
TASKLIST_COLUMN_VISIBLE + " INTEGER DEFAULT 1" +
|
||||||
|
");";
|
||||||
|
|
||||||
public static final String TASKS_TABLE_NAME = "tasks";
|
static final String TASKS_TABLE_NAME = "tasks";
|
||||||
public static final String TASKS_COLUMN_NAME = "name";
|
static final String TASKS_COLUMN_NAME = "name";
|
||||||
public static final String TASKS_COLUMN_DESC = "description";
|
static final String TASKS_COLUMN_DESC = "description";
|
||||||
public static final String TASKS_COLUMN_CYCLE = "cycle";
|
static final String TASKS_COLUMN_CYCLE = "cycle";
|
||||||
public static final String TASKS_COLUMN_PRIORITY = "priority";
|
static final String TASKS_COLUMN_PRIORITY = "priority";
|
||||||
public static final String TASKS_COLUMN_DONE = "done";
|
static final String TASKS_COLUMN_DONE = "done";
|
||||||
public static final String TASKS_COLUMN_DELETED= "deleted";
|
static final String TASKS_COLUMN_DELETED= "deleted";
|
||||||
public static final String TASKS_COLUMN_LIST = "list";
|
static final String TASKS_COLUMN_LIST = "list";
|
||||||
|
static final String TASKS_COLUMN_DUEDATE = "duedate";
|
||||||
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, " +
|
||||||
TASKS_COLUMN_NAME + " TEXT NOT NULL, " +
|
TASKS_COLUMN_NAME + " TEXT NOT NULL, " +
|
||||||
TASKS_COLUMN_DESC + " TEXT, " +
|
TASKS_COLUMN_DESC + " TEXT, " +
|
||||||
TASKS_COLUMN_PRIORITY + " INTEGER, " +
|
TASKS_COLUMN_PRIORITY + " INTEGER, " +
|
||||||
TASKS_COLUMN_CYCLE + " INTEGER DEFAULT 0, " +
|
TASKS_COLUMN_CYCLE + " INTEGER DEFAULT 0, " +
|
||||||
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_LIST + " INTEGER NOT NULL, " +
|
TASKS_COLUMN_LIST + " INTEGER NOT NULL, " +
|
||||||
"FOREIGN KEY(" + TASKS_COLUMN_LIST + ") REFERENCES " +
|
"FOREIGN KEY(" + TASKS_COLUMN_LIST + ") REFERENCES " +
|
||||||
TASKLIST_TABLE_NAME + "(" + COLUMN_ID + ")" +
|
TASKLIST_TABLE_NAME + "(" + COLUMN_ID + ")" +
|
||||||
");";
|
TASKS_COLUMN_DUEDATE + " DATE, " +
|
||||||
|
");";
|
||||||
|
|
||||||
DatabaseHelper(Context context) {
|
DatabaseHelper(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
@@ -63,5 +68,12 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||||||
// Add new Order column
|
// Add new 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");
|
||||||
}
|
}
|
||||||
|
if (oldVersion == 2)
|
||||||
|
{
|
||||||
|
// Add new Visible column
|
||||||
|
db.execSQL("ALTER TABLE " + TASKLIST_TABLE_NAME + " ADD COLUMN " + TASKLIST_COLUMN_VISIBLE + " INTEGER DEFAULT 1");
|
||||||
|
// Add new Due Date column
|
||||||
|
db.execSQL("ALTER TABLE " + TASKS_TABLE_NAME + " ADD COLUMN " + TASKS_COLUMN_DUEDATE + " DATE");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,9 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import com.wismna.geoffroy.donext.R;
|
import com.wismna.geoffroy.donext.R;
|
||||||
import com.wismna.geoffroy.donext.dao.Task;
|
import com.wismna.geoffroy.donext.dao.Task;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -55,11 +58,17 @@ public class TaskDataAccess implements AutoCloseable {
|
|||||||
|
|
||||||
/** Adds or update a task in the database */
|
/** Adds or update a task in the database */
|
||||||
public Task createOrUpdateTask(long id, String name, String description, String priority, long taskList) {
|
public Task createOrUpdateTask(long id, String name, String description, String priority, long taskList) {
|
||||||
|
return createOrUpdateTask(id, name, description, priority, taskList, new Date());
|
||||||
|
}
|
||||||
|
public Task createOrUpdateTask(long id, String name, String description, String priority, long taskList, Date date) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(DatabaseHelper.TASKS_COLUMN_NAME, name);
|
values.put(DatabaseHelper.TASKS_COLUMN_NAME, name);
|
||||||
values.put(DatabaseHelper.TASKS_COLUMN_DESC, description);
|
values.put(DatabaseHelper.TASKS_COLUMN_DESC, description);
|
||||||
values.put(DatabaseHelper.TASKS_COLUMN_PRIORITY, priorities.indexOf(priority));
|
values.put(DatabaseHelper.TASKS_COLUMN_PRIORITY, priorities.indexOf(priority));
|
||||||
values.put(DatabaseHelper.TASKS_COLUMN_LIST, taskList);
|
values.put(DatabaseHelper.TASKS_COLUMN_LIST, taskList);
|
||||||
|
DateFormat sdf = SimpleDateFormat.getDateInstance();
|
||||||
|
String dateString = sdf.format(date);
|
||||||
|
values.put(DatabaseHelper.TASKS_COLUMN_DUEDATE, dateString);
|
||||||
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);
|
||||||
@@ -92,7 +101,7 @@ public class TaskDataAccess implements AutoCloseable {
|
|||||||
return tasks;
|
return tasks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getAllTasksCursor(long id) {
|
private Cursor getAllTasksCursor(long id) {
|
||||||
return database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns,
|
return database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns,
|
||||||
DatabaseHelper.TASKS_COLUMN_LIST + " = " + id +
|
DatabaseHelper.TASKS_COLUMN_LIST + " = " + id +
|
||||||
" AND " + DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 +
|
" AND " + DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 +
|
||||||
@@ -102,22 +111,23 @@ public class TaskDataAccess implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int setDone(long id) {
|
public int setDone(long id) {
|
||||||
ContentValues contentValues = new ContentValues();
|
return update(id, DatabaseHelper.TASKS_COLUMN_DONE, 1);
|
||||||
contentValues.put(DatabaseHelper.TASKS_COLUMN_DONE, 1);
|
|
||||||
return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int increaseCycle(int newCycle, long id) {
|
public int increaseCycle(int newCycle, long id) {
|
||||||
ContentValues contentValues = new ContentValues();
|
return update(id, DatabaseHelper.TASKS_COLUMN_CYCLE, newCycle);
|
||||||
contentValues.put(DatabaseHelper.TASKS_COLUMN_CYCLE, newCycle);
|
|
||||||
return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int deleteTask(long id) {
|
public int deleteTask(long id) {
|
||||||
/*database.delete(DatabaseHelper.TASKS_TABLE_NAME,
|
/*database.delete(DatabaseHelper.TASKS_TABLE_NAME,
|
||||||
DatabaseHelper.COLUMN_ID + " = " + taskId, null);*/
|
DatabaseHelper.COLUMN_ID + " = " + taskId, null);*/
|
||||||
|
return update(id, DatabaseHelper.TASKS_COLUMN_DELETED, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int update(long id, String column, Object value) {
|
||||||
ContentValues contentValues = new ContentValues();
|
ContentValues contentValues = new ContentValues();
|
||||||
contentValues.put(DatabaseHelper.TASKS_COLUMN_DELETED, 1);
|
if (value instanceof Integer)
|
||||||
|
contentValues.put(column, (int) value);
|
||||||
return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +141,7 @@ public class TaskDataAccess implements AutoCloseable {
|
|||||||
task.setDone(cursor.getInt(5));
|
task.setDone(cursor.getInt(5));
|
||||||
task.setDeleted(cursor.getInt(6));
|
task.setDeleted(cursor.getInt(6));
|
||||||
task.setTaskList(cursor.getLong(7));
|
task.setTaskList(cursor.getLong(7));
|
||||||
|
task.setDueDate(cursor.getString(8));
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,8 @@ public class TaskListDataAccess {
|
|||||||
private SQLiteDatabase database;
|
private SQLiteDatabase database;
|
||||||
private DatabaseHelper dbHelper;
|
private DatabaseHelper dbHelper;
|
||||||
private String[] taskListColumns =
|
private String[] taskListColumns =
|
||||||
{DatabaseHelper.COLUMN_ID, DatabaseHelper.TASKLIST_COLUMN_NAME, DatabaseHelper.COLUMN_ORDER};
|
{DatabaseHelper.COLUMN_ID, DatabaseHelper.TASKLIST_COLUMN_NAME,
|
||||||
|
DatabaseHelper.COLUMN_ORDER, DatabaseHelper.TASKLIST_COLUMN_VISIBLE};
|
||||||
|
|
||||||
public TaskListDataAccess(Context context) {
|
public TaskListDataAccess(Context context) {
|
||||||
dbHelper = new DatabaseHelper(context);
|
dbHelper = new DatabaseHelper(context);
|
||||||
@@ -35,9 +36,14 @@ public class TaskListDataAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TaskList createTaskList(String name, int order) {
|
public TaskList createTaskList(String name, int order) {
|
||||||
|
return createTaskList(name, order, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskList createTaskList(String name, int order, Boolean visible) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(DatabaseHelper.TASKLIST_COLUMN_NAME, name);
|
values.put(DatabaseHelper.TASKLIST_COLUMN_NAME, name);
|
||||||
values.put(DatabaseHelper.COLUMN_ORDER, order);
|
values.put(DatabaseHelper.COLUMN_ORDER, order);
|
||||||
|
values.put(DatabaseHelper.TASKLIST_COLUMN_VISIBLE, visible ? 1 : 0);
|
||||||
long insertId = database.insert(DatabaseHelper.TASKLIST_TABLE_NAME, null,
|
long insertId = database.insert(DatabaseHelper.TASKLIST_TABLE_NAME, null,
|
||||||
values);
|
values);
|
||||||
Cursor cursor = database.query(DatabaseHelper.TASKLIST_TABLE_NAME,
|
Cursor cursor = database.query(DatabaseHelper.TASKLIST_TABLE_NAME,
|
||||||
@@ -59,22 +65,32 @@ public class TaskListDataAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateOrder(long id, int order) {
|
public void updateOrder(long id, int order) {
|
||||||
ContentValues contentValues = new ContentValues();
|
update(id, DatabaseHelper.COLUMN_ORDER, order);
|
||||||
contentValues.put(DatabaseHelper.COLUMN_ORDER, order);
|
|
||||||
database.update(DatabaseHelper.TASKLIST_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateName(long id, String name) {
|
public void updateName(long id, String name) {
|
||||||
ContentValues contentValues = new ContentValues();
|
update(id, DatabaseHelper.TASKLIST_COLUMN_NAME, name);
|
||||||
contentValues.put(DatabaseHelper.TASKLIST_COLUMN_NAME, name);
|
}
|
||||||
database.update(DatabaseHelper.TASKLIST_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
|
||||||
|
public void updateVisibility(long id, boolean visible){
|
||||||
|
update(id, DatabaseHelper.TASKLIST_COLUMN_VISIBLE, visible ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
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<TaskList> getAllTaskLists() {
|
public List<TaskList> getAllTaskLists() {
|
||||||
List<TaskList> taskLists = new ArrayList<>();
|
List<TaskList> taskLists = new ArrayList<>();
|
||||||
|
|
||||||
Cursor cursor = getAllTaskListsCursor();
|
Cursor cursor = getAllTaskListsCursor();
|
||||||
|
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
while (!cursor.isAfterLast()) {
|
while (!cursor.isAfterLast()) {
|
||||||
TaskList taskList = cursorToTaskList(cursor);
|
TaskList taskList = cursorToTaskList(cursor);
|
||||||
@@ -86,13 +102,28 @@ public class TaskListDataAccess {
|
|||||||
return taskLists;
|
return taskLists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getAllTaskListsCursor() {
|
private void update(long id, String column, Object value)
|
||||||
|
{
|
||||||
|
ContentValues contentValues = new ContentValues();
|
||||||
|
if (value instanceof String)
|
||||||
|
contentValues.put(column, (String) value);
|
||||||
|
if (value instanceof Integer)
|
||||||
|
contentValues.put(column, (int) value);
|
||||||
|
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 + "'", null, null, null, null, null);
|
||||||
|
}
|
||||||
|
private Cursor getAllTaskListsCursor() {
|
||||||
return database.rawQuery("SELECT *," +
|
return database.rawQuery("SELECT *," +
|
||||||
" (SELECT COUNT(*) " +
|
" (SELECT COUNT(*) " +
|
||||||
" FROM " + DatabaseHelper.TASKS_TABLE_NAME +
|
" FROM " + DatabaseHelper.TASKS_TABLE_NAME +
|
||||||
" WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " +
|
" WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " +
|
||||||
DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + ") AS " + DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT +
|
DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + ") AS " + DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT +
|
||||||
" FROM " + DatabaseHelper.TASKLIST_TABLE_NAME +
|
" FROM " + DatabaseHelper.TASKLIST_TABLE_NAME +
|
||||||
|
" WHERE " + DatabaseHelper.TASKLIST_COLUMN_VISIBLE + " = " + 1 +
|
||||||
" ORDER BY " + DatabaseHelper.COLUMN_ORDER + " ASC ",
|
" ORDER BY " + DatabaseHelper.COLUMN_ORDER + " ASC ",
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
@@ -102,8 +133,11 @@ public class TaskListDataAccess {
|
|||||||
taskList.setId(cursor.getLong(0));
|
taskList.setId(cursor.getLong(0));
|
||||||
taskList.setName(cursor.getString(1));
|
taskList.setName(cursor.getString(1));
|
||||||
taskList.setOrder(cursor.getInt(2));
|
taskList.setOrder(cursor.getInt(2));
|
||||||
if (cursor.getColumnCount() == 4)
|
taskList.setVisible(cursor.getInt(3));
|
||||||
taskList.setTaskCount(cursor.getLong(3));
|
// Get "false" count column if it exists
|
||||||
|
if (cursor.getColumnCount() == 5)
|
||||||
|
taskList.setTaskCount(cursor.getLong(4));
|
||||||
return taskList;
|
return taskList;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -70,6 +70,10 @@ public class TaskListsFragment extends Fragment implements
|
|||||||
editText.setError(getResources().getString(R.string.task_list_new_list_error));
|
editText.setError(getResources().getString(R.string.task_list_new_list_error));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (text.matches(getString(R.string.task_list_today))) {
|
||||||
|
editText.setError(getResources().getString(R.string.task_list_today_list_error));
|
||||||
|
return;
|
||||||
|
}
|
||||||
int position = taskListRecyclerViewAdapter.getItemCount();
|
int position = taskListRecyclerViewAdapter.getItemCount();
|
||||||
|
|
||||||
TaskList taskList = taskListDataAccess.createTaskList(text, position);
|
TaskList taskList = taskListDataAccess.createTaskList(text, position);
|
||||||
@@ -101,7 +105,7 @@ public class TaskListsFragment extends Fragment implements
|
|||||||
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();
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "3");
|
String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "5");
|
||||||
int maxTaskLists = Integer.valueOf(maxTaskListsString);
|
int maxTaskLists = Integer.valueOf(maxTaskListsString);
|
||||||
if (taskListCount >= maxTaskLists) layout.setVisibility(View.GONE);
|
if (taskListCount >= maxTaskLists) layout.setVisibility(View.GONE);
|
||||||
else layout.setVisibility(View.VISIBLE);
|
else layout.setVisibility(View.VISIBLE);
|
||||||
@@ -192,7 +196,7 @@ public class TaskListsFragment extends Fragment implements
|
|||||||
protected void onPostExecute(List<TaskList> taskLists) {
|
protected void onPostExecute(List<TaskList> taskLists) {
|
||||||
super.onPostExecute(taskLists);
|
super.onPostExecute(taskLists);
|
||||||
taskListRecyclerViewAdapter =
|
taskListRecyclerViewAdapter =
|
||||||
new TaskListRecyclerViewAdapter(taskLists, TaskListsFragment.this);
|
new TaskListRecyclerViewAdapter(taskLists, TaskListsFragment.this, getString(R.string.task_list_today));
|
||||||
|
|
||||||
// Set the adapter
|
// Set the adapter
|
||||||
Context context = mView.getContext();
|
Context context = mView.getContext();
|
||||||
|
7
DoNExt/app/src/main/res/values-fr/arrays.xml
Normal file
7
DoNExt/app/src/main/res/values-fr/arrays.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string-array name="settings_today_actions">
|
||||||
|
<item>Terminé</item>
|
||||||
|
<item>Supprimé</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
@@ -63,4 +63,10 @@
|
|||||||
<string name="task_total">%1$d tâche%2$s</string>
|
<string name="task_total">%1$d tâche%2$s</string>
|
||||||
<string name="task_total_cycles">%1$d cycle%2$s</string>
|
<string name="task_total_cycles">%1$d cycle%2$s</string>
|
||||||
<string name="title_activity_task_list">TaskListActivity</string>
|
<string name="title_activity_task_list">TaskListActivity</string>
|
||||||
|
<string name="settings_today_title">Liste Aujourd\'hui</string>
|
||||||
|
<string name="settings_today_enable">Activer la liste Aujourd\'hui?</string>
|
||||||
|
<string name="settings_today_desc">La liste Aujourd\'hui est une liste spéciale, dans laquelle les tâches n\'existent que pour la journée en cours. Chaque jour, cette liste est réinitialisée.</string>
|
||||||
|
<string name="task_list_today">Aujourd\'hui</string>
|
||||||
|
<string name="task_list_today_list_error">Le nom \"Aujourd\'hui\" est réservé. Vous pouvez activer la liste Aujourd\'hui dans les paramètres.</string>
|
||||||
|
<string name="settings_today_action_title">Action à entreprendre à la fin de la journée:</string>
|
||||||
</resources>
|
</resources>
|
28
DoNExt/app/src/main/res/values/arrays.xml
Normal file
28
DoNExt/app/src/main/res/values/arrays.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string-array name="settings_max_lists_number" translatable="false">
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
<item>3</item>
|
||||||
|
<item>4</item>
|
||||||
|
<item>5</item>
|
||||||
|
<item>6</item>
|
||||||
|
<item>7</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="settings_task_layouts">
|
||||||
|
<item>Simple</item>
|
||||||
|
<item>Detailed</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="settings_task_layout_values" translatable="false">
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="settings_today_actions">
|
||||||
|
<item>Done</item>
|
||||||
|
<item>Delete</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="settings_today_action_values" translatable="false">
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
@@ -69,28 +69,18 @@
|
|||||||
<string name="settings_confirm_markdone">Confirm on done?</string>
|
<string name="settings_confirm_markdone">Confirm on done?</string>
|
||||||
<string name="settings_confirm_delete">Confirm on delete?</string>
|
<string name="settings_confirm_delete">Confirm on delete?</string>
|
||||||
<string name="settings_task_layout">Task layout:</string>
|
<string name="settings_task_layout">Task layout:</string>
|
||||||
<string-array name="settings_task_layouts">
|
|
||||||
<item>Simple</item>
|
|
||||||
<item>Detailed</item>
|
|
||||||
</string-array>
|
|
||||||
<string-array name="settings_task_layout_values" translatable="false">
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
</string-array>
|
|
||||||
<string name="settings_max_lists_label">Maximum number of lists:</string>
|
<string name="settings_max_lists_label">Maximum number of lists:</string>
|
||||||
<string-array name="settings_max_lists_number" translatable="false">
|
|
||||||
<item>1</item>
|
|
||||||
<item>2</item>
|
|
||||||
<item>3</item>
|
|
||||||
<item>4</item>
|
|
||||||
<item>5</item>
|
|
||||||
<item>6</item>
|
|
||||||
<item>7</item>
|
|
||||||
</string-array>
|
|
||||||
<string name="title_activity_task_list">TaskListActivity</string>
|
<string name="title_activity_task_list">TaskListActivity</string>
|
||||||
|
|
||||||
<!-- Strings related to About -->
|
<!-- Strings related to About -->
|
||||||
<string name="about_version_donext">DoNext version %s</string>
|
<string name="about_version_donext">DoNext version %s</string>
|
||||||
<string name="about_version_android">Android version %s</string>
|
<string name="about_version_android">Android version %s</string>
|
||||||
<string name="about_link" translatable="false">https://github.com/wismna</string>
|
<string name="about_link" translatable="false">https://github.com/wismna</string>
|
||||||
|
<string name="settings_today_title">Today list</string>
|
||||||
|
<string name="settings_today_enable">Enable Today list?</string>
|
||||||
|
<string name="settings_today_desc">The Today list is a special kind of list, in which tasks only exist for the current day. Each day, the list is reset.</string>
|
||||||
|
<string name="task_list_today">Today</string>
|
||||||
|
<string name="task_list_today_list_error">Name \"Today\" is reserved. You may activate the Today list from the Settings.</string>
|
||||||
|
<string name="settings_today_action_title">Action at the end of the day</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -35,5 +35,22 @@
|
|||||||
android:entryValues="@array/settings_max_lists_number"
|
android:entryValues="@array/settings_max_lists_number"
|
||||||
android:summary="%s"
|
android:summary="%s"
|
||||||
android:defaultValue="5" />
|
android:defaultValue="5" />
|
||||||
|
<PreferenceScreen
|
||||||
|
android:title="@string/settings_today_title">
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/settings_today_title" />
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="pref_conf_today_enable"
|
||||||
|
android:title="@string/settings_today_enable"
|
||||||
|
android:summary="@string/settings_today_desc"/>
|
||||||
|
<ListPreference
|
||||||
|
android:key="pref_conf_today_action"
|
||||||
|
android:title="@string/settings_today_action_title"
|
||||||
|
android:dialogTitle="@string/settings_today_title"
|
||||||
|
android:entries="@array/settings_today_actions"
|
||||||
|
android:entryValues="@array/settings_today_action_values"
|
||||||
|
android:summary="%s"
|
||||||
|
android:defaultValue="0" />
|
||||||
|
</PreferenceScreen>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Reference in New Issue
Block a user