Skip to content

Commit 18be6c6

Browse files
Merge pull request #693 from android/reactive_master
Migrates master to reactive arch
2 parents 6f21231 + cf82aa2 commit 18be6c6

File tree

39 files changed

+670
-521
lines changed

39 files changed

+670
-521
lines changed

app/build.gradle

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ android {
3232
debug {
3333
minifyEnabled false
3434
testCoverageEnabled true
35-
useProguard false
3635
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3736
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
3837
}
3938

4039
release {
4140
minifyEnabled true
42-
useProguard true
41+
shrinkResources true
4342
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
4443
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
4544
}
@@ -81,6 +80,15 @@ android {
8180
enabled = true
8281
enabledForTests = true
8382
}
83+
84+
compileOptions {
85+
sourceCompatibility = 1.8
86+
targetCompatibility = 1.8
87+
}
88+
89+
kotlinOptions {
90+
jvmTarget = "1.8"
91+
}
8492
}
8593

8694
/*
@@ -107,8 +115,8 @@ dependencies {
107115
kapt "androidx.room:room-compiler:$roomVersion"
108116
implementation "androidx.room:room-ktx:$roomVersion"
109117
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
110-
kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion"
111118
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
119+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"
112120
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
113121
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
114122

app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/tasks/AppNavigationTest.kt renamed to app/src/androidTestMock/java/com/example/android/architecture/blueprints/todoapp/tasks/AppNavigationTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ import org.junit.runner.RunWith
5151
/**
5252
* Tests for the [DrawerLayout] layout component in [TasksActivity] which manages
5353
* navigation within the app.
54+
*
55+
* UI tests usually use [ActivityTestRule] but there's no API to perform an action before
56+
* each test. The workaround is to use `ActivityScenario.launch()` and `ActivityScenario.close()`.
5457
*/
5558
@RunWith(AndroidJUnit4::class)
5659
@LargeTest
@@ -117,6 +120,8 @@ class AppNavigationTest {
117120

118121
// Check that tasks screen was opened.
119122
onView(withId(R.id.tasks_container_layout)).check(matches(isDisplayed()))
123+
// When using ActivityScenario.launch, always call close()
124+
activityScenario.close()
120125
}
121126

122127
@Test
@@ -140,6 +145,8 @@ class AppNavigationTest {
140145
// Check if drawer is open
141146
onView(withId(R.id.drawer_layout))
142147
.check(matches(isOpen(Gravity.START))) // Left drawer is open open.
148+
// When using ActivityScenario.launch, always call close()
149+
activityScenario.close()
143150
}
144151

145152
@Test
@@ -168,6 +175,8 @@ class AppNavigationTest {
168175
// Then check that the drawer is open
169176
onView(withId(R.id.drawer_layout))
170177
.check(matches(isOpen(Gravity.START))) // Left drawer is open open.
178+
// When using ActivityScenario.launch, always call close()
179+
activityScenario.close()
171180
}
172181

173182
@Test
@@ -201,6 +210,8 @@ class AppNavigationTest {
201210
)
202211
).perform(click())
203212
onView(withId(R.id.tasks_container_layout)).check(matches(isDisplayed()))
213+
// When using ActivityScenario.launch, always call close()
214+
activityScenario.close()
204215
}
205216

206217
@Test
@@ -224,5 +235,7 @@ class AppNavigationTest {
224235
// Confirm that if we click back a second time, we end up back at the home screen
225236
pressBack()
226237
onView(withId(R.id.tasks_container_layout)).check(matches(isDisplayed()))
238+
// When using ActivityScenario.launch, always call close()
239+
activityScenario.close()
227240
}
228241
}

app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksActivityTest.kt renamed to app/src/androidTestMock/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksActivityTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ import org.junit.runner.RunWith
5252

5353
/**
5454
* Large End-to-End test for the tasks module.
55+
*
56+
* UI tests usually use [ActivityTestRule] but there's no API to perform an action before
57+
* each test. The workaround is to use `ActivityScenario.launch()` and `ActivityScenario.close()`.
5558
*/
5659
@RunWith(AndroidJUnit4::class)
5760
@LargeTest
@@ -116,6 +119,8 @@ class TasksActivityTest {
116119
onView(withText("NEW TITLE")).check(matches(isDisplayed()))
117120
// Verify previous task is not displayed
118121
onView(withText("TITLE1")).check(doesNotExist())
122+
// Make sure the activity is closed before resetting the db:
123+
activityScenario.close()
119124
}
120125

