List edition activity redone with a RecyclerView

Lists are now editable and swappable
Lots of code simplification (TaskDialogFragment...)
This commit is contained in:
2015-12-30 19:02:27 -05:00
parent 27884add9e
commit c8dbcb1aff
26 changed files with 547 additions and 523 deletions

View File

@@ -14,7 +14,6 @@
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
@@ -28,20 +27,12 @@
</activity> </activity>
<activity <activity
android:name=".activities.TaskListActivity" android:name=".activities.TaskListActivity"
android:label="@string/task_list_activity_title" android:label="@string/action_editTabs"
android:parentActivityName=".activities.MainActivity"> android:parentActivityName=".activities.MainActivity">
<meta-data <meta-data
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>

View File

@@ -0,0 +1,37 @@
package com.wismna.geoffroy.donext.ItemTouchHelpers;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
/**
* Created by geoffroy on 15-12-30.
* Helper class that handles all drags events on a TaskList
*/
public class TaskListTouchHelper extends ItemTouchHelper.SimpleCallback {
public interface TaskListTouchHelperAdapter {
boolean onItemMove (int fromPosition, int toPosition);
}
private final TaskListTouchHelperAdapter mAdapter;
public TaskListTouchHelper(TaskListTouchHelperAdapter adapter) {
super(ItemTouchHelper.UP | ItemTouchHelper.DOWN, 0);
mAdapter = adapter;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
// No swipe moves
}
@Override
public boolean isLongPressDragEnabled() {
return true;
}
}

View File

