mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
Add RecyclerView Manager: finally correct swiping and scrolling handling
Add Delete Task confirmation
This commit is contained in:
@@ -34,6 +34,14 @@
|
|||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value=".activities.MainActivity" />
|
android:value=".activities.MainActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".activities.TaskActivity"
|
||||||
|
android:label="@string/task_details_activity_title"
|
||||||
|
android:theme="@android:style/Theme.Holo.DialogWhenLarge" >
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value=".activities.MainActivity" />
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -27,17 +27,24 @@ public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback {
|
|||||||
|
|
||||||
public TaskTouchHelper(TaskAdapter taskAdapter, TaskDataAccess taskDataAccess,
|
public TaskTouchHelper(TaskAdapter taskAdapter, TaskDataAccess taskDataAccess,
|
||||||
FragmentManager fragmentManager, RecyclerView recyclerView){
|
FragmentManager fragmentManager, RecyclerView recyclerView){
|
||||||
// No drag moves, only swipes
|
// No drag moves, only left swipes (except for 1st element, see getSwipeDirs method)
|
||||||
super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
|
super(0, ItemTouchHelper.LEFT);
|
||||||
this.taskAdapter = taskAdapter;
|
this.taskAdapter = taskAdapter;
|
||||||
this.taskDataAccess = taskDataAccess;
|
this.taskDataAccess = taskDataAccess;
|
||||||
this.fragmentManager = fragmentManager;
|
this.fragmentManager = fragmentManager;
|
||||||
this.recyclerView = recyclerView;
|
this.recyclerView = recyclerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||||
|
// Allow both directions swiping on first item, only left on the others
|
||||||
|
if (viewHolder.getAdapterPosition() == 0)
|
||||||
|
return ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
|
||||||
|
else return super.getSwipeDirs(recyclerView, viewHolder);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
||||||
//TODO: Not implemented here
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,19 +52,19 @@ public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback {
|
|||||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(viewHolder.itemView.getContext());
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(viewHolder.itemView.getContext());
|
||||||
int itemPosition = viewHolder.getAdapterPosition();
|
int itemPosition = viewHolder.getAdapterPosition();
|
||||||
String title = "Confirm";
|
String title = "";
|
||||||
boolean showDialog = false;
|
boolean showDialog = false;
|
||||||
|
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
// Mark item as Done
|
// Mark item as Done
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT:
|
||||||
title = "Done";
|
title = "Mark task as done?";
|
||||||
showDialog = sharedPref.getBoolean("pref_conf_done", true);
|
showDialog = sharedPref.getBoolean("pref_conf_done", true);
|
||||||
break;
|
break;
|
||||||
// Increase task cycle count
|
// Increase task cycle count
|
||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT:
|
||||||
title = "Next";
|
title = "Go to next task?";
|
||||||
showDialog = sharedPref.getBoolean("pref_conf_next", true);
|
showDialog = sharedPref.getBoolean("pref_conf_next", true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -140,7 +140,7 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
taskDataAccess.close();
|
taskDataAccess.close();
|
||||||
}
|
}
|
||||||
// TODO: change add methods to add or update
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewTaskDialogPositiveClick(DialogFragment dialog) {
|
public void onNewTaskDialogPositiveClick(DialogFragment dialog) {
|
||||||
// Get the dialog fragment
|
// Get the dialog fragment
|
||||||
@@ -163,8 +163,6 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
taskList.getId());
|
taskList.getId());
|
||||||
taskDataAccess.close();
|
taskDataAccess.close();
|
||||||
// Update the corresponding tab adapter
|
// 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 taskAdapter = ((TaskDialogFragment)dialog).getTaskAdapter();
|
TaskAdapter taskAdapter = ((TaskDialogFragment)dialog).getTaskAdapter();
|
||||||
// Add the task
|
// Add the task
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
@@ -177,40 +175,27 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public void onNewTaskDialogNeutralClick(DialogFragment dialog) {
|
public void onNewTaskDialogNeutralClick(DialogFragment dialog) {
|
||||||
// TODO: add confirm dialog
|
// TODO: add confirm dialog
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
String title = getResources().getString(R.string.task_confirmation_delete_text);
|
||||||
|
boolean showDialog = sharedPref.getBoolean("pref_conf_del", true);
|
||||||
TaskDialogFragment taskDialogFragment = (TaskDialogFragment) dialog;
|
TaskDialogFragment taskDialogFragment = (TaskDialogFragment) dialog;
|
||||||
Bundle args = dialog.getArguments();
|
Bundle args = dialog.getArguments();
|
||||||
final long id = args.getLong("id");
|
|
||||||
|
|
||||||
// Delete task from Adapter
|
// Delete task from Adapter
|
||||||
final int position = args.getInt("position");
|
final int itemPosition = args.getInt("position");
|
||||||
final TaskAdapter taskAdapter = taskDialogFragment.getTaskAdapter();
|
final TaskAdapter taskAdapter = taskDialogFragment.getTaskAdapter();
|
||||||
final Task task = taskAdapter.getItem(position);
|
final RecyclerView view = taskDialogFragment.getRecyclerView();
|
||||||
taskAdapter.remove(position);
|
|
||||||
|
|
||||||
// Setup the snack bar
|
if (showDialog) {
|
||||||
final View view = taskDialogFragment.getRecyclerView();
|
ConfirmDialogFragment confirmDialogFragment =
|
||||||
Snackbar.make(view, "Task deleted", Snackbar.LENGTH_LONG)
|
ConfirmDialogFragment.newInstance(taskAdapter, title, view);
|
||||||
.setAction("Undo", new View.OnClickListener() {
|
Bundle confirmArgs = new Bundle();
|
||||||
@Override
|
confirmArgs.putInt("ItemPosition", itemPosition);
|
||||||
public void onClick(View v) {
|
confirmArgs.putInt("Direction", -1);
|
||||||
// Undo adapter changes
|
confirmDialogFragment.setArguments(confirmArgs);
|
||||||
taskAdapter.add(task, position);
|
confirmDialogFragment.show(getSupportFragmentManager(), title);
|
||||||
((RecyclerView)view).scrollToPosition(position);
|
}
|
||||||
}
|
else PerformSwipeAction(taskDataAccess, taskAdapter, itemPosition, -1, view);
|
||||||
}).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 */
|
/** Called when user clicks on the New Task floating button */
|
||||||
@@ -251,7 +236,7 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
SharedPreferences.Editor editor = sharedPref.edit();
|
SharedPreferences.Editor editor = sharedPref.edit();
|
||||||
editor.putBoolean("pref_conf_next", false);
|
//editor.putBoolean("pref_conf_next", false);
|
||||||
|
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
@@ -263,6 +248,10 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT:
|
||||||
editor.putBoolean("pref_conf_next", false);
|
editor.putBoolean("pref_conf_next", false);
|
||||||
break;
|
break;
|
||||||
|
// TODO: add delete action
|
||||||
|
case -1:
|
||||||
|
editor.putBoolean("pref_conf_del", false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
editor.apply();
|
editor.apply();
|
||||||
TaskAdapter taskAdapter = ((ConfirmDialogFragment)dialog).getTaskAdapter();
|
TaskAdapter taskAdapter = ((ConfirmDialogFragment)dialog).getTaskAdapter();
|
||||||
@@ -288,32 +277,37 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
final View view) {
|
final View view) {
|
||||||
final long itemId = taskAdapter.getItemId(itemPosition);
|
final long itemId = taskAdapter.getItemId(itemPosition);
|
||||||
final Task task = taskAdapter.getItem(itemPosition);
|
final Task task = taskAdapter.getItem(itemPosition);
|
||||||
String title = "";
|
String action = "";
|
||||||
taskAdapter.remove(itemPosition);
|
taskAdapter.remove(itemPosition);
|
||||||
|
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
// Mark item as Done
|
// Mark item as Done
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT:
|
||||||
title = "Done";
|
action = "done";
|
||||||
break;
|
break;
|
||||||
// Increase task cycle count
|
// Increase task cycle count
|
||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT:
|
||||||
title = "Nexted";
|
action = "nexted";
|
||||||
task.setCycle(task.getCycle() + 1);
|
task.setCycle(task.getCycle() + 1);
|
||||||
taskAdapter.add(task, taskAdapter.getItemCount());
|
taskAdapter.add(task, taskAdapter.getItemCount());
|
||||||
break;
|
break;
|
||||||
|
// TODO: add delete action
|
||||||
|
case -1:
|
||||||
|
action = "deleted";
|
||||||
|
taskAdapter.remove(itemPosition);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the snack bar
|
// Setup the snack bar
|
||||||
Snackbar.make(view, "Task marked as " + title, Snackbar.LENGTH_LONG)
|
Snackbar.make(view, "Task " + action, Snackbar.LENGTH_LONG)
|
||||||
.setAction("Undo", new View.OnClickListener() {
|
.setAction("Undo", new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// Undo adapter changes
|
// Undo adapter changes
|
||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
// Nothing special to do yet
|
// Nothing special to do for done
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT:
|
||||||
break;
|
break;
|
||||||
// Remove the last item
|
// Remove the last item
|
||||||
@@ -321,6 +315,10 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
taskAdapter.remove(taskAdapter.getItemCount() - 1);
|
taskAdapter.remove(taskAdapter.getItemCount() - 1);
|
||||||
task.setCycle(task.getCycle() - 1);
|
task.setCycle(task.getCycle() - 1);
|
||||||
break;
|
break;
|
||||||
|
// TODO: add delete action
|
||||||
|
// Nothing special to do for delete
|
||||||
|
case -1:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// Reset the first item
|
// Reset the first item
|
||||||
taskAdapter.add(task, itemPosition);
|
taskAdapter.add(task, itemPosition);
|
||||||
@@ -346,6 +344,10 @@ public class MainActivity extends AppCompatActivity implements
|
|||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT:
|
||||||
taskDataAccess.increaseCycle(task.getCycle(), itemId);
|
taskDataAccess.increaseCycle(task.getCycle(), itemId);
|
||||||
break;
|
break;
|
||||||
|
// TODO: add delete action
|
||||||
|
case -1:
|
||||||
|
// Commit the changes to DB
|
||||||
|
taskDataAccess.deleteTask(itemId);
|
||||||
}
|
}
|
||||||
taskDataAccess.close();
|
taskDataAccess.close();
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,15 @@
|
|||||||
|
package com.wismna.geoffroy.donext.activities;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import com.wismna.geoffroy.donext.R;
|
||||||
|
|
||||||
|
public class TaskActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_task);
|
||||||
|
}
|
||||||
|
}
|
@@ -48,6 +48,7 @@ public class TaskDataAccess {
|
|||||||
values.put(DatabaseHelper.TASKS_COLUMN_NAME, name);
|
values.put(DatabaseHelper.TASKS_COLUMN_NAME, name);
|
||||||
values.put(DatabaseHelper.TASKS_COLUMN_DESC, description);
|
values.put(DatabaseHelper.TASKS_COLUMN_DESC, description);
|
||||||
values.put(DatabaseHelper.TASKS_COLUMN_PRIORITY, priorities.indexOf(priority));
|
values.put(DatabaseHelper.TASKS_COLUMN_PRIORITY, priorities.indexOf(priority));
|
||||||
|
//values.put(DatabaseHelper.TASKS_COLUMN_PRIORITY, priority);
|
||||||
values.put(DatabaseHelper.TASKS_COLUMN_LIST, taskList);
|
values.put(DatabaseHelper.TASKS_COLUMN_LIST, taskList);
|
||||||
long insertId;
|
long insertId;
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
|
@@ -74,18 +74,18 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
builder.setMessage(getResources().getString(R.string.settings_confirm_message) + " " + message + "?")
|
builder.setMessage(message)
|
||||||
.setPositiveButton(R.string.task_swipe_confirmation_yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.task_confirmation_yes_button, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
confirmDialogListener.onConfirmDialogPositiveClick(ConfirmDialogFragment.this);
|
confirmDialogListener.onConfirmDialogPositiveClick(ConfirmDialogFragment.this);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.task_swipe_confirmation_no, new DialogInterface.OnClickListener() {
|
.setNegativeButton(R.string.task_confirmation_no_button, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
// User cancelled the dialog
|
// User cancelled the dialog
|
||||||
ConfirmDialogFragment.this.getDialog().cancel();
|
ConfirmDialogFragment.this.getDialog().cancel();
|
||||||
}
|
}
|
||||||
}).setNeutralButton(R.string.task_swipe_confirmation_never, new DialogInterface.OnClickListener() {
|
}).setNeutralButton(R.string.task_confirmation_never_button, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
confirmDialogListener.onConfirmDialogNeutralClick(ConfirmDialogFragment.this);
|
confirmDialogListener.onConfirmDialogNeutralClick(ConfirmDialogFragment.this);
|
||||||
}
|
}
|
||||||
|
@@ -159,7 +159,7 @@ public class TaskDialogFragment extends DialogFragment {
|
|||||||
mListener.onNewTaskDialogNeutralClick(TaskDialogFragment.this);
|
mListener.onNewTaskDialogNeutralClick(TaskDialogFragment.this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light);
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -20,6 +19,7 @@ import com.wismna.geoffroy.donext.adapters.TaskAdapter;
|
|||||||
import com.wismna.geoffroy.donext.dao.Task;
|
import com.wismna.geoffroy.donext.dao.Task;
|
||||||
import com.wismna.geoffroy.donext.database.TaskDataAccess;
|
import com.wismna.geoffroy.donext.database.TaskDataAccess;
|
||||||
import com.wismna.geoffroy.donext.listeners.RecyclerItemClickListener;
|
import com.wismna.geoffroy.donext.listeners.RecyclerItemClickListener;
|
||||||
|
import com.wismna.geoffroy.donext.widgets.NoScrollingLayoutManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment representing a list of Items.
|
* A fragment representing a list of Items.
|
||||||
@@ -70,7 +70,8 @@ public class TasksFragment extends Fragment {
|
|||||||
|
|
||||||
// Set the Recycler view
|
// Set the Recycler view
|
||||||
final 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));
|
//recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||||
|
recyclerView.setLayoutManager(new NoScrollingLayoutManager(context));
|
||||||
|
|
||||||
TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext());
|
TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext());
|
||||||
taskDataAccess.open();
|
taskDataAccess.open();
|
||||||
@@ -90,14 +91,12 @@ public class TasksFragment extends Fragment {
|
|||||||
taskDataAccess.close();
|
taskDataAccess.close();
|
||||||
|
|
||||||
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
||||||
// TODO: conflicts with ItemTouchListener, see why
|
|
||||||
ItemTouchHelper.Callback callback = new TaskTouchHelper(
|
ItemTouchHelper.Callback callback = new TaskTouchHelper(
|
||||||
taskAdapter, taskDataAccess, getFragmentManager(), recyclerView);
|
taskAdapter, taskDataAccess, getFragmentManager(), recyclerView);
|
||||||
ItemTouchHelper helper = new ItemTouchHelper(callback);
|
ItemTouchHelper helper = new ItemTouchHelper(callback);
|
||||||
helper.attachToRecyclerView(recyclerView);
|
helper.attachToRecyclerView(recyclerView);
|
||||||
|
|
||||||
// Implements touch listener to add click detection
|
// Implements touch listener to add click detection
|
||||||
// TODO: conflicts with ItemTouchHelper (maybe add swipe detection there with onFling?)
|
|
||||||
//final Toast mToast = Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT);
|
//final Toast mToast = Toast.makeText(getActivity(), "", Toast.LENGTH_SHORT);
|
||||||
recyclerView.addOnItemTouchListener(
|
recyclerView.addOnItemTouchListener(
|
||||||
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
|
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
|
||||||
@@ -106,8 +105,8 @@ public class TasksFragment extends Fragment {
|
|||||||
//tasksFragmentListener.onItemClick(view, position);
|
//tasksFragmentListener.onItemClick(view, position);
|
||||||
|
|
||||||
TextView idTextView = (TextView) view.findViewById(R.id.task_id);
|
TextView idTextView = (TextView) view.findViewById(R.id.task_id);
|
||||||
/*mToast.setText("Item " + idTextView.getText() + " clicked!");
|
//mToast.setText("Item " + idTextView.getText() + " clicked!");
|
||||||
mToast.show();*/
|
//mToast.show();
|
||||||
|
|
||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getFragmentManager();
|
||||||
TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(taskAdapter, recyclerView);
|
TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(taskAdapter, recyclerView);
|
||||||
|
@@ -9,7 +9,6 @@ import android.view.View;
|
|||||||
/**
|
/**
|
||||||
* Created by geoffroy on 15-12-02.
|
* Created by geoffroy on 15-12-02.
|
||||||
* Listener class on RecyclerView to intercept touch events
|
* 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 {
|
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
|
||||||
private OnItemClickListener mListener;
|
private OnItemClickListener mListener;
|
||||||
@@ -33,15 +32,12 @@ public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
|
|||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
|
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
|
||||||
View childView = view.findChildViewUnder(e.getX(), e.getY());
|
View childView = view.findChildViewUnder(e.getX(), e.getY());
|
||||||
int childId = view.getChildAdapterPosition(childView);
|
//int childId = view.getChildAdapterPosition(childView);
|
||||||
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
|
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
|
||||||
mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
|
mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
// Allows right swipe moves only on first element of the list, left everywhere
|
|
||||||
return e.getAction() != MotionEvent.ACTION_MOVE ||
|
|
||||||
((e.getY() - e.getHistoricalY(0) > 0 || (e.getY() - e.getHistoricalY(0)) < 0) ||
|
|
||||||
childId != 0 && e.getX() - e.getHistoricalX(0) > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -0,0 +1,20 @@
|
|||||||
|
package com.wismna.geoffroy.donext.widgets;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by geoffroy on 15-12-21.
|
||||||
|
* Custom Layout Manager that disables vertical scrolling for the RecyclerView
|
||||||
|
*/
|
||||||
|
public class NoScrollingLayoutManager extends LinearLayoutManager {
|
||||||
|
|
||||||
|
public NoScrollingLayoutManager(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canScrollVertically() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -7,6 +7,7 @@ import android.view.MotionEvent;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by geoffroy on 15-12-04.
|
* Created by geoffroy on 15-12-04.
|
||||||
|
* Custom ViewPager to forbid vertical swiping between tabs
|
||||||
*/
|
*/
|
||||||
public class NonSwipeableViewPager extends ViewPager {
|
public class NonSwipeableViewPager extends ViewPager {
|
||||||
|
|
||||||
|
83
DoNExt/app/src/main/res/layout/activity_task.xml
Normal file
83
DoNExt/app/src/main/res/layout/activity_task.xml
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:context=".activities.MainActivity">
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_task_list"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/new_task_list"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
</Spinner>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_task_name"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/new_task_name"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_task_description"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/new_task_description"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:lines="3"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_task_priority"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/new_task_priority"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/new_task_priority_low"
|
||||||
|
android:text="@string/new_task_priority_low"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
</RadioButton>
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/new_task_priority_normal"
|
||||||
|
android:text="@string/new_task_priority_normal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:checked="true">
|
||||||
|
</RadioButton>
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/new_task_priority_high"
|
||||||
|
android:text="@string/new_task_priority_high"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
</RadioButton>
|
||||||
|
</RadioGroup>
|
||||||
|
<LinearLayout
|
||||||
|
android:padding="20dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:orientation="horizontal" >
|
||||||
|
<Button
|
||||||
|
android:id="@+id/new_task_save"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_task_save" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/new_task_cancel"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/new_task_cancel"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
@@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="fill_parent"
|
||||||
android:padding="10dp"
|
android:padding="16dp"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context=".activities.MainActivity">
|
tools:context=".activities.MainActivity">
|
||||||
<TextView
|
<TextView
|
||||||
|
@@ -27,16 +27,20 @@
|
|||||||
<string name="new_task_cancel">Cancel</string>
|
<string name="new_task_cancel">Cancel</string>
|
||||||
<string name="new_task_delete">Delete</string>
|
<string name="new_task_delete">Delete</string>
|
||||||
|
|
||||||
<!-- String related to task details activity -->
|
<!-- Strings related to task details activity -->
|
||||||
<string name="task_details_activity_title">Details</string>
|
<string name="task_details_activity_title">Details</string>
|
||||||
|
|
||||||
<!-- String related to task list Recycler View -->
|
|
||||||
<string name="task_swipe_confirmation_title">Confirm</string>
|
<!-- Strings related to the confirmation dialog -->
|
||||||
<string name="task_swipe_confirmation_done">Mark task as Done?</string>
|
<string name="task_confirmation_done_text">Mark task as Done?</string>
|
||||||
<string name="task_swipe_confirmation_next">Mark task as Nexted?</string>
|
<string name="task_confirmation_next_text">Go to next task?</string>
|
||||||
<string name="task_swipe_confirmation_yes">Yes</string>
|
<string name="task_confirmation_delete_text">Delete this task?</string>
|
||||||
<string name="task_swipe_confirmation_no">No</string>
|
<string name="task_confirmation_done_button">Done</string>
|
||||||
<string name="task_swipe_confirmation_never">Never ask again</string>
|
<string name="task_confirmation_next_button">Next</string>
|
||||||
|
<string name="task_confirmation_delete_button">Delete</string>
|
||||||
|
<string name="task_confirmation_yes_button">Yes</string>
|
||||||
|
<string name="task_confirmation_no_button">No</string>
|
||||||
|
<string name="task_confirmation_never_button">Never ask again</string>
|
||||||
|
|
||||||
<!-- Strings related to Settings -->
|
<!-- Strings related to Settings -->
|
||||||
<string name="settings_confirm_message">Mark task as</string>
|
<string name="settings_confirm_message">Mark task as</string>
|
||||||
|
Reference in New Issue
Block a user