Skip to content

Commit 34cb43a

Browse files
committed
the filter is now part of the constructor
1 parent 23a23ac commit 34cb43a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ protected void onCreate(Bundle savedInstanceState) {
8282
mTasksPresenter = new TasksPresenter(
8383
tasksOperations,
8484
repository,
85-
tasksFragment
85+
tasksFragment,
86+
TaskFilter.from(TasksFilterType.ALL_TASKS)
8687
);
8788

8889
// Load previously saved state, if available.

todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksPresenter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ public class TasksPresenter implements TasksContract.Presenter, TasksOperations.
4949
private boolean mFirstLoad;
5050

5151
public TasksPresenter(@NonNull TasksOperations tasksOperations, @NonNull TasksRepository tasksRepository,
52-
@NonNull TasksContract.View tasksView) {
52+
@NonNull TasksContract.View tasksView, @NonNull TaskFilter taskFilter) {
5353
mTasksOperations = checkNotNull(tasksOperations, "taskOperations provider cannot be null");
5454
mTasksRepository = checkNotNull(tasksRepository, "tasksRepository cannot be null");
5555
mTasksView = checkNotNull(tasksView, "tasksView cannot be null!");
56+
mCurrentFiltering = checkNotNull(taskFilter, "taskFilter cannot be null!");
5657
mTasksView.setPresenter(this);
5758
}
5859

@@ -73,7 +74,7 @@ public void start() {
7374
@Override
7475
public void onTasksLoaded(Cursor data) {
7576
mTasksView.setLoadingIndicator(false);
76-
if ((null == data) || (data.getCount() > 0)) {
77+
if (data.getCount() > 0) {
7778
// Show the list of tasks
7879
mTasksView.showTasks(data);
7980
// Set the filter label's text.
@@ -165,7 +166,7 @@ public void clearCompletedTasks() {
165166
* Sets the current task filtering type.
166167
*
167168
* @param taskFilter Can be {@link TasksFilterType#ALL_TASKS},
168-
* {@link TasksFilterType#COMPLETED_TASKS}, or {@link TasksFilterType#ACTIVE_TASKS}
169+
* {@link TasksFilterType#COMPLETED_TASKS}, or {@link TasksFilterType#ACTIVE_TASKS}
169170
*/
170171
@Override
171172
public void setFiltering(TaskFilter taskFilter) {

todoapp/app/src/test/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksPresenterTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ public void setupTasksPresenter() {
8080
// inject the mocks in the test the initMocks method needs to be called.
8181
MockitoAnnotations.initMocks(this);
8282

83+
// Given a task filter
84+
when(mBundle.getSerializable(TasksOperations.KEY_TASK_FILTER)).thenReturn(TasksFilterType.ALL_TASKS);
85+
TaskFilter taskFilter = new TaskFilter(mBundle);
86+
8387
// Get a reference to the class under test
84-
mTasksPresenter = new TasksPresenter(mTasksOperations, mTasksRepository, mTasksView);
88+
mTasksPresenter = new TasksPresenter(mTasksOperations, mTasksRepository, mTasksView, taskFilter);
8589

8690
mCompletedTasksCursor = MockCursorProvider.createCompletedTasksCursor();
8791
mActiveTasksCursor = MockCursorProvider.createActiveTasksCursor();

0 commit comments

Comments
 (0)