@@ -11,7 +11,7 @@ import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View; import android.view.View;
import com.wismna.geoffroy.donext.activities.MainActivity; import com.wismna.geoffroy.donext.activities.MainActivity;
import com.wismna.geoffroy.donext.adapters.TaskAdapter; import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter;
import com.wismna.geoffroy.donext.database.TaskDataAccess; import com.wismna.geoffroy.donext.database.TaskDataAccess;
import com.wismna.geoffroy.donext.fragments.ConfirmDialogFragment; import com.wismna.geoffroy.donext.fragments.ConfirmDialogFragment;
@@ -20,16 +20,16 @@ import com.wismna.geoffroy.donext.fragments.ConfirmDialogFragment;
* Helper class that handles all swipe events on a Task * Helper class that handles all swipe events on a Task
*/ */
public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback { public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback {
private TaskAdapter taskAdapter; private TaskRecyclerViewAdapter taskRecyclerViewAdapter;
private TaskDataAccess taskDataAccess; private TaskDataAccess taskDataAccess;
private FragmentManager fragmentManager; private FragmentManager fragmentManager;
private RecyclerView recyclerView; private RecyclerView recyclerView;
public TaskTouchHelper(TaskAdapter taskAdapter, TaskDataAccess taskDataAccess, public TaskTouchHelper(TaskRecyclerViewAdapter taskRecyclerViewAdapter, TaskDataAccess taskDataAccess,
FragmentManager fragmentManager, RecyclerView recyclerView){ FragmentManager fragmentManager, RecyclerView recyclerView){
// No drag moves, only left swipes (except for 1st element, see getSwipeDirs method) // No drag moves, only left swipes (except for 1st element, see getSwipeDirs method)
super(0, ItemTouchHelper.LEFT); super(0, ItemTouchHelper.LEFT);
this.taskAdapter = taskAdapter; this.taskRecyclerViewAdapter = taskRecyclerViewAdapter;
this.taskDataAccess = taskDataAccess; this.taskDataAccess = taskDataAccess;
this.fragmentManager = fragmentManager; this.fragmentManager = fragmentManager;
this.recyclerView = recyclerView; this.recyclerView = recyclerView;
@@ -70,14 +70,14 @@ public class TaskTouchHelper extends ItemTouchHelper.SimpleCallback {
} }
if (showDialog) { if (showDialog) {
ConfirmDialogFragment confirmDialogFragment = ConfirmDialogFragment confirmDialogFragment =
ConfirmDialogFragment.newInstance(taskAdapter, title, recyclerView); ConfirmDialogFragment.newInstance(/*taskRecyclerViewAdapter, */title, recyclerView);
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt("ItemPosition", itemPosition); args.putInt("ItemPosition", itemPosition);
args.putInt("Direction", direction); args.putInt("Direction", direction);
confirmDialogFragment.setArguments(args); confirmDialogFragment.setArguments(args);
confirmDialogFragment.show(fragmentManager, title); confirmDialogFragment.show(fragmentManager, title);
} }
else MainActivity.PerformSwipeAction(taskDataAccess, taskAdapter, itemPosition, direction, recyclerView); else MainActivity.PerformSwipeAction(taskDataAccess, taskRecyclerViewAdapter, itemPosition, direction, recyclerView);
} }
@Override @Override

View File

@@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
@@ -26,7 +27,7 @@ import android.widget.Spinner;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.SmartFragmentStatePagerAdapter; import com.wismna.geoffroy.donext.adapters.SmartFragmentStatePagerAdapter;
import com.wismna.geoffroy.donext.adapters.TaskAdapter; import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter;
import com.wismna.geoffroy.donext.dao.Task; import com.wismna.geoffroy.donext.dao.Task;
import com.wismna.geoffroy.donext.dao.TaskList; import com.wismna.geoffroy.donext.dao.TaskList;
import com.wismna.geoffroy.donext.database.TaskDataAccess; import com.wismna.geoffroy.donext.database.TaskDataAccess;
@@ -39,7 +40,6 @@ import java.util.List;
public class MainActivity extends AppCompatActivity implements public class MainActivity extends AppCompatActivity implements
TaskDialogFragment.NewTaskListener, TaskDialogFragment.NewTaskListener,
TasksFragment.OnListFragmentInteractionListener,
ConfirmDialogFragment.ConfirmDialogListener ConfirmDialogFragment.ConfirmDialogListener
{ {
@@ -52,7 +52,7 @@ public class MainActivity extends AppCompatActivity implements
* may be best to switch to a * may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}. * {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/ */
private SectionsPagerAdapter mSectionsPagerAdapter;
/** /**
* The {@link ViewPager} that will host the section contents. * The {@link ViewPager} that will host the section contents.
*/ */
@@ -69,7 +69,7 @@ public class MainActivity extends AppCompatActivity implements
// Create the adapter that will return a fragment for each of the three // Create the adapter that will return a fragment for each of the three
// primary sections of the activity. // primary sections of the activity.
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Access database to retrieve tasks // Access database to retrieve tasks
taskDataAccess = new TaskDataAccess(this); taskDataAccess = new TaskDataAccess(this);
@@ -81,6 +81,7 @@ public class MainActivity extends AppCompatActivity implements
taskLists = taskListDataAccess.getAllTaskLists(); taskLists = taskListDataAccess.getAllTaskLists();
mSectionsPagerAdapter.notifyDataSetChanged(); mSectionsPagerAdapter.notifyDataSetChanged();
taskListDataAccess.close();
// Set up the ViewPager with the sections adapter. // Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container); mViewPager = (ViewPager) findViewById(R.id.container);
@@ -89,16 +90,10 @@ public class MainActivity extends AppCompatActivity implements
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager); tabLayout.setupWithViewPager(mViewPager);
// Add Task floating button // Hide or show new task floating button
// TODO: disable or hide button when no lists exist FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); if (taskLists.size() == 0) fab.hide();
fab.setOnClickListener(new View.OnClickListener() { else fab.show();
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});*/
} }
@Override @Override
@@ -115,12 +110,8 @@ public class MainActivity extends AppCompatActivity implements
// as you specify a parent activity in AndroidManifest.xml. // as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); int id = item.getItemId();
//noinspection SimplifiableIfStatement return id == R.id.action_settings || super.onOptionsItemSelected(item);
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} }
@Override @Override
@@ -145,8 +136,10 @@ public class MainActivity extends AppCompatActivity implements
public void onNewTaskDialogPositiveClick(DialogFragment dialog) { public void onNewTaskDialogPositiveClick(DialogFragment dialog) {
// Get the dialog fragment // Get the dialog fragment
Dialog dialogView = dialog.getDialog(); Dialog dialogView = dialog.getDialog();
Bundle args = dialog.getArguments(); long id = 0;
long id = args.getLong("id"); Task task = ((TaskDialogFragment)dialog).getTask();
if (task != null) id = task.getId();
// Get the controls // Get the controls
Spinner listSpinner = (Spinner) dialogView.findViewById(R.id.new_task_list); Spinner listSpinner = (Spinner) dialogView.findViewById(R.id.new_task_list);
EditText nameText = (EditText) dialogView.findViewById(R.id.new_task_name); EditText nameText = (EditText) dialogView.findViewById(R.id.new_task_name);
@@ -154,22 +147,40 @@ public class MainActivity extends AppCompatActivity implements
RadioGroup priorityGroup = (RadioGroup) dialogView.findViewById(R.id.new_task_priority); RadioGroup priorityGroup = (RadioGroup) dialogView.findViewById(R.id.new_task_priority);
RadioButton priorityRadio = (RadioButton) dialogView.findViewById(priorityGroup.getCheckedRadioButtonId()); RadioButton priorityRadio = (RadioButton) dialogView.findViewById(priorityGroup.getCheckedRadioButtonId());
TaskList taskList = (TaskList) listSpinner.getSelectedItem(); TaskList taskList = (TaskList) listSpinner.getSelectedItem();
// Add the task to the database // Add the task to the database
taskDataAccess.open(); taskDataAccess.open();
Task task = taskDataAccess.createOrUpdateTask(id, Task newTask = taskDataAccess.createOrUpdateTask(id,
nameText.getText().toString(), nameText.getText().toString(),
descText.getText().toString(), descText.getText().toString(),
priorityRadio.getText().toString(), priorityRadio.getText().toString(),
taskList.getId()); taskList.getId());
taskDataAccess.close(); taskDataAccess.close();
// Update the corresponding tab adapter // Update the corresponding tab adapter
TaskAdapter taskAdapter = ((TaskDialogFragment)dialog).getTaskAdapter();
Bundle args = dialog.getArguments();
TaskRecyclerViewAdapter taskRecyclerViewAdapter = getSpecificTabAdapter(args.getInt("list"));
// Should never happen because we will have to be on this tab to open the dialog
if (taskRecyclerViewAdapter == null) return;
// Add the task // Add the task
if (id == 0) if (task == null)
taskAdapter.add(task, taskAdapter.getItemCount()); taskRecyclerViewAdapter.add(newTask, taskRecyclerViewAdapter.getItemCount());
// Update the task // Update the task
else else {
taskAdapter.update(task, args.getInt("position")); int position = args.getInt("position");
// Check if task list was changed
if (task.getTaskListId() != taskList.getId())
{
// Remove item from current tab
taskRecyclerViewAdapter.remove(position);
// Add it to the corresponding tab provided it is already instanciated
TaskRecyclerViewAdapter destinationTaskAdapter = getSpecificTabAdapter(listSpinner.getSelectedItemPosition());
if (destinationTaskAdapter != null) destinationTaskAdapter.add(newTask, destinationTaskAdapter.getItemCount());
}
else taskRecyclerViewAdapter.update(newTask, position);
}
} }
@Override @Override
@@ -177,30 +188,39 @@ public class MainActivity extends AppCompatActivity implements
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String title = getResources().getString(R.string.task_confirmation_delete_text); String title = getResources().getString(R.string.task_confirmation_delete_text);
boolean showDialog = sharedPref.getBoolean("pref_conf_del", true); boolean showDialog = sharedPref.getBoolean("pref_conf_del", true);
TaskDialogFragment taskDialogFragment = (TaskDialogFragment) dialog;
Bundle args = dialog.getArguments(); Bundle args = dialog.getArguments();
// Delete task from Adapter // Delete task from Adapter
final int itemPosition = args.getInt("position"); final int itemPosition = args.getInt("position");
final TaskAdapter taskAdapter = taskDialogFragment.getTaskAdapter(); final RecyclerView view = getSpecificTabRecyclerView(args.getInt("list"));
final RecyclerView view = taskDialogFragment.getRecyclerView(); final TaskRecyclerViewAdapter taskRecyclerViewAdapter = (TaskRecyclerViewAdapter) view.getAdapter();
if (showDialog) { if (showDialog) {
ConfirmDialogFragment confirmDialogFragment = ConfirmDialogFragment confirmDialogFragment =
ConfirmDialogFragment.newInstance(taskAdapter, title, view); ConfirmDialogFragment.newInstance(title, view);
Bundle confirmArgs = new Bundle(); Bundle confirmArgs = new Bundle();
confirmArgs.putInt("ItemPosition", itemPosition); confirmArgs.putInt("ItemPosition", itemPosition);
confirmArgs.putInt("Direction", -1); confirmArgs.putInt("Direction", -1);
confirmDialogFragment.setArguments(confirmArgs); confirmDialogFragment.setArguments(confirmArgs);
confirmDialogFragment.show(getSupportFragmentManager(), title); confirmDialogFragment.show(getSupportFragmentManager(), title);
} }
else PerformSwipeAction(taskDataAccess, taskAdapter, itemPosition, -1, view); else PerformSwipeAction(taskDataAccess, taskRecyclerViewAdapter, itemPosition, -1, view);
} }
/** Called when user clicks on the New Task floating button */ /** Called when user clicks on the New Task floating button */
public void onNewTaskClick(View view) { public void onNewTaskClick(View view) {
OpenNewTaskDialog(); FragmentManager manager = getSupportFragmentManager();
TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(null,
mSectionsPagerAdapter.getAllItems());
// Set current tab value to new task dialog
Bundle args = new Bundle();
args.putInt("list", mViewPager.getCurrentItem());
taskDialogFragment.setArguments(args);
taskDialogFragment.show(manager, "Create new task");
} }
/** Called when the user clicks the Settings button */ /** Called when the user clicks the Settings button */
public void openSettings(MenuItem menuItem) { public void openSettings(MenuItem menuItem) {
Intent intent = new Intent(this, SettingsActivity.class); Intent intent = new Intent(this, SettingsActivity.class);
@@ -212,19 +232,14 @@ public class MainActivity extends AppCompatActivity implements
startActivity(intent); startActivity(intent);
} }
@Override
public void onListFragmentInteraction(Task item) {
}
@Override @Override
public void onConfirmDialogPositiveClick(DialogFragment dialog) { public void onConfirmDialogPositiveClick(DialogFragment dialog) {
Bundle args = dialog.getArguments(); Bundle args = dialog.getArguments();
int itemPosition = args.getInt("ItemPosition"); int itemPosition = args.getInt("ItemPosition");
int direction = args.getInt("Direction"); int direction = args.getInt("Direction");
TaskAdapter taskAdapter = ((ConfirmDialogFragment)dialog).getTaskAdapter(); TaskRecyclerViewAdapter taskRecyclerViewAdapter = ((ConfirmDialogFragment)dialog).getTaskRecyclerViewAdapter();
PerformSwipeAction(taskDataAccess, taskAdapter, itemPosition, direction, ((ConfirmDialogFragment) dialog).getRecyclerView()); PerformSwipeAction(taskDataAccess, taskRecyclerViewAdapter, itemPosition, direction, ((ConfirmDialogFragment) dialog).getRecyclerView());
} }
@Override @Override
@@ -235,7 +250,6 @@ 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);
switch (direction) switch (direction)
{ {
@@ -252,31 +266,19 @@ public class MainActivity extends AppCompatActivity implements
break; break;
} }
editor.apply(); editor.apply();
TaskAdapter taskAdapter = ((ConfirmDialogFragment)dialog).getTaskAdapter(); TaskRecyclerViewAdapter taskRecyclerViewAdapter = ((ConfirmDialogFragment)dialog).getTaskRecyclerViewAdapter();
PerformSwipeAction(taskDataAccess, taskAdapter, itemPosition, direction, ((ConfirmDialogFragment) dialog).getRecyclerView()); PerformSwipeAction(taskDataAccess, taskRecyclerViewAdapter, itemPosition, direction, ((ConfirmDialogFragment) dialog).getRecyclerView());
}
private void OpenNewTaskDialog() {
FragmentManager manager = getSupportFragmentManager();
TaskDialogFragment taskDialogFragment = new TaskDialogFragment();
// Set current tab value to new task dialog
Bundle args = new Bundle();
args.putInt("list", mViewPager.getCurrentItem());
taskDialogFragment.setArguments(args);
taskDialogFragment.show(manager, "Create new task");
} }
public static void PerformSwipeAction(final TaskDataAccess taskDataAccess, public static void PerformSwipeAction(final TaskDataAccess taskDataAccess,
final TaskAdapter taskAdapter, final TaskRecyclerViewAdapter taskRecyclerViewAdapter,
final int itemPosition, final int itemPosition,
final int direction, final int direction,
final View view) { final View view) {
final long itemId = taskAdapter.getItemId(itemPosition); final long itemId = taskRecyclerViewAdapter.getItemId(itemPosition);
final Task task = taskAdapter.getItem(itemPosition); final Task task = taskRecyclerViewAdapter.getItem(itemPosition);
String action = ""; String action = "";
taskAdapter.remove(itemPosition); taskRecyclerViewAdapter.remove(itemPosition);
switch (direction) switch (direction)
{ {
@@ -288,11 +290,10 @@ public class MainActivity extends AppCompatActivity implements
case ItemTouchHelper.RIGHT: case ItemTouchHelper.RIGHT:
action = "nexted"; action = "nexted";
task.setCycle(task.getCycle() + 1); task.setCycle(task.getCycle() + 1);
taskAdapter.add(task, taskAdapter.getItemCount()); taskRecyclerViewAdapter.add(task, taskRecyclerViewAdapter.getItemCount());
break; break;
case -1: case -1:
action = "deleted"; action = "deleted";
taskAdapter.remove(itemPosition);
break; break;
} }
@@ -309,7 +310,7 @@ public class MainActivity extends AppCompatActivity implements
break; break;
// Remove the last item // Remove the last item
case ItemTouchHelper.RIGHT: case ItemTouchHelper.RIGHT:
taskAdapter.remove(taskAdapter.getItemCount() - 1); taskRecyclerViewAdapter.remove(taskRecyclerViewAdapter.getItemCount() - 1);
task.setCycle(task.getCycle() - 1); task.setCycle(task.getCycle() - 1);
break; break;
// Nothing special to do for delete // Nothing special to do for delete
@@ -317,7 +318,7 @@ public class MainActivity extends AppCompatActivity implements
break; break;
} }
// Reset the first item // Reset the first item
taskAdapter.add(task, itemPosition); taskRecyclerViewAdapter.add(task, itemPosition);
((RecyclerView)view).scrollToPosition(0); ((RecyclerView)view).scrollToPosition(0);
} }
}).setCallback(new Snackbar.Callback() { }).setCallback(new Snackbar.Callback() {
@@ -348,6 +349,21 @@ public class MainActivity extends AppCompatActivity implements
} }
}).show(); }).show();
} }
private RecyclerView getSpecificTabRecyclerView(int position) {
TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position);
if (taskFragment == null) return null;
View view = taskFragment.getView();
if (view == null) return null;
return ((RecyclerView) view.findViewById(R.id.task_list_view));
}
private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) {
RecyclerView view = getSpecificTabRecyclerView(position);
if (view == null) return null;
return (TaskRecyclerViewAdapter) view.getAdapter();
}
/** /**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages. * one of the sections/tabs/pages.
@@ -379,5 +395,9 @@ public class MainActivity extends AppCompatActivity implements
if (taskLists == null) return "N/A"; if (taskLists == null) return "N/A";
return taskLists.get(position).getName(); return taskLists.get(position).getName();
} }
public List<TaskList> getAllItems(){
return taskLists;
}
} }
} }

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 TaskActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task);
}
}

View File

@@ -1,91 +1,15 @@
package com.wismna.geoffroy.donext.activities; package com.wismna.geoffroy.donext.activities;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.TaskListCursorAdapter;
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
// TODO: create a fragment
// TODO: replace ListView with RecycleView
public class TaskListActivity extends AppCompatActivity {
private TaskListDataAccess dataAccess;
private TaskListCursorAdapter adapter;
private ListView listView;
public class TaskListActivity extends AppCompatActivity{
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task_list); setContentView(R.layout.activity_tasklists);
listView = (ListView) findViewById(android.R.id.list);
dataAccess = new TaskListDataAccess(this);
dataAccess.open();
adapter = new TaskListCursorAdapter(
this, R.layout.item_task_list, dataAccess.getAllTaskListsCursor(), 0);
listView.setAdapter(adapter);
updateCreateButtonEnabled();
}
/** Will be called when the create Task List button is clicked */
public void onCreateTaskList(View view) {
@SuppressWarnings("unchecked")
EditText editText = (EditText) findViewById(R.id.new_task_list_name);
Cursor cursor = dataAccess.createTaskList(editText.getText().toString());
adapter.changeCursor(cursor);
editText.setText("");
updateCreateButtonEnabled();
}
/** Will be called when the delete Task List button is clicked */
public void onDeleteTaskList(View view) {
@SuppressWarnings("unchecked")
final int position = listView.getPositionForView((View) view.getParent());
Cursor cursor = dataAccess.deleteTaskList((Cursor) adapter.getItem(position));
adapter.changeCursor(cursor);
updateCreateButtonEnabled();
}
@Override
protected void onResume() {
dataAccess.open();
super.onResume();
}
@Override
protected void onPause() {
dataAccess.close();
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
dataAccess.close();
}
private void updateCreateButtonEnabled() {
//Button createButton = (Button) findViewById(R.id.new_task_list_button);
//EditText editText = (EditText) findViewById(R.id.new_task_list_name);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.new_task_list_layout);
int taskListCount = adapter.getCount();
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "3");
int maxTaskLists = Integer.valueOf(maxTaskListsString);
//createButton.setEnabled(taskListCount < maxTaskLists);
//editText.setEnabled(taskListCount < maxTaskLists);
if (taskListCount >= maxTaskLists) layout.setVisibility(View.GONE);
else layout.setVisibility(View.VISIBLE);
} }
} }

