Lots of code cleanup

Confirm dialog cancel now also works on touch outside and click back button
New task dialog is now also an Edit Task dialog:
 - data is loaded when clicked on an existing  Task
 - a delete button is added on Edit mode
 - Undo in snackbar is working
 - Saving inserts or updates in DB depending on mode
This commit is contained in:
2015-12-16 23:48:58 -05:00
parent 8386a136b5
commit 239e34d9fd
22 changed files with 161 additions and 266 deletions

View File

@@ -1,6 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="geoffroy">
<words>
<w>geoffroy</w>
<w>wismna</w>
</words>
</dictionary>

View File

@@ -34,14 +34,6 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
<activity
android:name=".activities.TaskDetailsActivity"
android:label="@string/task_details_activity_title"
android:parentActivityName=".activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
</application>
</manifest>

View File

@@ -17,6 +17,7 @@ import com.wismna.geoffroy.donext.fragments.ConfirmDialogFragment;
/**
* Created by geoffroy on 15-12-04.
* Helper class that handles all swipe events on a Task
*/
public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback {
private TaskAdapter taskAdapter;

View File

@@ -16,7 +16,6 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -33,13 +32,13 @@ import com.wismna.geoffroy.donext.dao.TaskList;
import com.wismna.geoffroy.donext.database.TaskDataAccess;
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
import com.wismna.geoffroy.donext.fragments.ConfirmDialogFragment;
import com.wismna.geoffroy.donext.fragments.NewTaskFragment;
import com.wismna.geoffroy.donext.fragments.TaskDialogFragment;
import com.wismna.geoffroy.donext.fragments.TasksFragment;
import java.util.List;
public class MainActivity extends AppCompatActivity implements
NewTaskFragment.NewTaskListener,
TaskDialogFragment.NewTaskListener,
TasksFragment.OnListFragmentInteractionListener,
ConfirmDialogFragment.ConfirmDialogListener
{
@@ -53,13 +52,11 @@ public class MainActivity extends AppCompatActivity implements
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
private List<TaskList> taskLists;
@Override
@@ -72,7 +69,7 @@ public class MainActivity extends AppCompatActivity implements
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Access database to retrieve tasks
taskDataAccess = new TaskDataAccess(this);
@@ -148,6 +145,8 @@ public class MainActivity extends AppCompatActivity implements
public void onNewTaskDialogPositiveClick(DialogFragment dialog) {
// Get the dialog fragment
Dialog dialogView = dialog.getDialog();
Bundle args = dialog.getArguments();
long id = args.getLong("id");
// Get the controls
Spinner listSpinner = (Spinner) dialogView.findViewById(R.id.new_task_list);
EditText nameText = (EditText) dialogView.findViewById(R.id.new_task_name);
@@ -156,17 +155,64 @@ public class MainActivity extends AppCompatActivity implements
RadioButton priorityRadio = (RadioButton) dialogView.findViewById(priorityGroup.getCheckedRadioButtonId());
TaskList taskList = (TaskList) listSpinner.getSelectedItem();
// Add the task to the database
Task task = taskDataAccess.createOrUpdateTask(
taskDataAccess.open();
Task task = taskDataAccess.createOrUpdateTask(id,
nameText.getText().toString(),
descText.getText().toString(),
priorityRadio.getText().toString(),
taskList.getId());
taskDataAccess.close();
// Update the corresponding tab adapter
TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(listSpinner.getSelectedItemPosition());
TaskAdapter taskAdapter = ((TaskAdapter)((RecyclerView)taskFragment.getView().findViewById(R.id.task_list_view)).getAdapter());
taskAdapter.add(task, taskAdapter.getItemCount());
//TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(listSpinner.getSelectedItemPosition());
//TaskAdapter taskAdapter = ((TaskAdapter)((RecyclerView)taskFragment.getView().findViewById(R.id.task_list_view)).getAdapter());
TaskAdapter taskAdapter = ((TaskDialogFragment)dialog).getTaskAdapter();
// Add the task
if (id == 0)
taskAdapter.add(task, taskAdapter.getItemCount());
// Update the task
else
taskAdapter.update(task, args.getInt("position"));
}
@Override
public void onNewTaskDialogNeutralClick(DialogFragment dialog) {
// TODO: add confirm dialog
TaskDialogFragment taskDialogFragment = (TaskDialogFragment) dialog;
Bundle args = dialog.getArguments();
final long id = args.getLong("id");
// Delete task from Adapter
final int position = args.getInt("position");
final TaskAdapter taskAdapter = taskDialogFragment.getTaskAdapter();
final Task task = taskAdapter.getItem(position);
taskAdapter.remove(position);
// Setup the snack bar
final View view = taskDialogFragment.getRecyclerView();
Snackbar.make(view, "Task deleted", Snackbar.LENGTH_LONG)
.setAction("Undo", new View.OnClickListener() {
@Override
public void onClick(View v) {
// Undo adapter changes
taskAdapter.add(task, position);
((RecyclerView)view).scrollToPosition(position);
}
}).setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
// When clicked on undo, do not write to DB
if (event == DISMISS_EVENT_ACTION) return;
// Commit the changes to DB
taskDataAccess.open();
taskDataAccess.deleteTask(id);
taskDataAccess.close();
}
}).show();
}
/** Called when user clicks on the New Task floating button */
public void onNewTaskClick(View view) {
OpenNewTaskDialog();
@@ -182,17 +228,6 @@ public class MainActivity extends AppCompatActivity implements
startActivity(intent);
}
/** Called when the user clicks the New Task button */
public void openNewTaskDialog(MenuItem menuItem) {
OpenNewTaskDialog();
}
/** Will be called when the delete Task button is clicked */
public void onDeleteTask(View view) {
RecyclerView recyclerView = (RecyclerView) view;
}
@Override
public void onListFragmentInteraction(Task item) {
@@ -209,7 +244,7 @@ public class MainActivity extends AppCompatActivity implements
}
@Override
public void onConfirmDialogNeutralClick(android.support.v4.app.DialogFragment dialog) {
public void onConfirmDialogNeutralClick(DialogFragment dialog) {
Bundle args = dialog.getArguments();
int itemPosition = args.getInt("ItemPosition");
int direction = args.getInt("Direction");
@@ -234,31 +269,16 @@ public class MainActivity extends AppCompatActivity implements
PerformSwipeAction(taskDataAccess, taskAdapter, itemPosition, direction, ((ConfirmDialogFragment) dialog).getRecyclerView());
}
@Override
public void onConfirmDialogNegativeClick(android.support.v4.app.DialogFragment dialog) {
Bundle args = dialog.getArguments();
int itemPosition = args.getInt("ItemPosition");
TaskAdapter taskAdapter = ((ConfirmDialogFragment)dialog).getTaskAdapter();
taskAdapter.notifyItemChanged(itemPosition);
}
@Override
public boolean onConfirmDialogKeyListener(android.support.v4.app.DialogFragment dialog, int keyCode, KeyEvent event) {
onConfirmDialogNegativeClick(dialog);
return keyCode != KeyEvent.KEYCODE_BACK;
}
private void OpenNewTaskDialog() {
FragmentManager manager = getSupportFragmentManager();
NewTaskFragment newTaskFragment = new NewTaskFragment();
TaskDialogFragment taskDialogFragment = new TaskDialogFragment();
// Set current tab value to new task dialog
Bundle args = new Bundle();
args.putInt("list", mViewPager.getCurrentItem());
newTaskFragment.setArguments(args);
taskDialogFragment.setArguments(args);
newTaskFragment.show(manager, "Create new task");
taskDialogFragment.show(manager, "Create new task");
}
public static void PerformSwipeAction(final TaskDataAccess taskDataAccess,

View File

@@ -1,15 +0,0 @@
package com.wismna.geoffroy.donext.activities;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.wismna.geoffroy.donext.R;
public class TaskDetailsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task_details);
}
}

