Skip to content
This repository was archived by the owner on Oct 25, 2025. It is now read-only.

Commit 16c4107

Browse files
Updates End codelab 3 to 4.2.1
Updates End codelab 3 to 4.2.1
2 parents e194273 + eb6d209 commit 16c4107

File tree

13 files changed

+184
-42
lines changed

13 files changed

+184
-42
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Advanced Android Issue Template for Testing Codelab
3+
about: Report problems with Advanced Android in Kotlin Testing codelab
4+
title: "[Codelab Issue] Testing Codelab 5.#, Step # - Issue description"
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the problem**
11+
A clear and concise description of what the problem is.
12+
13+
**In which lesson and step of the codelab can this issue be found?**
14+
Lesson number + step number. (ex. 5.2, Step 7)
15+
16+
**How to reproduce?**
17+
What are the exact steps to reproduce the problem?
18+
19+
**Versions**
20+
1. What version of Android Studio are you using?
21+
22+
**Additional information**
23+
Add any other context about the problem here.
24+
25+
**codelab:** advanced-android-kotlin

.github/ci-gradle.properties

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Copyright 2020 The Android Open Source Project
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
org.gradle.daemon=false
18+
org.gradle.parallel=true
19+
org.gradle.jvmargs=-Xmx5120m
20+
org.gradle.workers.max=2
21+
22+
kotlin.incremental=false
23+
kotlin.compiler.execution.strategy=in-process

.github/workflows/blueprints.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: testingcodelabs
2+
3+
on:
4+
push:
5+
branches:
6+
- starter_code
7+
- end_codelab_1
8+
- end_codelab_2
9+
- end_codelab_3
10+
pull_request:
11+
branches:
12+
- starter_code
13+
- end_codelab_1
14+
- end_codelab_2
15+
- end_codelab_3
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 30
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
26+
- name: Copy CI gradle.properties
27+
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
28+
29+
- name: Set up JDK 11
30+
uses: actions/setup-java@v1
31+
with:
32+
java-version: 11
33+
34+
- uses: actions/cache@v2
35+
with:
36+
path: |
37+
~/.gradle/caches/modules-*
38+
~/.gradle/caches/jars-*
39+
~/.gradle/caches/build-cache-*
40+
key: gradle-${{ hashFiles('checksum.txt') }}
41+
42+
- name: Build project
43+
run: ./gradlew build test --stacktrace
44+
45+
- name: Upload build reports
46+
if: always()
47+
uses: actions/upload-artifact@v2
48+
with:
49+
name: build-reports
50+
path: app/build/reports/
51+
52+
test:
53+
needs: build
54+
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
55+
timeout-minutes: 30
56+
strategy:
57+
matrix:
58+
api-level: [23, 29]
59+
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v2
63+
64+
- name: Copy CI gradle.properties
65+
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
66+
67+
- name: Set up JDK 11
68+
uses: actions/setup-java@v1
69+
with:
70+
java-version: 11
71+
72+
- name: Run instrumentation tests
73+
uses: reactivecircus/android-emulator-runner@v2
74+
with:
75+
api-level: ${{ matrix.api-level }}
76+
arch: x86
77+
disable-animations: true
78+
script: ./gradlew app:cC --stacktrace
79+
80+
- name: Upload test reports
81+
if: always()
82+
uses: actions/upload-artifact@v2
83+
with:
84+
name: test-reports
85+
path: app/build/reports/

app/build.gradle

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ android {
3131
includeAndroidResources = true
3232
returnDefaultValues = true
3333
}
34+
35+
packagingOptions {
36+
exclude 'META-INF/AL2.0'
37+
exclude 'META-INF/LGPL2.1'
38+
}
39+
40+
packagingOptions {
41+
exclude 'META-INF/AL2.0'
42+
exclude 'META-INF/LGPL2.1'
43+
}
3444
}
3545