View File

@@ -1,49 +0,0 @@
package com.wismna.geoffroy.donext.adapters;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
import com.wismna.geoffroy.donext.R;
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) {
super(context, layout, cursor, flags);
}
// The newView method is used to inflate a new view and return it,
// you don't bind any data to the view at this point.
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.item_task_list, parent, false);
}
// The bindView method is used to bind all data to a given view
// such as setting the text on a TextView.
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Find fields to populate in inflated template
TextView taskListCount = (TextView) view.findViewById(R.id.task_list_count);
TextView taskListName = (TextView) view.findViewById(R.id.task_list_name);
// Extract properties from cursor
String name = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseHelper.TASKLIST_COLUMN_NAME));
long count = cursor.getLong(cursor.getColumnIndexOrThrow(DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT));
// Populate fields with extracted properties
taskListCount.setText(String.valueOf(count));
taskListName.setText(name);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return super.getView(position, convertView, parent);
}
}

View File

@@ -0,0 +1,153 @@
package com.wismna.geoffroy.donext.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.wismna.geoffroy.donext.ItemTouchHelpers.TaskListTouchHelper;
import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.dao.TaskList;
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
import java.util.Collections;
import java.util.List;
/**
* {@link RecyclerView.Adapter} that can display a {@link TaskList}.
*/
// TODO: implement inline edit
public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRecyclerViewAdapter.ViewHolder>
implements TaskListTouchHelper.TaskListTouchHelperAdapter {
private final List<TaskList> mValues;
private Context mContext;
public TaskListRecyclerViewAdapter(List<TaskList> items, Context context) {
mValues = items;
mContext = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_tasklist, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.mItem = mValues.get(position);
holder.mTaskCountView.setText(String.valueOf(mValues.get(position).getTaskCount()));
holder.mTaskNameView.setText(mValues.get(position).getName());
// Handle inline name change
holder.mTaskNameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus)
{
EditText editText = (EditText) v;
holder.mItem.setName(editText.getText().toString());
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(mContext);
taskListDataAccess.open();
update(holder.mItem, position);
taskListDataAccess.updateName(holder.mItem.getId(), holder.mItem.getName());
taskListDataAccess.close();
}
}
});
// Handle click on delete button
// TODO: find a way to call TaskListsFragment.toggleVisibleCreateNewTaskListLayout
holder.mTaskDeleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(mContext);
taskListDataAccess.open();
taskListDataAccess.deleteTaskList(holder.mItem.getId());
remove(position);
taskListDataAccess.close();
}
});
}
@Override
public int getItemCount() {
return mValues.size();
}
public void add(TaskList item, int position) {
mValues.add(position, item);
notifyItemInserted(position);
}
public void remove(int position) {
mValues.remove(position);
notifyItemRemoved(position);
}
public void update(TaskList item, int position) {
mValues.set(position, item);
notifyItemChanged(position);
}
@Override
public boolean onItemMove(int fromPosition, int toPosition) {
TaskListDataAccess taskListDataAccess = new TaskListDataAccess(mContext);
taskListDataAccess.open();
long fromTaskId = mValues.get(fromPosition).getId();
long toTaskId = mValues.get(toPosition).getId();
if (fromPosition < toPosition) {
for (int i = fromPosition; i < toPosition; i++) {
Collections.swap(mValues, i, i + 1);
}
}
else {
for (int i = fromPosition; i > toPosition; i--) {
Collections.swap(mValues, i, i - 1);
}
}
taskListDataAccess.updateOrder(fromTaskId, toPosition);
taskListDataAccess.updateOrder(toTaskId, fromPosition);
// Update the adapter on the fly
notifyItemMoved(fromPosition, toPosition);
taskListDataAccess.close();
return true;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final TextView mTaskCountView;
public final TextView mTaskNameView;
public final Button mTaskDeleteButton;
public TaskList mItem;
public ViewHolder(View view) {
super(view);
mView = view;
mTaskCountView = (TextView) view.findViewById(R.id.task_list_count);
mTaskNameView = (TextView) view.findViewById(R.id.task_list_name);
mTaskDeleteButton = (Button) view.findViewById(R.id.task_list_delete);
}
@Override
public String toString() {
return super.toString() + " '" + mTaskNameView.getText() + "'";
}
}
}

