Skip to content

Commit f58e7ba

Browse files
committed
Merge branch 'todo-mvp' into todo-mvp-loaders
2 parents 66a615f + f4ebc23 commit f58e7ba

File tree

2 files changed

+63
-12
lines changed

2 files changed

+63
-12
lines changed

todoapp/app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksScreenTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,55 @@ public void markTaskAsActiveOnDetailScreen_taskIsActiveInList() {
345345
hasSibling(withText(TITLE1)))).check(matches(not(isChecked())));
346346
}
347347

348+
@Test
349+
public void markTaskAsAcompleteAndActiveOnDetailScreen_taskIsActiveInList() {
350+
viewAllTasks();
351+
352+
// Add 1 active task
353+
createTask(TITLE1, DESCRIPTION);
354+
355+
// Click on the task on the list
356+
onView(withText(TITLE1)).perform(click());
357+
358+
// Click on the checkbox in task details screen
359+
onView(withId(R.id.task_detail_complete)).perform(click());
360+
361+
// Click again to restore it to original state
362+
onView(withId(R.id.task_detail_complete)).perform(click());
363+
364+
// Click on the navigation up button to go back to the list
365+
onView(withContentDescription("Navigate up")).perform(click());
366+
367+
// Check that the task is marked as active
368+
onView(allOf(withId(R.id.complete),
369+
hasSibling(withText(TITLE1)))).check(matches(not(isChecked())));
370+
}
371+
372+
@Test
373+
public void markTaskAsActiveAndCompleteOnDetailScreen_taskIsCompleteInList() {
374+
viewAllTasks();
375+
376+
// Add 1 completed task
377+
createTask(TITLE1, DESCRIPTION);
378+
clickCheckBoxForTask(TITLE1);
379+
380+
// Click on the task on the list
381+
onView(withText(TITLE1)).perform(click());
382+
383+
// Click on the checkbox in task details screen
384+
onView(withId(R.id.task_detail_complete)).perform(click());
385+
386+
// Click again to restore it to original state
387+
onView(withId(R.id.task_detail_complete)).perform(click());
388+
389+
// Click on the navigation up button to go back to the list
390+
onView(withContentDescription("Navigate up")).perform(click());
391+
392+
// Check that the task is marked as active
393+
onView(allOf(withId(R.id.complete),
394+
hasSibling(withText(TITLE1)))).check(matches(isChecked()));
395+
}
396+
348397
@Test
349398
public void orientationChange_FilterActivePersists() {
350399

todoapp/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailFragment.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.example.android.architecture.blueprints.todoapp.taskdetail;
1818

19+
import static com.google.common.base.Preconditions.checkNotNull;
20+
1921
import android.app.Activity;
2022
import android.content.Intent;
2123
import android.os.Bundle;
@@ -31,14 +33,13 @@
3133
import android.view.View;
3234
import android.view.ViewGroup;
3335
import android.widget.CheckBox;
36+
import android.widget.CompoundButton;
3437
import android.widget.TextView;
3538

3639
import com.example.android.architecture.blueprints.todoapp.R;
3740
import com.example.android.architecture.blueprints.todoapp.addedittask.AddEditTaskActivity;
3841
import com.example.android.architecture.blueprints.todoapp.addedittask.AddEditTaskFragment;
3942

40-
import static com.google.common.base.Preconditions.checkNotNull;
41-
4243
/**
4344
* Main UI for the task detail screen.
4445
*/
@@ -142,16 +143,17 @@ public void showDescription(String description) {
142143
@Override
143144
public void showCompletionStatus(final boolean complete) {
144145
mDetailCompleteStatus.setChecked(complete);
145-
mDetailCompleteStatus.setOnClickListener(new View.OnClickListener() {
146-
@Override
147-
public void onClick(View v) {
148-
if (complete) {
149-
mPresenter.activateTask();
150-
} else {
151-
mPresenter.completeTask();
152-
}
153-
}
154-
});
146+
mDetailCompleteStatus.setOnCheckedChangeListener(
147+
new CompoundButton.OnCheckedChangeListener() {
148+
@Override
149+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
150+
if (isChecked) {
151+
mPresenter.completeTask();
152+
} else {
153+
mPresenter.activateTask();
154+
}
155+
}
156+
});
155157
}
156158

157159
@Override

0 commit comments

Comments
 (0)