diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java index ad2dbec..8781d33 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java @@ -28,7 +28,7 @@ import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter; import com.wismna.geoffroy.donext.dao.Task; import com.wismna.geoffroy.donext.dao.TaskList; import com.wismna.geoffroy.donext.database.TaskListDataAccess; -import com.wismna.geoffroy.donext.fragments.TaskDialogFragment; +import com.wismna.geoffroy.donext.fragments.TaskFormDialogFragment; import com.wismna.geoffroy.donext.fragments.TasksFragment; import java.util.List; @@ -183,20 +183,24 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas /** Called when user clicks on the New Task floating button */ public void onNewTaskClick(View view) { int currentTabPosition = mViewPager.getCurrentItem(); - TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(null, + TaskFormDialogFragment taskDialogFragment = TaskFormDialogFragment.newInstance(null, mSectionsPagerAdapter.getAllItems(), (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(currentTabPosition)); - FragmentManager fragmentManager = getSupportFragmentManager(); - // Set current tab value to new task dialog + // Set some configuration values for the tab SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); Bundle args = new Bundle(); args.putInt("list", currentTabPosition); args.putBoolean("layout", mIsLargeLayout); args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false)); + args.putBoolean("neutral", false); + args.putString("button_positive", getString(R.string.new_task_save)); + args.putString("button_negative", getString(R.string.new_task_cancel)); + args.putString("button_neutral", getString(R.string.new_task_delete)); taskDialogFragment.setArguments(args); String title = getString(R.string.action_new_task); + FragmentManager fragmentManager = getSupportFragmentManager(); if (mIsLargeLayout) taskDialogFragment.show(fragmentManager, title); else { diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TodayActivity.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TodayActivity.java index da6d32c..97152a9 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TodayActivity.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TodayActivity.java @@ -1,15 +1,25 @@ package com.wismna.geoffroy.donext.activities; import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import com.wismna.geoffroy.donext.R; +import com.wismna.geoffroy.donext.dao.Task; +import com.wismna.geoffroy.donext.database.TaskDataAccess; +import com.wismna.geoffroy.donext.fragments.TodayFormDialogFragment; -public class TodayActivity extends AppCompatActivity { +import java.util.List; +public class TodayActivity extends AppCompatActivity + implements TodayFormDialogFragment.TodayTaskListener { + + private boolean mIsLargeLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -24,8 +34,43 @@ public class TodayActivity extends AppCompatActivity { // Enable the Up button ab.setDisplayHomeAsUpEnabled(true); } + + mIsLargeLayout = getResources().getBoolean(R.bool.large_layout); } public void onNewTaskClick(View view) { + List tasks; + try(TaskDataAccess taskDataAccess = new TaskDataAccess(this)) { + tasks = taskDataAccess.getAllTasks(); + } + TodayFormDialogFragment taskDialogFragment = + TodayFormDialogFragment.newInstance(tasks, TodayActivity.this); + + // Set some configuration values for the dialog + Bundle args = new Bundle(); + args.putBoolean("layout", mIsLargeLayout); + args.putString("button_positive", getString(R.string.new_task_save)); + args.putString("button_negative", getString(R.string.new_task_cancel)); + taskDialogFragment.setArguments(args); + + String title = getString(R.string.action_today_select); + FragmentManager fragmentManager = getSupportFragmentManager(); + if (mIsLargeLayout) + taskDialogFragment.show(fragmentManager, title); + else { + // The device is smaller, so show the fragment fullscreen + FragmentTransaction transaction = fragmentManager.beginTransaction(); + // For a little polish, specify a transition animation + transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + // To make it fullscreen, use the 'content' root view as the container + // for the fragment, which is always the root view for the activity + transaction.add(android.R.id.content, taskDialogFragment, title) + .addToBackStack(null).commit(); + } + } + + @Override + public void onTodayTaskDialogPositiveClick(DialogFragment dialog, View dialogView) { + } } diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/dao/Task.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/dao/Task.java index 2c30aae..318e824 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/dao/Task.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/dao/Task.java @@ -114,7 +114,7 @@ public class Task { } 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 diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java index 95b171f..787fc3c 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java @@ -87,10 +87,19 @@ public class TaskDataAccess implements AutoCloseable { contentValues.put(column, 1); return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.TASKS_COLUMN_DUEDATE + " <= date('now','-1 day')" + - " AND " + DatabaseHelper.TASKS_COLUMN_LIST + " = " + taskListId, null); + " AND " + DatabaseHelper.TASKS_COLUMN_LIST + " = " + taskListId, null); } - public List getAllTasks(long id) { + public List getAllTasks() { + Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns, + 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); + } + + public List getAllTasksFromList(long id) { Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns, DatabaseHelper.TASKS_COLUMN_LIST + " = " + id + " AND " + DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 + diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java new file mode 100644 index 0000000..ef3317d --- /dev/null +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java @@ -0,0 +1,184 @@ +package com.wismna.geoffroy.donext.fragments; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; + +import com.wismna.geoffroy.donext.R; + +/** + * 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 + * a full screen fragment in smaller layouts. + */ + +public abstract class DynamicDialogFragment extends DialogFragment { + private View mDialogView = null; + protected boolean mHasNeutralButton = false; + protected boolean mIsLargeLayout = false; + protected Fragment mContentFragment = new Fragment(); + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + // This part is only needed on small layouts (large layouts use onCreateDialog) + if (!mIsLargeLayout) { + View view = inflater.inflate(R.layout.fragment_dynamic_dialog, container, false); + AppCompatActivity activity = (AppCompatActivity) getActivity(); + activity.setSupportActionBar(setToolbarTitle(view)); + + ActionBar actionBar = activity.getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + actionBar.setHomeAsUpIndicator(android.R.drawable.ic_menu_close_clear_cancel); + } + setHasOptionsMenu(true); + setContentFragment(); + return view; + } + //return super.onCreateView(inflater, container, savedInstanceState); + // Returns the saved view from Dialog Builder on large screens + return mDialogView; + } + + @Override + @NonNull + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Inflate and set the layout for the dialog + LayoutInflater inflater = getActivity().getLayoutInflater(); + // As it is a Dialog, the root ViewGroup can be null without issues + @SuppressLint("InflateParams") final View view = inflater.inflate(R.layout.fragment_dynamic_dialog, null); + setToolbarTitle(view); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + Bundle args = getArguments(); + // Pass null as the parent view because its going in the dialog layout + builder.setView(view) + // Add action buttons + .setPositiveButton(args.getString("button_positive"), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + onPositiveButtonClick(view); + } + }) + .setNegativeButton(args.getString("button_negative"), new DialogInterface.OnClickListener() { + 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(); + } + }); + if (mHasNeutralButton) { + builder.setNeutralButton(args.getString("button_neutral"), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + onNeutralButtonClick(view); + } + }); + } + setContentFragment(); + // Save the View so that it can returned by onCreateView + // (otherwise it is null and it poses problems when committing child fragment transactions) + mDialogView = view; + return builder.create(); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + //super.onCreateOptionsMenu(menu, inflater); + menu.clear(); + getActivity().getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + // Show the neutral button if needed + if (!mHasNeutralButton) { + menu.removeItem(R.id.menu_neutral_button); + } + super.onPrepareOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Determine which menu item was clicked + int id = item.getItemId(); + View view = getView(); + + // Hide the keyboard if present + if (view != null) { + InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); + } + if (id == R.id.menu_positive_button) { + // Handle positive button click here + onPositiveButtonClick(view); + return true; + } + else if (id == R.id.menu_neutral_button) { + // Handle neutral button click here + onNeutralButtonClick(view); + return true; + } + else if (id == android.R.id.home) { + // Handle negative button click here + onNegativeButtonClick(); + return true; + } + + return super.onOptionsItemSelected(item); + } + + @Override + public void onDestroyView() { + Dialog dialog = getDialog(); + // Stop the dialog from being dismissed on rotation, due to a bug with the compatibility library + // https://code.google.com/p/android/issues/detail?id=17423 + if (dialog != null && getRetainInstance()) { + dialog.setDismissMessage(null); + } + super.onDestroyView(); + } + + private void setContentFragment() { + // Get the child fragment manager (and not the "normal" one) + FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); + + // Set the actual content of the fragment + transaction.replace(R.id.dynamic_fragment_content, mContentFragment); + + // Commit the transaction instantly + transaction.commitNow(); + } + + /** Sets the title of the Fragment from the Tag */ + private Toolbar setToolbarTitle(View view) { + Toolbar toolbar = (Toolbar) view.findViewById(R.id.dialog_toolbar); + toolbar.setTitle(getTag()); + return toolbar; + } + + protected abstract void onPositiveButtonClick(View view); + + protected abstract void onNeutralButtonClick(View view); + + protected abstract void onNegativeButtonClick(); +} diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskDialogFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskDialogFragment.java index 8667c21..86af339 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskDialogFragment.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskDialogFragment.java @@ -38,6 +38,7 @@ import java.util.List; * Created by geoffroy on 15-11-26. * Represents a New or Edit Task dialog */ +@Deprecated public class TaskDialogFragment extends DialogFragment { public Task getTask() { @@ -128,13 +129,13 @@ public class TaskDialogFragment extends DialogFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { //super.onCreateOptionsMenu(menu, inflater); menu.clear(); - getActivity().getMenuInflater().inflate(R.menu.menu_new_task, menu); + getActivity().getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu); } @Override public void onPrepareOptionsMenu(Menu menu) { if (task == null) { - menu.removeItem(R.id.menu_new_task_delete); + menu.removeItem(R.id.menu_neutral_button); } super.onPrepareOptionsMenu(menu); } @@ -150,12 +151,12 @@ public class TaskDialogFragment extends DialogFragment { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); } - if (id == R.id.menu_new_task_save) { + if (id == R.id.menu_positive_button) { // handle save button click here onPositiveButtonClick(view); return true; } - else if (id == R.id.menu_new_task_delete) { + else if (id == R.id.menu_neutral_button) { // handle delete button click here onNeutralButtonClick(); return true; @@ -227,7 +228,7 @@ public class TaskDialogFragment extends DialogFragment { } private Toolbar setToolbarTitle(View view) { - Toolbar toolbar = (Toolbar) view.findViewById(R.id.new_task_toolbar); + Toolbar toolbar = (Toolbar) view.findViewById(R.id.dialog_toolbar); toolbar.setTitle(getTag()); return toolbar; } diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormContentFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormContentFragment.java new file mode 100644 index 0000000..f004884 --- /dev/null +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormContentFragment.java @@ -0,0 +1,23 @@ +package com.wismna.geoffroy.donext.fragments; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.wismna.geoffroy.donext.R; + +/** + * Created by bg45 on 2017-03-21. + * Content fragment for the Task Form Dialog fragment. + */ + +public class TaskFormContentFragment extends Fragment { + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.content_task_form, container, false); + } +} diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java new file mode 100644 index 0000000..03b0589 --- /dev/null +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java @@ -0,0 +1,142 @@ +package com.wismna.geoffroy.donext.fragments; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.SeekBar; +import android.widget.Spinner; +import android.widget.TextView; + +import com.wismna.geoffroy.donext.R; +import com.wismna.geoffroy.donext.dao.Task; +import com.wismna.geoffroy.donext.dao.TaskList; + +import org.joda.time.LocalDate; + +import java.util.List; + +/** + * Created by bg45 on 2017-03-21. + * This is Task Form dynamic dialog fragment + */ + +public class TaskFormDialogFragment extends DynamicDialogFragment { + public Task getTask() { + return task; + } + + /** The activity that creates an instance of this dialog fragment must + * implement this interface in order to receive event callbacks. + * Each method passes the DialogFragment in case the host needs to query it. */ + interface NewTaskListener { + void onNewTaskDialogPositiveClick(DialogFragment dialog, View dialogView); + void onNewTaskDialogNeutralClick(DialogFragment dialog); + } + + private TaskFormDialogFragment.NewTaskListener mListener; + private Task task; + private List taskLists; + + public static TaskFormDialogFragment newInstance(Task task, List taskLists, NewTaskListener newTaskListener) { + TaskFormDialogFragment fragment = new TaskFormDialogFragment(); + fragment.task = task; + fragment.taskLists = taskLists; + fragment.mListener = newTaskListener; + fragment.setRetainInstance(true); + return fragment; + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mContentFragment = new TaskFormContentFragment(); + Bundle args = getArguments(); + if (args != null) { + mIsLargeLayout = args.getBoolean("layout"); + mHasNeutralButton = args.getBoolean("neutral"); + } + } + + @Override + public void onStart() { + 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(getView()); + } + + @Override + protected void onPositiveButtonClick(View view) { + if (view == null) return; + EditText titleText = (EditText) view.findViewById(R.id.new_task_name); + // handle confirmation button click hereEditText titleText = (EditText) d.findViewById(R.id.new_task_name); + if (titleText.getText().toString().matches("")) + titleText.setError(getResources().getString(R.string.new_task_name_error)); + else { + // Send the positive button event back to the host activity + mListener.onNewTaskDialogPositiveClick(TaskFormDialogFragment.this, view); + dismiss(); + } + } + + @Override + protected void onNeutralButtonClick(View view) { + mListener.onNewTaskDialogNeutralClick(TaskFormDialogFragment.this); + } + + @Override + protected void onNegativeButtonClick() { + dismiss(); + } + + private void setTaskValues(View view) { + // Get date picker + final DatePicker dueDatePicker = (DatePicker) view.findViewById(R.id.new_task_due_date); + + // Populate spinner with task lists + Spinner spinner = (Spinner) view.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); + // Specify the layout to use when the list of choices appears + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + + // Auto set list value to current tab + Bundle args = getArguments(); + int id = args.getInt("list"); + spinner.setSelection(id); + + CheckBox checkBox = (CheckBox) view.findViewById(R.id.new_task_today); + TextView todayLabel = (TextView) view.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); + + // Set other properties if they exist + if (task != null) { + + EditText titleText = (EditText) view.findViewById(R.id.new_task_name); + titleText.setText(task.getName()); + EditText descText = (EditText) view.findViewById(R.id.new_task_description); + descText.setText(task.getDescription()); + SeekBar seekBar = (SeekBar) view.findViewById(R.id.new_task_priority); + seekBar.setProgress(task.getPriority()); + + // Set Due Date + LocalDate dueDate = task.getDueDate(); + dueDatePicker.updateDate(dueDate.getYear(), dueDate.getMonthOfYear() - 1, dueDate.getDayOfMonth()); + + checkBox.setChecked(task.isToday()); + } + else { + // Disallow past dates on new tasks + dueDatePicker.setMinDate(LocalDate.now().toDate().getTime()); + } + } +} diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java index 6d593e2..605fb94 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java @@ -44,7 +44,7 @@ import java.util.List; * A fragment representing a list of Items. */ public class TasksFragment extends Fragment implements - TaskDialogFragment.NewTaskListener, + TaskFormDialogFragment.NewTaskListener, ConfirmDialogFragment.ConfirmDialogListener, TaskTouchHelper.TaskTouchHelperAdapter { @@ -106,7 +106,7 @@ public class TasksFragment extends Fragment implements // Get all tasks try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext())) { taskRecyclerViewAdapter = new TaskRecyclerViewAdapter( - isTodayView? taskDataAccess.getTodayTasks() : taskDataAccess.getAllTasks(taskListId), + isTodayView? taskDataAccess.getTodayTasks() : taskDataAccess.getAllTasksFromList(taskListId), Integer.valueOf(sharedPref.getString("pref_conf_task_layout", "1"))); } recyclerView.setAdapter(taskRecyclerViewAdapter); @@ -126,6 +126,10 @@ public class TasksFragment extends Fragment implements args.putInt("position", position); args.putBoolean("layout", mIsLargeLayout); args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false)); + args.putBoolean("neutral", true); + args.putString("button_positive", getString(R.string.new_task_save)); + args.putString("button_negative", getString(R.string.new_task_cancel)); + args.putString("button_neutral", getString(R.string.new_task_delete)); // Set current tab value to new task dialog ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.container); @@ -149,7 +153,7 @@ public class TasksFragment extends Fragment implements } FragmentManager manager = getFragmentManager(); - TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance( + TaskFormDialogFragment taskDialogFragment = TaskFormDialogFragment.newInstance( task, taskLists, TasksFragment.this); taskDialogFragment.setArguments(args); @@ -335,7 +339,7 @@ public class TasksFragment extends Fragment implements // Get the dialog fragment if (dialogView == null) return; long id = 0; - Task task = ((TaskDialogFragment)dialog).getTask(); + Task task = ((TaskFormDialogFragment)dialog).getTask(); if (task != null) id = task.getId(); // Get the controls @@ -346,7 +350,7 @@ public class TasksFragment extends Fragment implements DatePicker dueDatePicker = (DatePicker) dialogView.findViewById(R.id.new_task_due_date); TaskList taskList = (TaskList) listSpinner.getSelectedItem(); CheckBox todayList = (CheckBox) dialogView.findViewById(R.id.new_task_today); - + boolean isToday = todayList.isChecked(); // Add the task to the database try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext(), TaskDataAccess.MODE.WRITE)) { Task newTask = taskDataAccess.createOrUpdateTask(id, @@ -355,7 +359,7 @@ public class TasksFragment extends Fragment implements seekBar.getProgress(), taskList.getId(), new LocalDate(dueDatePicker.getYear(), dueDatePicker.getMonth() + 1, dueDatePicker.getDayOfMonth()), - todayList.isChecked()); + isToday); Bundle args = dialog.getArguments(); // Should never happen because we will have to be on this tab to open the dialog @@ -377,15 +381,16 @@ public class TasksFragment extends Fragment implements else { int position = args.getInt("position"); // Check if task list was changed - if (mAdapter != null && task.getTaskListId() != taskList.getId()) + if ((isTodayView && !isToday) || (!isTodayView && task.getTaskListId() != taskList.getId())) { // Remove item from current tab taskRecyclerViewAdapter.remove(position); - //UpdateCycleCount(); // Add it to the corresponding tab provided it is already instantiated - mAdapter.onTaskListChanged(newTask, listSpinner.getSelectedItemPosition()); - } else taskRecyclerViewAdapter.update(newTask, position); + if (mAdapter != null) mAdapter.onTaskListChanged(newTask, listSpinner.getSelectedItemPosition()); + } else { + taskRecyclerViewAdapter.update(newTask, position); + } } } } diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormContentFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormContentFragment.java new file mode 100644 index 0000000..5bb0951 --- /dev/null +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormContentFragment.java @@ -0,0 +1,23 @@ +package com.wismna.geoffroy.donext.fragments; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.wismna.geoffroy.donext.R; + +/** + * Created by bg45 on 2017-03-21. + * Contains the Today Form contents. + */ + +public class TodayFormContentFragment extends Fragment { + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.content_today_form, container, false); + } +} diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormDialogFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormDialogFragment.java new file mode 100644 index 0000000..1252196 --- /dev/null +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TodayFormDialogFragment.java @@ -0,0 +1,105 @@ +package com.wismna.geoffroy.donext.fragments; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.EditText; +import android.widget.ListView; + +import com.wismna.geoffroy.donext.R; +import com.wismna.geoffroy.donext.dao.Task; + +import java.util.List; + +/** + * Created by bg45 on 2017-03-21. + * This is the Today Form dynamic dialog fragment + */ + +public class TodayFormDialogFragment extends DynamicDialogFragment { + /** The activity that creates an instance of this dialog fragment must + * implement this interface in order to receive event callbacks. + * Each method passes the DialogFragment in case the host needs to query it. */ + public interface TodayTaskListener { + void onTodayTaskDialogPositiveClick(DialogFragment dialog, View dialogView); + } + + private TodayFormDialogFragment.TodayTaskListener mListener; + private List tasks; + + public static TodayFormDialogFragment newInstance(List tasks, TodayTaskListener todayTaskListener) { + TodayFormDialogFragment fragment = new TodayFormDialogFragment(); + fragment.tasks = tasks; + fragment.mListener = todayTaskListener; + fragment.setRetainInstance(true); + return fragment; + } + + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mContentFragment = new TodayFormContentFragment(); + Bundle args = getArguments(); + if (args != null) { + mIsLargeLayout = args.getBoolean("layout"); + } + } + + @Override + public void onStart() { + super.onStart(); + setLayoutValues(getView()); + } + + private void setLayoutValues(View view) { + EditText editText = (EditText) view.findViewById(R.id.today_search); + ListView listView = (ListView) view.findViewById(R.id.today_tasks); + final ArrayAdapter adapter = new ArrayAdapter<>(getActivity(), R.layout.list_task_item, tasks); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + // Set as selected + Task task = tasks.get(position); + view.setSelected(!view.isSelected()); + } + }); + editText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + adapter.getFilter().filter(s); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + } + + @Override + protected void onPositiveButtonClick(View view) { + mListener.onTodayTaskDialogPositiveClick(TodayFormDialogFragment.this, view); + } + + @Override + protected void onNeutralButtonClick(View view) { + + } + + @Override + protected void onNegativeButtonClick() { + dismiss(); + } +} diff --git a/DoNExt/app/src/main/res/layout/content_task_form.xml b/DoNExt/app/src/main/res/layout/content_task_form.xml new file mode 100644 index 0000000..8d362dc --- /dev/null +++ b/DoNExt/app/src/main/res/layout/content_task_form.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DoNExt/app/src/main/res/layout/content_today_form.xml b/DoNExt/app/src/main/res/layout/content_today_form.xml new file mode 100644 index 0000000..c1ed20f --- /dev/null +++ b/DoNExt/app/src/main/res/layout/content_today_form.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file diff --git a/DoNExt/app/src/main/res/layout/fragment_dynamic_dialog.xml b/DoNExt/app/src/main/res/layout/fragment_dynamic_dialog.xml new file mode 100644 index 0000000..28ea834 --- /dev/null +++ b/DoNExt/app/src/main/res/layout/fragment_dynamic_dialog.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/DoNExt/app/src/main/res/layout/fragment_task_form.xml b/DoNExt/app/src/main/res/layout/fragment_task_form.xml index b5ce149..cec27bf 100644 --- a/DoNExt/app/src/main/res/layout/fragment_task_form.xml +++ b/DoNExt/app/src/main/res/layout/fragment_task_form.xml @@ -11,7 +11,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> - + + \ No newline at end of file diff --git a/DoNExt/app/src/main/res/menu/menu_new_task.xml b/DoNExt/app/src/main/res/menu/menu_dynamic_fragment.xml similarity index 82% rename from DoNExt/app/src/main/res/menu/menu_new_task.xml rename to DoNExt/app/src/main/res/menu/menu_dynamic_fragment.xml index 42d8e5d..f379ab3 100644 --- a/DoNExt/app/src/main/res/menu/menu_new_task.xml +++ b/DoNExt/app/src/main/res/menu/menu_dynamic_fragment.xml @@ -2,12 +2,12 @@ diff --git a/DoNExt/app/src/main/res/values-fr/strings.xml b/DoNExt/app/src/main/res/values-fr/strings.xml index a0915dc..ea6410b 100644 --- a/DoNExt/app/src/main/res/values-fr/strings.xml +++ b/DoNExt/app/src/main/res/values-fr/strings.xml @@ -70,4 +70,6 @@ Vue Aujourd\'hui Aujourd\'hui Ajouter la tâche à la vue Aujourd\'hui? + Rechercher... + Choisissez des tâches \ No newline at end of file diff --git a/DoNExt/app/src/main/res/values/strings.xml b/DoNExt/app/src/main/res/values/strings.xml index c610eff..1ccbe87 100644 --- a/DoNExt/app/src/main/res/values/strings.xml +++ b/DoNExt/app/src/main/res/values/strings.xml @@ -89,4 +89,9 @@ Today Add task to Today View? Main2Activity + + + Hello blank fragment + Search... + Select tasks