View File

@@ -10,22 +10,22 @@ import android.widget.TextView;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.dao.Task; import com.wismna.geoffroy.donext.dao.Task;
import com.wismna.geoffroy.donext.fragments.TasksFragment.OnListFragmentInteractionListener;
import java.util.List; import java.util.List;
//import com.wismna.geoffroy.donext.fragments.TasksFragment.OnListFragmentInteractionListener;
/** /**
* {@link RecyclerView.Adapter} that can display a {@link Task} and makes a call to the * {@link RecyclerView.Adapter} that can display a {@link Task}.
* specified {@link OnListFragmentInteractionListener}.
*/ */
public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.ViewHolder> { public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerViewAdapter.ViewHolder> {
private final List<Task> mValues; private final List<Task> mValues;
private final OnListFragmentInteractionListener mListener; //private final OnListFragmentInteractionListener mListener;
public TaskAdapter(List<Task> items, OnListFragmentInteractionListener listener) { public TaskRecyclerViewAdapter(List<Task> items/*, OnListFragmentInteractionListener listener*/) {
mValues = items; mValues = items;
mListener = listener; //mListener = listener;
} }
@Override @Override
@@ -59,7 +59,7 @@ public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.ViewHolder> {
break; break;
} }
holder.mView.setOnClickListener(new View.OnClickListener() { /*holder.mView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (null != mListener) { if (null != mListener) {
@@ -68,7 +68,7 @@ public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.ViewHolder> {
mListener.onListFragmentInteraction(holder.mItem); mListener.onListFragmentInteraction(holder.mItem);
} }
} }
}); });*/
} }
@Override @Override

View File

@@ -71,7 +71,7 @@ public class Task {
this.deleted = deleted; this.deleted = deleted;
} }
public long getTaskList() { public long getTaskListId() {
return taskList; return taskList;
} }