3646
dependencies {
@@ -52,7 +62,8 @@ dependencies {
5262
implementation "androidx.room:room-runtime:$roomVersion"
5363
kapt "androidx.room:room-compiler:$roomVersion"
5464
implementation "androidx.room:room-ktx:$roomVersion"
55-
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
65+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
66+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"
5667
kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion"
5768
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
5869
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"
@@ -74,7 +85,7 @@ dependencies {
7485

7586
// Testing code should not be included in the main code.
7687
// Once https://issuetracker.google.com/128612536 is fixed this can be fixed.
77-
implementation "androidx.fragment:fragment-testing:$fragmentVersion"
88+
debugImplementation "androidx.fragment:fragment-testing:$fragmentVersion"
7889
implementation "androidx.test:core:$androidXTestCoreVersion"
7990

8091
// AndroidX Test - JVM testing

app/src/androidTest/java/com/example/android/architecture/blueprints/todoapp/util/DataBindingIdlingResource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fun DataBindingIdlingResource.monitorActivity(
106106
/**
107107
* Sets the fragment from a [FragmentScenario] to be used from [DataBindingIdlingResource].
108108
*/
109-
fun DataBindingIdlingResource.monitorFragment(fragmentScenario: FragmentScenario<out Fragment>) {
109+
fun <T : Fragment> DataBindingIdlingResource.monitorFragment(fragmentScenario: FragmentScenario<T>) {
110110
fragmentScenario.onFragment {
111111
this.activity = it.requireActivity()
112112
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class AddEditTaskFragment : Fragment() {
6868
}
6969

7070
private fun setupNavigation() {
71-
viewModel.taskUpdatedEvent.observe(this, EventObserver {
71+
viewModel.taskUpdatedEvent.observe(viewLifecycleOwner, EventObserver {
7272
val action = AddEditTaskFragmentDirections
7373
.actionAddEditTaskFragmentToTasksFragment(ADD_EDIT_RESULT_OK)
7474
findNavController().navigate(action)

app/src/main/java/com/example/android/architecture/blueprints/todoapp/data/source/remote/TasksRemoteDataSource.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.example.android.architecture.blueprints.todoapp.data.source.remote
1717

18+
import android.annotation.SuppressLint
1819
import androidx.lifecycle.LiveData
1920
import androidx.lifecycle.MutableLiveData
2021
import androidx.lifecycle.map
@@ -41,6 +42,7 @@ object TasksRemoteDataSource : TasksDataSource {
4142

4243
private val observableTasks = MutableLiveData<Result<List<Task>>>()
4344

45+
@SuppressLint("NullSafeMutableLiveData")
4446
override suspend fun refreshTasks() {
4547
observableTasks.value = getTasks()
4648
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ class TaskDetailFragment : Fragment() {
5656
}
5757

5858
private fun setupNavigation() {
59-
viewModel.deleteTaskEvent.observe(this, EventObserver {
59+
viewModel.deleteTaskEvent.observe(viewLifecycleOwner, EventObserver {
6060
val action = TaskDetailFragmentDirections
6161
.actionTaskDetailFragmentToTasksFragment(DELETE_RESULT_OK)
6262
findNavController().navigate(action)
6363
})
64-
viewModel.editTaskEvent.observe(this, EventObserver {
64+
viewModel.editTaskEvent.observe(viewLifecycleOwner, EventObserver {
6565
val action = TaskDetailFragmentDirections
6666
.actionTaskDetailFragmentToAddEditTaskFragment(
6767
args.taskId,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class TaskDetailViewModel(
8080
}
8181
}
8282

83-
fun start(taskId: String?) {
83+
fun start(taskId: String) {
8484
// If we're already loading or already loaded, return (might be a config change)
8585
if (_dataLoading.value == true || taskId == _taskId.value) {
8686
return

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class TasksFragment : Fragment() {
9999
}
100100

101101
private fun setupNavigation() {
102-
viewModel.openTaskEvent.observe(this, EventObserver {
102+
viewModel.openTaskEvent.observe(viewLifecycleOwner, EventObserver {
103103
openTaskDetails(it)
104104
})
105-
viewModel.newTaskEvent.observe(this, EventObserver {
105+
viewModel.newTaskEvent.observe(viewLifecycleOwner, EventObserver {
106106
navigateToAddNewTask()
107107
})
108108
}

0 commit comments

Comments
 (0)