121126
@Test
@@ -141,6 +146,8 @@ class TasksActivityTest {
141146
onView(withId(R.id.menu_filter)).perform(click())
142147
onView(withText(string.nav_all)).perform(click())
143148
onView(withText("TITLE1")).check(doesNotExist())
149+
// Make sure the activity is closed before resetting the db:
150+
activityScenario.close()
144151
}
145152

146153
@Test
@@ -162,6 +169,8 @@ class TasksActivityTest {
162169
onView(withText(string.nav_all)).perform(click())
163170
onView(withText("TITLE1")).check(matches(isDisplayed()))
164171
onView(withText("TITLE2")).check(doesNotExist())
172+
// Make sure the activity is closed before resetting the db:
173+
activityScenario.close()
165174
}
166175

167176
@Test
@@ -190,6 +199,8 @@ class TasksActivityTest {
190199
// Check that the task is marked as completed
191200
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
192201
.check(matches(isChecked()))
202+
// Make sure the activity is closed before resetting the db:
203+
activityScenario.close()
193204
}
194205

195206
@Test
@@ -217,6 +228,8 @@ class TasksActivityTest {
217228
// Check that the task is marked as active
218229
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
219230
.check(matches(not(isChecked())))
231+
// Make sure the activity is closed before resetting the db:
232+
activityScenario.close()
220233
}
221234

222235
@Test
@@ -246,6 +259,8 @@ class TasksActivityTest {
246259
// Check that the task is marked as active
247260
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
248261
.check(matches(not(isChecked())))
262+
// Make sure the activity is closed before resetting the db:
263+
activityScenario.close()
249264
}
250265

251266
@Test
@@ -275,6 +290,8 @@ class TasksActivityTest {
275290
// Check that the task is marked as active
276291
onView(allOf(withId(R.id.complete_checkbox), hasSibling(withText(taskTitle))))
277292
.check(matches(isChecked()))
293+
// Make sure the activity is closed before resetting the db:
294+
activityScenario.close()
278295
}
279296

280297
@Test
@@ -292,5 +309,7 @@ class TasksActivityTest {
292309

293310
// Then verify task is displayed on screen
294311
onView(withText("title")).check(matches(isDisplayed()))
312+
// Make sure the activity is closed before resetting the db:
313+
activityScenario.close()
295314
}
296315
}

app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/tasks/TestUtils.kt renamed to app/src/androidTestMock/java/com/example/android/architecture/blueprints/todoapp/tasks/TestUtils.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import androidx.appcompat.widget.Toolbar
2121
import androidx.test.core.app.ActivityScenario
2222
import com.example.android.architecture.blueprints.todoapp.R
2323

24-
fun <T : Activity> ActivityScenario<T>.getToolbarNavigationContentDescription()
25-
: String {
24+
fun <T : Activity> ActivityScenario<T>.getToolbarNavigationContentDescription(): String {
2625
var description = ""
2726
onActivity {
2827
description =

app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskFragment.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class AddEditTaskFragment : Fragment() {
4444
private val viewModel by viewModels<AddEditTaskViewModel> { getViewModelFactory() }
4545

4646
override fun onCreateView(
47-
inflater: LayoutInflater, container: ViewGroup?,
47+
inflater: LayoutInflater,
48+
container: ViewGroup?,
4849
savedInstanceState: Bundle?
4950
): View? {
5051
val root = inflater.inflate(R.layout.addtask_frag, container, false)

app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/Task.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import java.util.UUID
2424
* Immutable model class for a Task. In order to compile with Room, we can't use @JvmOverloads to
2525
* generate multiple constructors.
2626
*
27-
* @param title title of the task
27+
* @param title title of the task
2828
* @param description description of the task
2929
* @param isCompleted whether or not this task is completed
30-
* @param id id of the task
30+
* @param id id of the task
3131
*/
3232
@Entity(tableName = "tasks")
3333
data class Task @JvmOverloads constructor(
@@ -40,7 +40,6 @@ data class Task @JvmOverloads constructor(
4040
val titleForList: String
4141
get() = if (title.isNotEmpty()) title else description
4242

43-
4443
val isActive
4544
get() = !isCompleted
4645

0 commit comments

Comments
 (0)