View File

@@ -8,6 +8,7 @@ public class TaskList {
private long id; private long id;
private String name; private String name;
private long taskCount; private long taskCount;
private int order;
public long getId() { public long getId() {
return id; return id;
@@ -25,10 +26,24 @@ public class TaskList {
this.name = comment; this.name = comment;
} }
// Will be used by the ArrayAdapter in the ListView public long getTaskCount() {
return taskCount;
}
public void setTaskCount(long taskCount) {
this.taskCount = taskCount;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
@Override @Override
public String toString() { public String toString() {
return name; return name;
} }
} }

View File

@@ -9,9 +9,10 @@ import android.database.sqlite.SQLiteOpenHelper;
* Database helper class that contains table and column names as well as handles database creation * Database helper class that contains table and column names as well as handles database creation
*/ */
public class DatabaseHelper extends SQLiteOpenHelper { public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "donext.db"; private static final String DATABASE_NAME = "donext.db";
public static final String COLUMN_ID = "_id"; public static final String COLUMN_ID = "_id";
public static final String COLUMN_ORDER = "displayorder";
public static final String TASKLIST_TABLE_NAME = "tasklist"; public static final String TASKLIST_TABLE_NAME = "tasklist";
public static final String TASKLIST_COLUMN_NAME = "name"; public static final String TASKLIST_COLUMN_NAME = "name";
@@ -19,7 +20,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private static final String TASKLIST_TABLE_CREATE = private static final String TASKLIST_TABLE_CREATE =
"CREATE TABLE " + TASKLIST_TABLE_NAME + " (" + "CREATE TABLE " + TASKLIST_TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
TASKLIST_COLUMN_NAME + " TEXT NOT NULL);"; TASKLIST_COLUMN_NAME + " TEXT NOT NULL, " +
COLUMN_ORDER + " INTEGER);";
public static final String TASKS_TABLE_NAME = "tasks"; public static final String TASKS_TABLE_NAME = "tasks";
public static final String TASKS_COLUMN_NAME = "name"; public static final String TASKS_COLUMN_NAME = "name";
@@ -38,6 +40,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
TASKS_COLUMN_CYCLE + " INTEGER DEFAULT 0, " + TASKS_COLUMN_CYCLE + " INTEGER DEFAULT 0, " +
TASKS_COLUMN_DONE + " INTEGER DEFAULT 0, " + TASKS_COLUMN_DONE + " INTEGER DEFAULT 0, " +
TASKS_COLUMN_DELETED + " INTEGER DEFAULT 0, " + TASKS_COLUMN_DELETED + " INTEGER DEFAULT 0, " +
COLUMN_ORDER + " INTEGER, " +
TASKS_COLUMN_LIST + " INTEGER NOT NULL, " + TASKS_COLUMN_LIST + " INTEGER NOT NULL, " +
"FOREIGN KEY(" + TASKS_COLUMN_LIST + ") REFERENCES " + "FOREIGN KEY(" + TASKS_COLUMN_LIST + ") REFERENCES " +
TASKLIST_TABLE_NAME + "(" + COLUMN_ID + ")" + TASKLIST_TABLE_NAME + "(" + COLUMN_ID + ")" +
@@ -55,6 +58,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 1)
{
// Add new Order column
db.execSQL("ALTER TABLE " + TASKLIST_TABLE_NAME + " ADD COLUMN " + COLUMN_ORDER + " INTEGER");
}
} }
} }

View File

@@ -71,15 +71,6 @@ public class TaskDataAccess {
DatabaseHelper.COLUMN_ID + " = " + taskId, null); DatabaseHelper.COLUMN_ID + " = " + taskId, null);
} }
/*public Cursor deleteTask(Cursor taskCursor) {
Task task = cursorToTask(taskCursor);
long id = task.getId();
//System.out.println("Task deleted with id: " + id);
database.delete(DatabaseHelper.TASKS_TABLE_NAME, DatabaseHelper.COLUMN_ID
+ " = " + id, null);
return getAllTasksCursor();
}*/
public Task getTask(long id) public Task getTask(long id)
{ {
Cursor cursor = getTaskCursor(id); Cursor cursor = getTaskCursor(id);

View File

@@ -19,7 +19,8 @@ public class TaskListDataAccess {
// Database fields // Database fields
private SQLiteDatabase database; private SQLiteDatabase database;
private DatabaseHelper dbHelper; private DatabaseHelper dbHelper;
//private String[] taskListColumns = {DatabaseHelper.COLUMN_ID, DatabaseHelper.TASKLIST_COLUMN_NAME}; private String[] taskListColumns =
{DatabaseHelper.COLUMN_ID, DatabaseHelper.TASKLIST_COLUMN_NAME, DatabaseHelper.COLUMN_ORDER};
public TaskListDataAccess(Context context) { public TaskListDataAccess(Context context) {
dbHelper = new DatabaseHelper(context); dbHelper = new DatabaseHelper(context);
@@ -33,9 +34,10 @@ public class TaskListDataAccess {
dbHelper.close(); dbHelper.close();
} }
/*public TaskList createTaskList(String name) { public TaskList createTaskList(String name, int order) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(DatabaseHelper.TASKLIST_COLUMN_NAME, name); values.put(DatabaseHelper.TASKLIST_COLUMN_NAME, name);
values.put(DatabaseHelper.COLUMN_ORDER, order);
long insertId = database.insert(DatabaseHelper.TASKLIST_TABLE_NAME, null, long insertId = database.insert(DatabaseHelper.TASKLIST_TABLE_NAME, null,
values); values);
Cursor cursor = database.query(DatabaseHelper.TASKLIST_TABLE_NAME, Cursor cursor = database.query(DatabaseHelper.TASKLIST_TABLE_NAME,
@@ -45,31 +47,27 @@ public class TaskListDataAccess {
TaskList newTaskList = cursorToTaskList(cursor); TaskList newTaskList = cursorToTaskList(cursor);
cursor.close(); cursor.close();
return newTaskList; return newTaskList;
}*/
public Cursor createTaskList(String name) {
ContentValues values = new ContentValues();
values.put(DatabaseHelper.TASKLIST_COLUMN_NAME, name);
database.insert(DatabaseHelper.TASKLIST_TABLE_NAME, null, values);
return getAllTaskListsCursor();
} }
/*public void deleteTaskList(TaskList comment) { public void deleteTaskList(long id) {
long id = comment.getId(); // Delete all related tasks
System.out.println("Comment deleted with id: " + id);
database.delete(DatabaseHelper.TASKLIST_TABLE_NAME, DatabaseHelper.COLUMN_ID
+ " = " + id, null);
}*/
public Cursor deleteTaskList(Cursor taskListCursor) {
TaskList taskList = cursorToTaskList(taskListCursor);
long id = taskList.getId();
System.out.println("Task list deleted with id: " + id);
database.delete(DatabaseHelper.TASKS_TABLE_NAME, DatabaseHelper.TASKS_COLUMN_LIST database.delete(DatabaseHelper.TASKS_TABLE_NAME, DatabaseHelper.TASKS_COLUMN_LIST
+ " = " + id, null); + " = " + id, null);
// Delete list
database.delete(DatabaseHelper.TASKLIST_TABLE_NAME, DatabaseHelper.COLUMN_ID database.delete(DatabaseHelper.TASKLIST_TABLE_NAME, DatabaseHelper.COLUMN_ID
+ " = " + id, null); + " = " + id, null);
return getAllTaskListsCursor(); }
public void updateOrder(long id, int order) {
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.COLUMN_ORDER, order);
database.update(DatabaseHelper.TASKLIST_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
}
public void updateName(long id, String name) {
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.TASKLIST_COLUMN_NAME, name);
database.update(DatabaseHelper.TASKLIST_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
} }
public List<TaskList> getAllTaskLists() { public List<TaskList> getAllTaskLists() {
@@ -96,7 +94,8 @@ public class TaskListDataAccess {
" FROM " + DatabaseHelper.TASKS_TABLE_NAME + " FROM " + DatabaseHelper.TASKS_TABLE_NAME +
" WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " + " WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " +
DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + ") AS " + DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT + DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + ") AS " + DatabaseHelper.TASKLIST_COLUMN_TASK_COUNT +
" FROM " + DatabaseHelper.TASKLIST_TABLE_NAME, " FROM " + DatabaseHelper.TASKLIST_TABLE_NAME +
" ORDER BY " + DatabaseHelper.COLUMN_ORDER + " ASC ",
null); null);
} }
@@ -104,6 +103,9 @@ public class TaskListDataAccess {
TaskList taskList = new TaskList(); TaskList taskList = new TaskList();
taskList.setId(cursor.getLong(0)); taskList.setId(cursor.getLong(0));
taskList.setName(cursor.getString(1)); taskList.setName(cursor.getString(1));
taskList.setOrder(cursor.getInt(2));
if (cursor.getColumnCount() == 4)
taskList.setTaskCount(cursor.getLong(3));
return taskList; return taskList;
} }
} }