View File

@@ -2,6 +2,9 @@ package com.wismna.geoffroy.donext.adapters;
/**
* Created by geoffroy on 15-11-28.
* Extension of FragmentStatePagerAdapter which intelligently caches
* all active fragments and manages the fragment lifecycles.
* Usage involves extending from SmartFragmentStatePagerAdapter as you would any other PagerAdapter.
*/
import android.support.v4.app.Fragment;
@@ -10,11 +13,6 @@ import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.SparseArray;
import android.view.ViewGroup;
/**
Extension of FragmentStatePagerAdapter which intelligently caches
all active fragments and manages the fragment lifecycles.
Usage involves extending from SmartFragmentStatePagerAdapter as you would any other PagerAdapter.
*/
public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
// Sparse array to keep track of registered fragments in memory
private SparseArray<Fragment> registeredFragments = new SparseArray<>();

View File

@@ -33,8 +33,7 @@ public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.ViewHolder> {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_task, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
return new ViewHolder(view);
}
@Override
@@ -84,7 +83,6 @@ public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.ViewHolder> {
}
public void remove(int position) {
//int position = mValues.indexOf(item);
mValues.remove(position);
notifyItemRemoved(position);
}

View File

@@ -13,6 +13,7 @@ import com.wismna.geoffroy.donext.database.DatabaseHelper;
/**
* Created by geoffroy on 15-11-25.
* DEPRECATED
*/
public class TaskListCursorAdapter extends ResourceCursorAdapter {
public TaskListCursorAdapter(Context context, int layout, Cursor cursor, int flags) {

View File

@@ -2,6 +2,7 @@ package com.wismna.geoffroy.donext.dao;
/**
* Created by geoffroy on 15-11-25.
* Data access object class that represents a Task
*/
public class Task {
private long id;
@@ -14,18 +15,6 @@ public class Task {
private long taskList;
private String taskListName;
public enum TaskPriority {
LOW(0),
NORMAL(1),
HIGH(2);
private int value;
private TaskPriority(int value) {
this.value = value;
}
}
public long getId() {
return id;
}

View File

@@ -2,6 +2,7 @@ package com.wismna.geoffroy.donext.dao;
/**
* Created by geoffroy on 15-11-25.
* Data access object class that represents a Task List
*/
public class TaskList {
private long id;
@@ -24,14 +25,6 @@ public class TaskList {
this.name = comment;
}
public long getTaskCount() {
return taskCount;
}
public void setTaskCount(long taskCount) {
this.taskCount = taskCount;
}
// Will be used by the ArrayAdapter in the ListView
@Override
public String toString() {

View File

@@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteOpenHelper;
/**
* Created by geoffroy on 15-11-25.
* Database helper class that contains table and column names as well as handles database creation
*/
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;

View File

@@ -14,6 +14,7 @@ import java.util.List;
/**
* Created by geoffroy on 15-11-27.
* Data access class that handles Tasks
*/
public class TaskDataAccess {
private SQLiteDatabase database;
@@ -41,15 +42,20 @@ public class TaskDataAccess {
dbHelper.close();
}
// TODO: add taskID
public Task createOrUpdateTask(String name, String description, String priority, long taskList) {
/** Adds or update a task in the database */
public Task createOrUpdateTask(long id, String name, String description, String priority, long taskList) {
ContentValues values = new ContentValues();
values.put(DatabaseHelper.TASKS_COLUMN_NAME, name);
values.put(DatabaseHelper.TASKS_COLUMN_DESC, description);
values.put(DatabaseHelper.TASKS_COLUMN_PRIORITY, priorities.indexOf(priority));
values.put(DatabaseHelper.TASKS_COLUMN_LIST, taskList);
long insertId = database.insert(DatabaseHelper.TASKS_TABLE_NAME, null, values);
long insertId;
if (id == 0)
insertId = database.insert(DatabaseHelper.TASKS_TABLE_NAME, null, values);
else {
database.update(DatabaseHelper.TASKS_TABLE_NAME, values, DatabaseHelper.COLUMN_ID + " == " + id, null);
insertId = id;
}
Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME,
taskColumns, DatabaseHelper.COLUMN_ID + " = " + insertId, null,
null, null, null);
@@ -60,7 +66,8 @@ public class TaskDataAccess {
}
public void deleteTask(long taskId) {
database.delete(DatabaseHelper.TASKS_TABLE_NAME,
DatabaseHelper.COLUMN_ID + " = " + taskId, null);
}
/*public Cursor deleteTask(Cursor taskCursor) {

View File

@@ -13,12 +13,13 @@ import java.util.List;
/**
* Created by geoffroy on 15-11-25.
* Data access class that handles Task Lists
*/
public class TaskListDataAccess {
// Database fields
private SQLiteDatabase database;
private DatabaseHelper dbHelper;
private String[] taskListColumns = {DatabaseHelper.COLUMN_ID, DatabaseHelper.TASKLIST_COLUMN_NAME};
//private String[] taskListColumns = {DatabaseHelper.COLUMN_ID, DatabaseHelper.TASKLIST_COLUMN_NAME};
public TaskListDataAccess(Context context) {
dbHelper = new DatabaseHelper(context);

View File

@@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
@@ -16,8 +17,6 @@ public class ConfirmDialogFragment extends DialogFragment {
public interface ConfirmDialogListener {
void onConfirmDialogPositiveClick(DialogFragment dialog);
void onConfirmDialogNeutralClick(DialogFragment dialog);
void onConfirmDialogNegativeClick(DialogFragment dialog);
boolean onConfirmDialogKeyListener(DialogFragment dialog, int keyCode, KeyEvent event);
}
private ConfirmDialogListener confirmDialogListener;
@@ -38,6 +37,15 @@ public class ConfirmDialogFragment extends DialogFragment {
return fragment;
}
/** Allows refreshing the first item of the adapter */
private void RefreshAdapter()
{
Bundle args = getArguments();
int itemPosition = args.getInt("ItemPosition");
getTaskAdapter().notifyItemChanged(itemPosition);
}
public TaskAdapter getTaskAdapter() {
return taskAdapter;
}
@@ -49,6 +57,7 @@ public class ConfirmDialogFragment extends DialogFragment {
@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
RefreshAdapter();
}
@Override
@@ -66,9 +75,9 @@ public class ConfirmDialogFragment extends DialogFragment {
}
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// TODO: Handle on dismiss or similar
builder.setMessage(getResources().getString(R.string.settings_confirm_message) + " " + message + "?")
.setPositiveButton(R.string.task_swipe_confirmation_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
@@ -78,7 +87,7 @@ public class ConfirmDialogFragment extends DialogFragment {
.setNegativeButton(R.string.task_swipe_confirmation_no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
confirmDialogListener.onConfirmDialogNegativeClick(ConfirmDialogFragment.this);
RefreshAdapter();
}
}).setNeutralButton(R.string.task_swipe_confirmation_never, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
@@ -89,7 +98,7 @@ public class ConfirmDialogFragment extends DialogFragment {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
//return false;
return confirmDialogListener.onConfirmDialogKeyListener(ConfirmDialogFragment.this, keyCode, event);
return keyCode != KeyEvent.KEYCODE_BACK;
}
});
// Create the AlertDialog object and return it

View File

@@ -1,109 +0,0 @@
package com.wismna.geoffroy.donext.fragments;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.wismna.geoffroy.donext.R;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link TaskDetailsFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link TaskDetailsFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class TaskDetailsFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public TaskDetailsFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment TaskDetailsFragment.
*/
// TODO: Rename and change types and number of parameters
public static TaskDetailsFragment newInstance(String param1, String param2) {
TaskDetailsFragment fragment = new TaskDetailsFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_task_details, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}

View File

@@ -5,7 +5,9 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
@@ -14,6 +16,7 @@ import android.widget.RadioGroup;
import android.widget.Spinner;
import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.TaskAdapter;
import com.wismna.geoffroy.donext.dao.TaskList;
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
@@ -21,21 +24,51 @@ import java.util.List;
/**
* Created by geoffroy on 15-11-26.
* Represents a New or Edit Task dialog
*/
public class NewTaskFragment extends DialogFragment {
public class TaskDialogFragment extends DialogFragment {
public TaskAdapter getTaskAdapter() {
return taskAdapter;
}
public void setTaskAdapter(TaskAdapter taskAdapter) {
this.taskAdapter = taskAdapter;
}
public RecyclerView getRecyclerView() {
return recyclerView;
}
public void setRecyclerView(RecyclerView recyclerView) {
this.recyclerView = recyclerView;
}
/** 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 NewTaskListener {
void onNewTaskDialogPositiveClick(DialogFragment dialog);
void onNewTaskDialogNeutralClick(DialogFragment dialog);
//void onDialogNegativeClick(DialogFragment dialog);
}
//private TaskDataAccess taskDataAccess;
private TaskAdapter taskAdapter;
private RecyclerView recyclerView;
// Use this instance of the interface to deliver action events
private NewTaskListener mListener;
public static TaskDialogFragment newInstance(TaskAdapter taskAdapter, RecyclerView recyclerView) {
Bundle args = new Bundle();
TaskDialogFragment fragment = new TaskDialogFragment();
fragment.setTaskAdapter(taskAdapter);
fragment.setRecyclerView(recyclerView);
fragment.setArguments(args);
return fragment;
}
/** Override the Fragment.onAttach() method to instantiate the NoticeDialogListener */
@Override
public void onAttach(Activity activity) {
@@ -52,6 +85,7 @@ public class NewTaskFragment extends DialogFragment {
}
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
@@ -66,7 +100,7 @@ public class NewTaskFragment extends DialogFragment {
@Override
public void onClick(DialogInterface dialog, int id) {
// Send the positive button event back to the host activity
mListener.onNewTaskDialogPositiveClick(NewTaskFragment.this);
mListener.onNewTaskDialogPositiveClick(TaskDialogFragment.this);
}
})
.setNegativeButton(R.string.new_task_cancel, new DialogInterface.OnClickListener() {
@@ -74,7 +108,7 @@ public class NewTaskFragment extends DialogFragment {
// Send the negative button event back to the host activity
//mListener.onDialogNegativeClick(NoticeDialogFragment.this);
// Canceled creation, nothing to do
NewTaskFragment.this.getDialog().cancel();
TaskDialogFragment.this.getDialog().cancel();
}
});
@@ -98,7 +132,7 @@ public class NewTaskFragment extends DialogFragment {
int id = args.getInt("list");
spinner.setSelection(id);
// Set other properties
// Set other properties if they exist
EditText titleText = (EditText) view.findViewById(R.id.new_task_name);
titleText.setText(args.getString("title"));
EditText descText = (EditText) view.findViewById(R.id.new_task_description);
@@ -117,7 +151,14 @@ public class NewTaskFragment extends DialogFragment {
priorityGroup.check(R.id.new_task_priority_high);
break;
}
// Add a Delete button in Edit mode
if (args.getLong("id") != 0)
builder.setNeutralButton(R.string.new_task_delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mListener.onNewTaskDialogNeutralClick(TaskDialogFragment.this);
}
});
return builder.create();
}

View File

@@ -45,7 +45,6 @@ public class TasksFragment extends Fragment {
public TasksFragment() {
}
@SuppressWarnings("unused")
public static TasksFragment newInstance(long taskListId) {
TasksFragment fragment = new TasksFragment();
Bundle args = new Bundle();
@@ -70,7 +69,7 @@ public class TasksFragment extends Fragment {
final Context context = view.getContext();
// Set the Recycler view
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.task_list_view);
final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.task_list_view);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext());
@@ -85,7 +84,7 @@ public class TasksFragment extends Fragment {
totalTasksView.setText(String.valueOf(taskDataAccess.getTaskCount(taskListId)));
// Set RecyclerView Adapter
TaskAdapter taskAdapter = new TaskAdapter(taskDataAccess.getAllTasks(taskListId), mListener);
final TaskAdapter taskAdapter = new TaskAdapter(taskDataAccess.getAllTasks(taskListId), mListener);
recyclerView.setAdapter(taskAdapter);
taskDataAccess.close();
@@ -106,14 +105,16 @@ public class TasksFragment extends Fragment {
public void onItemClick(View view, int position) {
//tasksFragmentListener.onItemClick(view, position);
/*TextView idTextView = (TextView) view.findViewById(R.id.task_id);
mToast.setText("Item " + idTextView.getText() + " clicked!");
TextView idTextView = (TextView) view.findViewById(R.id.task_id);
/*mToast.setText("Item " + idTextView.getText() + " clicked!");
mToast.show();*/
FragmentManager manager = getFragmentManager();
NewTaskFragment newTaskFragment = new NewTaskFragment();
TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(taskAdapter, recyclerView);
Bundle args = new Bundle();
args.putLong("id", Long.valueOf(idTextView.getText().toString()));
args.putInt("position", position);
// Set current tab value to new task dialog
ViewPager viewPager =(ViewPager) getActivity().findViewById(R.id.container);
@@ -131,8 +132,8 @@ public class TasksFragment extends Fragment {
if (titleTextView.getTypeface().isBold()) priority = 2;
args.putInt("priority", priority);
newTaskFragment.setArguments(args);
newTaskFragment.show(manager, "Edit task");
taskDialogFragment.setArguments(args);
taskDialogFragment.show(manager, "Edit task");
}
})
);

View File

@@ -8,6 +8,8 @@ import android.view.View;
/**
* Created by geoffroy on 15-12-02.
* Listener class on RecyclerView to intercept touch events
* This allows disabling swipe on any other element than the first one
*/
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.wismna.geoffroy.donext.activities.TaskDetailsActivity">
<fragment
android:name="com.wismna.geoffroy.donext.fragments.TaskDetailsFragment"
android:id="@+id/task_details_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>

View File

@@ -30,7 +30,7 @@
android:layout_height="wrap_content"
android:maxLines="2"
android:textColor="@color/colorPrimary"
android:textSize="14dp"
android:textSize="14sp"
android:textAppearance="?attr/textAppearanceListItemSmall" />
</LinearLayout>
</LinearLayout>

View File

@@ -1,18 +0,0 @@
<RelativeLayout 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"
tools:context="com.wismna.geoffroy.donext.fragments.TaskDetailsFragment">
<EditText
android:id="@+id/task_details_name"
android:layout_width="300dp"
android:layout_height="50dp"
android:text="@string/hello_blank_fragment" />
<EditText
android:id="@+id/task_details_description"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_below="@id/task_details_name"
android:text="@string/hello_blank_fragment" />
</RelativeLayout>

View File

@@ -25,6 +25,7 @@
<string name="new_task_priority_high">High</string>
<string name="new_task_save">Save</string>
<string name="new_task_cancel">Cancel</string>
<string name="new_task_delete">Delete</string>
<!-- String related to task details activity -->
<string name="task_details_activity_title">Details</string>
@@ -39,8 +40,8 @@
<!-- Strings related to Settings -->
<string name="settings_confirm_message">Mark task as</string>
<string name="settings_confirm_donext">Confirm on DoNext?</string>
<string name="settings_confirm_markdone">Confirm on mark Done?</string>
<string name="settings_confirm_donext">Confirm on next?</string>
<string name="settings_confirm_markdone">Confirm on done?</string>
<string name="settings_confirm_delete">Confirm on delete?</string>
<string name="settings_max_lists_label">Maximum number of lists:</string>
<string-array name="settings_max_lists_number">
@@ -53,7 +54,4 @@
<item>7</item>
</string-array>
<string name="title_activity_task_list">TaskListActivity</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>