mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
No more scrolling on the toolbar
Display remaining task count on bottom of RecyclerView Total task count does not query the DB anymore
This commit is contained in:
@@ -53,10 +53,8 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
|||||||
|
|
||||||
// Handle inline name change
|
// Handle inline name change
|
||||||
holder.mTaskNameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
holder.mTaskNameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||||
// TODO: handle exception when onFocus is lost after click on Delete
|
|
||||||
@Override
|
@Override
|
||||||
public void onFocusChange(View v, boolean hasFocus) {
|
public void onFocusChange(View v, boolean hasFocus) {
|
||||||
|
|
||||||
EditText editText = (EditText) v;
|
EditText editText = (EditText) v;
|
||||||
String name = editText.getText().toString();
|
String name = editText.getText().toString();
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@ import android.support.v7.widget.helper.ItemTouchHelper;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
@@ -88,16 +89,13 @@ public class TasksFragment extends Fragment implements
|
|||||||
taskDataAccess = new TaskDataAccess(view.getContext());
|
taskDataAccess = new TaskDataAccess(view.getContext());
|
||||||
taskDataAccess.open();
|
taskDataAccess.open();
|
||||||
|
|
||||||
// Set total cycles
|
|
||||||
UpdateCycleCount();
|
|
||||||
|
|
||||||
// Set total count
|
|
||||||
UpdateTaskCount();
|
|
||||||
|
|
||||||
// Set RecyclerView Adapter
|
// Set RecyclerView Adapter
|
||||||
taskRecyclerViewAdapter = new TaskRecyclerViewAdapter(taskDataAccess.getAllTasks(taskListId));
|
taskRecyclerViewAdapter = new TaskRecyclerViewAdapter(taskDataAccess.getAllTasks(taskListId));
|
||||||
recyclerView.setAdapter(taskRecyclerViewAdapter);
|
recyclerView.setAdapter(taskRecyclerViewAdapter);
|
||||||
|
|
||||||
|
// Set total cycles
|
||||||
|
UpdateCycleCount();
|
||||||
|
|
||||||
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
|
||||||
@@ -120,13 +118,26 @@ public class TasksFragment extends Fragment implements
|
|||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getFragmentManager();
|
||||||
TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(
|
TaskDialogFragment taskDialogFragment = TaskDialogFragment.newInstance(
|
||||||
taskRecyclerViewAdapter.getItem(position),
|
taskRecyclerViewAdapter.getItem(position),
|
||||||
((MainActivity.SectionsPagerAdapter)viewPager.getAdapter()).getAllItems(), TasksFragment.this);
|
((MainActivity.SectionsPagerAdapter) viewPager.getAdapter()).getAllItems(), TasksFragment.this);
|
||||||
|
|
||||||
taskDialogFragment.setArguments(args);
|
taskDialogFragment.setArguments(args);
|
||||||
taskDialogFragment.show(manager, "Edit task");
|
taskDialogFragment.show(manager, "Edit task");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Set total count
|
||||||
|
UpdateTaskCount();
|
||||||
|
|
||||||
|
// Handle updating remaining task count in a listener to be sure that the layout is available
|
||||||
|
recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreDraw() {
|
||||||
|
UpdateRemainingTaskCount();
|
||||||
|
recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,8 +147,20 @@ public class TasksFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTaskCount() {
|
private void UpdateTaskCount() {
|
||||||
|
int totalTasks = taskRecyclerViewAdapter.getItemCount();
|
||||||
TextView totalTasksView = (TextView) view.findViewById(R.id.total_task_count);
|
TextView totalTasksView = (TextView) view.findViewById(R.id.total_task_count);
|
||||||
totalTasksView.setText(String.valueOf(taskDataAccess.getTaskCount(taskListId) + " tasks"));
|
totalTasksView.setText(String.valueOf(totalTasks + " tasks"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateRemainingTaskCount() {
|
||||||
|
TextView remainingTasksView = (TextView) view.findViewById(R.id.remaining_task_count);
|
||||||
|
NoScrollingLayoutManager layoutManager = (NoScrollingLayoutManager) recyclerView.getLayoutManager();
|
||||||
|
int remainingTaskCount = taskRecyclerViewAdapter.getItemCount() - layoutManager.getChildCount();
|
||||||
|
if (remainingTaskCount == 0)
|
||||||
|
remainingTasksView.setText("");
|
||||||
|
else
|
||||||
|
remainingTasksView.setText(String.valueOf(
|
||||||
|
remainingTaskCount + " task" + (remainingTaskCount > 1 ? "s" : "") +" remaining"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Performs an action on a task: done, next or delete */
|
/** Performs an action on a task: done, next or delete */
|
||||||
@@ -214,9 +237,10 @@ public class TasksFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateCycleCount();
|
UpdateCycleCount();
|
||||||
UpdateTaskCount();
|
|
||||||
|
|
||||||
taskDataAccess.close();
|
taskDataAccess.close();
|
||||||
|
|
||||||
|
UpdateTaskCount();
|
||||||
|
UpdateRemainingTaskCount();
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
@@ -285,18 +309,22 @@ public class TasksFragment extends Fragment implements
|
|||||||
priorityRadio.getText().toString(),
|
priorityRadio.getText().toString(),
|
||||||
taskList.getId());
|
taskList.getId());
|
||||||
|
|
||||||
UpdateTaskCount();
|
|
||||||
taskDataAccess.close();
|
taskDataAccess.close();
|
||||||
// Update the corresponding tab adapter
|
|
||||||
|
|
||||||
Bundle args = dialog.getArguments();
|
Bundle args = dialog.getArguments();
|
||||||
// Should never happen because we will have to be on this tab to open the dialog
|
// Should never happen because we will have to be on this tab to open the dialog
|
||||||
if (taskRecyclerViewAdapter == null) return;
|
if (taskRecyclerViewAdapter == null) return;
|
||||||
|
|
||||||
// Add the task
|
// Add the task
|
||||||
if (task == null)
|
if (task == null) {
|
||||||
taskRecyclerViewAdapter.add(newTask, 0);
|
taskRecyclerViewAdapter.add(newTask, 0);
|
||||||
// Update the task
|
recyclerView.scrollToPosition(0);
|
||||||
|
|
||||||
|
// Update the task count
|
||||||
|
UpdateTaskCount();
|
||||||
|
}
|
||||||
|
// Update the task
|
||||||
else {
|
else {
|
||||||
int position = args.getInt("position");
|
int position = args.getInt("position");
|
||||||
// Check if task list was changed
|
// Check if task list was changed
|
||||||
@@ -307,9 +335,10 @@ public class TasksFragment extends Fragment implements
|
|||||||
|
|
||||||
// Add it to the corresponding tab provided it is already instanciated
|
// Add it to the corresponding tab provided it is already instanciated
|
||||||
mAdapter.onTaskListChanged(newTask, listSpinner.getSelectedItemPosition());
|
mAdapter.onTaskListChanged(newTask, listSpinner.getSelectedItemPosition());
|
||||||
}
|
} else taskRecyclerViewAdapter.update(newTask, position);
|
||||||
else taskRecyclerViewAdapter.update(newTask, position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateRemainingTaskCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
android:background="?attr/colorPrimary"
|
android:background="?attr/colorPrimary"
|
||||||
app:layout_scrollFlags="scroll|enterAlways"
|
app:layout_scrollFlags="enterAlways"
|
||||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||||
|
|
||||||
<android.support.design.widget.TabLayout
|
<android.support.design.widget.TabLayout
|
||||||
|
@@ -6,23 +6,31 @@
|
|||||||
android:layout_height="match_parent" >
|
android:layout_height="match_parent" >
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/total_task_cycles"
|
android:id="@+id/total_task_cycles"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="100dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true" />
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentStart="true"/>
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/total_task_count"
|
android:id="@+id/total_task_count"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="100dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true" />
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentEnd="true" />
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/task_list_view"
|
android:id="@+id/task_list_view"
|
||||||
android:name="com.wismna.geoffroy.donext.activities.TaskFragment"
|
android:name="com.wismna.geoffroy.donext.activities.TaskFragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="410dp"
|
||||||
android:layout_marginLeft="16dp"
|
android:layout_marginLeft="16dp"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="16dp"
|
||||||
android:layout_below="@id/total_task_cycles"
|
android:layout_below="@id/total_task_cycles"
|
||||||
app:layoutManager="LinearLayoutManager"
|
app:layoutManager="LinearLayoutManager"
|
||||||
tools:context=".fragments.TasksFragment"
|
tools:context=".fragments.TasksFragment"
|
||||||
tools:listitem="@layout/fragment_task" />
|
tools:listitem="@layout/fragment_task" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/remaining_task_count"
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_below="@id/task_list_view" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Reference in New Issue
Block a user