View File

@@ -11,7 +11,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent; import android.view.KeyEvent;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.TaskAdapter; import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter;
public class ConfirmDialogFragment extends DialogFragment { public class ConfirmDialogFragment extends DialogFragment {
public interface ConfirmDialogListener { public interface ConfirmDialogListener {
@@ -20,25 +20,26 @@ public class ConfirmDialogFragment extends DialogFragment {
} }
private ConfirmDialogListener confirmDialogListener; private ConfirmDialogListener confirmDialogListener;
private TaskAdapter taskAdapter; //private TaskRecyclerViewAdapter taskRecyclerViewAdapter;
private RecyclerView recyclerView; private RecyclerView recyclerView;
private String message; private String message;
public static ConfirmDialogFragment newInstance( public static ConfirmDialogFragment newInstance(
TaskAdapter taskAdapter, String message, RecyclerView recyclerView) { /*TaskRecyclerViewAdapter taskRecyclerViewAdapter, */String message, RecyclerView recyclerView) {
Bundle args = new Bundle(); //Bundle args = new Bundle();
ConfirmDialogFragment fragment = new ConfirmDialogFragment(); ConfirmDialogFragment fragment = new ConfirmDialogFragment();
fragment.taskAdapter = taskAdapter; //fragment.taskRecyclerViewAdapter = taskRecyclerViewAdapter;
fragment.message = message; fragment.message = message;
fragment.recyclerView = recyclerView; fragment.recyclerView = recyclerView;
fragment.setArguments(args); //fragment.setArguments(args);
return fragment; return fragment;
} }
public TaskAdapter getTaskAdapter() { public TaskRecyclerViewAdapter getTaskRecyclerViewAdapter() {
return taskAdapter; //return taskRecyclerViewAdapter;
return (TaskRecyclerViewAdapter) recyclerView.getAdapter();
} }
public RecyclerView getRecyclerView() { public RecyclerView getRecyclerView() {
@@ -53,7 +54,7 @@ public class ConfirmDialogFragment extends DialogFragment {
Bundle args = getArguments(); Bundle args = getArguments();
int itemPosition = args.getInt("ItemPosition"); int itemPosition = args.getInt("ItemPosition");
getTaskAdapter().notifyItemChanged(itemPosition); getTaskRecyclerViewAdapter().notifyItemChanged(itemPosition);
} }
@Override @Override
@@ -93,7 +94,6 @@ public class ConfirmDialogFragment extends DialogFragment {
.setOnKeyListener(new DialogInterface.OnKeyListener() { .setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override @Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
//return false;
return keyCode != KeyEvent.KEYCODE_BACK; return keyCode != KeyEvent.KEYCODE_BACK;
} }
}); });

View File

@@ -7,7 +7,6 @@ import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
@@ -16,9 +15,8 @@ import android.widget.RadioGroup;
import android.widget.Spinner; import android.widget.Spinner;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.TaskAdapter; import com.wismna.geoffroy.donext.dao.Task;
import com.wismna.geoffroy.donext.dao.TaskList; import com.wismna.geoffroy.donext.dao.TaskList;
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
import java.util.List; import java.util.List;
@@ -28,20 +26,8 @@ import java.util.List;
*/ */
public class TaskDialogFragment extends DialogFragment { public class TaskDialogFragment extends DialogFragment {
public TaskAdapter getTaskAdapter() { public Task getTask() {
return taskAdapter; return task;
}
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 /** The activity that creates an instance of this dialog fragment must
@@ -50,22 +36,20 @@ public class TaskDialogFragment extends DialogFragment {
public interface NewTaskListener { public interface NewTaskListener {
void onNewTaskDialogPositiveClick(DialogFragment dialog); void onNewTaskDialogPositiveClick(DialogFragment dialog);
void onNewTaskDialogNeutralClick(DialogFragment dialog); void onNewTaskDialogNeutralClick(DialogFragment dialog);
//void onDialogNegativeClick(DialogFragment dialog);
} }
private TaskAdapter taskAdapter;
private RecyclerView recyclerView;
// Use this instance of the interface to deliver action events // Use this instance of the interface to deliver action events
private NewTaskListener mListener; private NewTaskListener mListener;
private Task task;
private List<TaskList> taskLists;
public static TaskDialogFragment newInstance(TaskAdapter taskAdapter, RecyclerView recyclerView) { public static TaskDialogFragment newInstance(Task task, List<TaskList> taskLists) {
Bundle args = new Bundle(); Bundle args = new Bundle();
TaskDialogFragment fragment = new TaskDialogFragment(); TaskDialogFragment fragment = new TaskDialogFragment();
fragment.setTaskAdapter(taskAdapter);
fragment.setRecyclerView(recyclerView);
fragment.setArguments(args); fragment.setArguments(args);
fragment.task = task;
fragment.taskLists = taskLists;
return fragment; return fragment;
} }
@@ -90,7 +74,7 @@ public class TaskDialogFragment extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater // Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.new_task, null); View view = inflater.inflate(R.layout.fragment_task_details, null);
// Inflate and set the layout for the dialog // Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout // Pass null as the parent view because its going in the dialog layout
@@ -106,26 +90,19 @@ public class TaskDialogFragment extends DialogFragment {
.setNegativeButton(R.string.new_task_cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.new_task_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
// Send the negative button event back to the host activity // Send the negative button event back to the host activity
//mListener.onDialogNegativeClick(NoticeDialogFragment.this);
// Canceled creation, nothing to do // Canceled creation, nothing to do
TaskDialogFragment.this.getDialog().cancel(); TaskDialogFragment.this.getDialog().cancel();
} }
}); });
// Access database to retrieve task lists
TaskListDataAccess dataAccess = new TaskListDataAccess(getActivity());
dataAccess.open();
// Populate spinner with task lists // Populate spinner with task lists
Spinner spinner = (Spinner) view.findViewById(R.id.new_task_list); Spinner spinner = (Spinner) view.findViewById(R.id.new_task_list);
// Create an ArrayAdapter using the string array and a default spinner layout // Create an ArrayAdapter using the string array and a default spinner layout
List<TaskList> taskLists = dataAccess.getAllTaskLists();
ArrayAdapter<TaskList> adapter = new ArrayAdapter<>( ArrayAdapter<TaskList> adapter = new ArrayAdapter<>(
getActivity(), android.R.layout.simple_spinner_item, taskLists); getActivity(), android.R.layout.simple_spinner_item, taskLists);
// Specify the layout to use when the list of choices appears // Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter); spinner.setAdapter(adapter);
dataAccess.close();
// Auto set list value to current tab // Auto set list value to current tab
Bundle args = getArguments(); Bundle args = getArguments();
@@ -133,33 +110,32 @@ public class TaskDialogFragment extends DialogFragment {
spinner.setSelection(id); spinner.setSelection(id);
// Set other properties if they exist // Set other properties if they exist
EditText titleText = (EditText) view.findViewById(R.id.new_task_name); if (task != null) {
titleText.setText(args.getString("title")); EditText titleText = (EditText) view.findViewById(R.id.new_task_name);
EditText descText = (EditText) view.findViewById(R.id.new_task_description); titleText.setText(task.getName());
descText.setText(args.getString("description")); EditText descText = (EditText) view.findViewById(R.id.new_task_description);
RadioGroup priorityGroup = (RadioGroup) view.findViewById(R.id.new_task_priority); descText.setText(task.getDescription());
int priority = args.getInt("priority"); RadioGroup priorityGroup = (RadioGroup) view.findViewById(R.id.new_task_priority);
switch (priority) switch (task.getPriority()) {
{ case 0:
case 0: priorityGroup.check(R.id.new_task_priority_low);
priorityGroup.check(R.id.new_task_priority_low); break;
break; case 1:
case 1: priorityGroup.check(R.id.new_task_priority_normal);
priorityGroup.check(R.id.new_task_priority_normal); break;
break; case 2:
case 2: priorityGroup.check(R.id.new_task_priority_high);
priorityGroup.check(R.id.new_task_priority_high); break;
break; }
}
// Add a Delete button in Edit mode
if (args.getLong("id") != 0)
builder.setNeutralButton(R.string.new_task_delete, new DialogInterface.OnClickListener() { builder.setNeutralButton(R.string.new_task_delete, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mListener.onNewTaskDialogNeutralClick(TaskDialogFragment.this); mListener.onNewTaskDialogNeutralClick(TaskDialogFragment.this);
} }
}); });
setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light); setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light);
}
return builder.create(); return builder.create();
} }
} }

View File

@@ -0,0 +1,99 @@
package com.wismna.geoffroy.donext.fragments;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import com.wismna.geoffroy.donext.ItemTouchHelpers.TaskListTouchHelper;
import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.TaskListRecyclerViewAdapter;
import com.wismna.geoffroy.donext.dao.TaskList;
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
/**
* A fragment representing a list of Items.
*/
public class TaskListsFragment extends Fragment {
private TaskListRecyclerViewAdapter taskListRecyclerViewAdapter;
private TaskListDataAccess taskListDataAccess;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public TaskListsFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get all task lists
taskListDataAccess = new TaskListDataAccess(getContext());
taskListDataAccess.open();
taskListRecyclerViewAdapter =
new TaskListRecyclerViewAdapter(taskListDataAccess.getAllTaskLists(), getContext());
taskListDataAccess.close();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_tasklists, container, false);
Button createTaskListButton = (Button) view.findViewById(R.id.new_task_list_button);
createTaskListButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editText = (EditText) view.findViewById(R.id.new_task_list_name);
String text = editText.getText().toString();
if (text.matches("")) return;
int position = taskListRecyclerViewAdapter.getItemCount();
taskListDataAccess.open();
TaskList taskList = taskListDataAccess.createTaskList(text, position);
taskListDataAccess.close();
taskListRecyclerViewAdapter.add(taskList, position);
editText.setText("");
toggleVisibleCreateNewTaskListLayout(view);
}
});
// Set the adapter
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.task_lists_view);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.setAdapter(taskListRecyclerViewAdapter);
// Set the Touch Helper
ItemTouchHelper.Callback callback = new TaskListTouchHelper(taskListRecyclerViewAdapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(recyclerView);
toggleVisibleCreateNewTaskListLayout(view);
return view;
}
private void toggleVisibleCreateNewTaskListLayout(View view) {
RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.new_task_list_layout);
int taskListCount = taskListRecyclerViewAdapter.getItemCount();
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "3");
int maxTaskLists = Integer.valueOf(maxTaskListsString);
if (taskListCount >= maxTaskLists) layout.setVisibility(View.GONE);
else layout.setVisibility(View.VISIBLE);
}
}

