mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 07:30:13 -04:00
New DynamicDialogFragment abstract class for dialogs
New fragment extending DynamicDialogFragment for Task Form New fragment extending DynamicDialogFragment for Today Form (WIP) Bug corrections related to the above
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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<Task> 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) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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<Task> getAllTasks(long id) {
|
||||
public List<Task> 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<Task> getAllTasksFromList(long id) {
|
||||
Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns,
|
||||
DatabaseHelper.TASKS_COLUMN_LIST + " = " + id +
|
||||
" AND " + DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 +
|
||||
|
@@ -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();
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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<TaskList> taskLists;
|
||||
|
||||
public static TaskFormDialogFragment newInstance(Task task, List<TaskList> 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<TaskList> 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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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<Task> tasks;
|
||||
|
||||
public static TodayFormDialogFragment newInstance(List<Task> 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<Task> 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();
|
||||
}
|
||||
}
|
96
DoNExt/app/src/main/res/layout/content_task_form.xml
Normal file
96
DoNExt/app/src/main/res/layout/content_task_form.xml
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:background="@android:color/background_light">
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/text_margin"
|
||||
android:orientation="vertical"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
tools:context=".activities.MainActivity">
|
||||
<TextView
|
||||
android:id="@+id/new_task_list_label"
|
||||
android:text="@string/new_task_list"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_marginTop="3dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<Spinner
|
||||
android:id="@+id/new_task_list"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_toEndOf="@id/new_task_list_label">
|
||||
</Spinner>
|
||||
<EditText
|
||||
android:id="@+id/new_task_name"
|
||||
android:hint="@string/new_task_name_hint"
|
||||
android:maxLines="1"
|
||||
android:inputType="text"
|
||||
android:textSize="30sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/new_task_list"/>
|
||||
<EditText
|
||||
android:id="@+id/new_task_description"
|
||||
android:hint="@string/new_task_description_hint"
|
||||
android:gravity="top|start"
|
||||
android:lines="3"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/new_task_name" />
|
||||
<TextView
|
||||
android:id="@+id/new_task_priority_label"
|
||||
android:text="@string/new_task_priority"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_below="@id/new_task_description" />
|
||||
<SeekBar
|
||||
android:id="@+id/new_task_priority"
|
||||
android:max="2"
|
||||
android:progress="1"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_toEndOf="@id/new_task_priority_label"
|
||||
android:layout_below="@id/new_task_description" />
|
||||
<TextView
|
||||
android:id="@+id/new_task_today_label"
|
||||
android:text="@string/new_task_today"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_below="@id/new_task_priority" />
|
||||
<CheckBox
|
||||
android:id="@+id/new_task_today"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/new_task_today_label"
|
||||
android:layout_below="@id/new_task_priority" />
|
||||
<TextView
|
||||
android:id="@+id/new_task_due_date_label"
|
||||
android:text="@string/new_task_due_date"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_below="@id/new_task_today" />
|
||||
<DatePicker
|
||||
android:id="@+id/new_task_due_date"
|
||||
android:datePickerMode="spinner"
|
||||
android:calendarViewShown="false"
|
||||
android:spinnersShown="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/new_task_due_date_label" />
|
||||
</RelativeLayout>
|
||||
</ScrollView>
|
23
DoNExt/app/src/main/res/layout/content_today_form.xml
Normal file
23
DoNExt/app/src/main/res/layout/content_today_form.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:background="@android:color/background_light" >
|
||||
<EditText
|
||||
android:id="@+id/today_search"
|
||||
android:hint="@string/today_search_hint"
|
||||
android:maxLines="1"
|
||||
android:inputType="text"
|
||||
android:textSize="30sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<ListView
|
||||
android:id="@+id/today_tasks"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textFilterEnabled="true">
|
||||
|
||||
</ListView>
|
||||
</LinearLayout>
|
18
DoNExt/app/src/main/res/layout/fragment_dynamic_dialog.xml
Normal file
18
DoNExt/app/src/main/res/layout/fragment_dynamic_dialog.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
<include layout="@layout/toolbar" android:id="@+id/dialog_toolbar" />
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
<FrameLayout
|
||||
android:id="@+id/dynamic_fragment_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
@@ -11,7 +11,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
<include layout="@layout/toolbar" android:id="@+id/new_task_toolbar" />
|
||||
<include layout="@layout/toolbar" android:id="@+id/dialog_toolbar" />
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<ScrollView
|
||||
|
7
DoNExt/app/src/main/res/layout/list_task_item.xml
Normal file
7
DoNExt/app/src/main/res/layout/list_task_item.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="20dp"
|
||||
android:textSize="20sp" />
|
@@ -2,12 +2,12 @@
|
||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/menu_new_task_save"
|
||||
android:id="@+id/menu_positive_button"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/new_task_save"
|
||||
app:showAsAction="always"/>
|
||||
<item
|
||||
android:id="@+id/menu_new_task_delete"
|
||||
android:id="@+id/menu_neutral_button"
|
||||
android:orderInCategory="50"
|
||||
android:title="@string/new_task_delete"
|
||||
app:showAsAction="ifRoom"/>
|
@@ -70,4 +70,6 @@
|
||||
<string name="action_todayList">Vue Aujourd\'hui</string>
|
||||
<string name="title_activity_today">Aujourd\'hui</string>
|
||||
<string name="new_task_today">Ajouter la tâche à la vue Aujourd\'hui?</string>
|
||||
<string name="today_search_hint">Rechercher...</string>
|
||||
<string name="action_today_select">Choisissez des tâches</string>
|
||||
</resources>
|
@@ -89,4 +89,9 @@
|
||||
<string name="title_activity_today">Today</string>
|
||||
<string name="new_task_today">Add task to Today View?</string>
|
||||
<string name="title_activity_main2">Main2Activity</string>
|
||||
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
<string name="today_search_hint">Search...</string>
|
||||
<string name="action_today_select">Select tasks</string>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user