View File

@@ -1,7 +1,6 @@
package com.wismna.geoffroy.donext.fragments; package com.wismna.geoffroy.donext.fragments;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.os.Bundle; 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;
@@ -15,28 +14,18 @@ import android.widget.TextView;
import com.wismna.geoffroy.donext.ItemTouchHelpers.TaskTouchHelper; import com.wismna.geoffroy.donext.ItemTouchHelpers.TaskTouchHelper;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.TaskAdapter; import com.wismna.geoffroy.donext.activities.MainActivity;
import com.wismna.geoffroy.donext.dao.Task; import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter;
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; import com.wismna.geoffroy.donext.widgets.NoScrollingLayoutManager;
/** /**
* A fragment representing a list of Items. * A fragment representing a list of Items.
* <p/>
* Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener}
* interface.
*/ */
public class TasksFragment extends Fragment { public class TasksFragment extends Fragment {
/*public interface TasksFragmentListener {
void onItemClick(View view, int position);
}*/
private static final String TASK_LIST_ID = "task_list_id"; private static final String TASK_LIST_ID = "task_list_id";
private long taskListId = -1; private long taskListId = -1;
//private TasksFragmentListener tasksFragmentListener;
private OnListFragmentInteractionListener mListener;
/** /**
* Mandatory empty constructor for the fragment manager to instantiate the * Mandatory empty constructor for the fragment manager to instantiate the
@@ -65,12 +54,11 @@ public class TasksFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_task_list, container, false); View view = inflater.inflate(R.layout.fragment_tasks, container, false);
final Context context = view.getContext(); final Context context = view.getContext();
// 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 NoScrollingLayoutManager(context)); recyclerView.setLayoutManager(new NoScrollingLayoutManager(context));
TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext()); TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext());
@@ -85,89 +73,39 @@ public class TasksFragment extends Fragment {
totalTasksView.setText(String.valueOf(taskDataAccess.getTaskCount(taskListId) + " tasks")); totalTasksView.setText(String.valueOf(taskDataAccess.getTaskCount(taskListId) + " tasks"));
// Set RecyclerView Adapter // Set RecyclerView Adapter
final TaskAdapter taskAdapter = new TaskAdapter(taskDataAccess.getAllTasks(taskListId), mListener); final TaskRecyclerViewAdapter taskRecyclerViewAdapter = new TaskRecyclerViewAdapter(taskDataAccess.getAllTasks(taskListId));
recyclerView.setAdapter(taskAdapter); recyclerView.setAdapter(taskRecyclerViewAdapter);
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
ItemTouchHelper.Callback callback = new TaskTouchHelper( ItemTouchHelper.Callback callback = new TaskTouchHelper(
taskAdapter, taskDataAccess, getFragmentManager(), recyclerView); taskRecyclerViewAdapter, 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
//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() {
@Override @Override
public void onItemClick(View view, int position) { public void onItemClick(View view, int position) {
//tasksFragmentListener.onItemClick(view, position); Bundle args = new Bundle();
args.putInt("position", position);
TextView idTextView = (TextView) view.findViewById(R.id.task_id); // Set current tab value to new task dialog
//mToast.setText("Item " + idTextView.getText() + " clicked!"); ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.container);
//mToast.show(); args.putInt("list", viewPager.getCurrentItem());
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(taskAdapter, recyclerView); TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(/*taskRecyclerViewAdapter, recyclerView,*/
taskRecyclerViewAdapter.getItem(position),
((MainActivity.SectionsPagerAdapter)viewPager.getAdapter()).getAllItems());
Bundle args = new Bundle(); taskDialogFragment.setArguments(args);
args.putLong("id", Long.valueOf(idTextView.getText().toString())); taskDialogFragment.show(manager, "Edit task");
args.putInt("position", position); }
})
// Set current tab value to new task dialog
ViewPager viewPager =(ViewPager) getActivity().findViewById(R.id.container);
args.putInt("list", viewPager.getCurrentItem());
// Set title
TextView titleTextView = (TextView) view.findViewById(R.id.task_name);
args.putString("title", titleTextView.getText().toString());
// Set description
TextView descTextView = (TextView) view.findViewById(R.id.task_description);
args.putString("description", descTextView.getText().toString());
// Set priority
int priority = 1;
if (titleTextView.getCurrentTextColor() == Color.LTGRAY) priority = 0;
else if (titleTextView.getTypeface().isBold()) priority = 2;
args.putInt("priority", priority);
taskDialogFragment.setArguments(args);
taskDialogFragment.show(manager, "Edit task");
}
})
); );
return view; return view;
} }
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener");
}
}
@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 OnListFragmentInteractionListener {
void onListFragmentInteraction(Task item);
}
} }

View File

@@ -1,83 +0,0 @@
<?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>

View File

@@ -0,0 +1,14 @@
<?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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.TaskListActivity">
<fragment
android:name="com.wismna.geoffroy.donext.fragments.TaskListsFragment"
android:id="@+id/fragment_task_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_tasklists" />
</LinearLayout>

View File

@@ -1,29 +1,34 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight" android:layout_height="wrap_content"
android:padding="6dip"> android:orientation="horizontal"
android:foreground="?selectableItemBackground" >
<TextView <TextView
android:id="@+id/task_list_count" android:id="@+id/task_list_count"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_alignParentLeft="true"
android:text="test" android:layout_alignParentStart="true"
android:padding="10dp"
android:textAppearance="?android:attr/textAppearanceMedium"/> android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView <EditText
android:id="@+id/task_list_name" android:id="@+id/task_list_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="@id/task_list_count" android:layout_toRightOf="@id/task_list_count"
android:layout_centerVertical="true" android:layout_toEndOf="@id/task_list_count"
android:text="Name" android:inputType="text"
android:textAppearance="?android:attr/textAppearanceLarge"/> android:textAppearance="?android:attr/textAppearanceLarge"/>
<Button <Button
android:id="@+id/task_list_delete"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:padding="10dp"
android:text="@string/task_list_delete" android:text="@string/task_list_delete"
android:onClick="onDeleteTaskList" /> android:onClick="onDeleteTaskList" />
</RelativeLayout> </RelativeLayout>

View File

@@ -23,12 +23,22 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:onClick="onCreateTaskList" android:layout_alignParentEnd="true"
android:text="@string/task_list_new_list_create"/> android:text="@string/task_list_new_list_create"/>
</RelativeLayout> </RelativeLayout>
<ListView <android.support.v7.widget.RecyclerView
android:id="@android:id/list" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/task_lists_view"
android:name="com.wismna.geoffroy.donext.fragments.TaskListFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
</ListView> android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context=".fragments.TaskListsFragment"
tools:listitem="@layout/fragment_tasklist" />
</LinearLayout> </LinearLayout>

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/task_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@@ -6,9 +6,7 @@
<string name="action_editTabs">Edit lists</string> <string name="action_editTabs">Edit lists</string>
<string name="action_about">About</string> <string name="action_about">About</string>
<string name="action_new_task">New task</string> <string name="action_new_task">New task</string>
<string name="section_format">Hello World from section: %1$d</string>
<string name="settings_activity_title">Settings</string> <string name="settings_activity_title">Settings</string>
<string name="task_list_activity_title">List edition</string>
<!-- Strings related to Task List edition --> <!-- Strings related to Task List edition -->
<string name="task_list_new_list_hint">New list name</string> <string name="task_list_new_list_hint">New list name</string>