Skip to content

Commit 5241201

Browse files
Implement Flow use case 1
1 parent 3abc81a commit 5241201

File tree

29 files changed

+222
-52
lines changed

29 files changed

+222
-52
lines changed

app/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ android {
3737
jvmTarget = JavaVersion.VERSION_1_8.toString()
3838
}
3939

40+
compileOptions {
41+
// Flag to enable support for the new language APIs
42+
coreLibraryDesugaringEnabled = true
43+
// Sets Java compatibility to Java 8
44+
sourceCompatibility = JavaVersion.VERSION_1_8
45+
targetCompatibility = JavaVersion.VERSION_1_8
46+
}
47+
4048
}
4149

4250
dependencies {
@@ -92,4 +100,6 @@ dependencies {
92100

93101
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
94102
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
103+
104+
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
95105
}

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/base/UseCase.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private val flowUseCases =
171171
)
172172

173173
val useCaseCategories = listOf(
174-
coroutinesUseCases /*,
175-
channelsUseCases,
176-
flowUseCases */
174+
coroutinesUseCases,
175+
// channelsUseCases,
176+
flowUseCases
177177
)

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/8-Terminal-flow-operators.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ fun main() = runBlocking {
1818
// Other Terminal operators
1919
// * toList(), toSet() => collects all of the objects emitted by the Flow and returns them in a List or a Set; works for bounded flows, but not for flows that emit object indefinitely
2020
// * reduce(), flow
21-
// * single() => returns first object emitted by the Flow, throws exception if more items are emmited
21+
// * single() => returns first object emitted by the Flow, throws exception if more items are emitted
2222
// * first() => returns one object of the flow and then stops consuming; safe to use with a Flow that might return more than one value

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/9-Flows-are-sequential.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ fun main() = runBlocking<Unit> {
2020
}.collect {
2121
println("Collect $it")
2222
}
23+
24+
// every item moves from upstream to downstream
25+
// items are NOT all filtered, then mapped, etc
2326
}

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/playground/flow/sharedFlowAndStateFlow/2-Replay.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import kotlinx.coroutines.launch
99
import kotlinx.coroutines.runBlocking
1010
import kotlin.random.Random
1111

12+
// replay caches emissions of the flow
13+
1214
private fun replaySharedFlow(): Flow<Int> {
1315
val sharedFlow = MutableSharedFlow<Int>(replay = 2)
1416

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/coroutines/usecase1/MockApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fun mockApi() =
1010
MockNetworkInterceptor()
1111
.mock(
1212
"http://localhost/recent-android-versions",
13-
Gson().toJson(mockAndroidVersions),
13+
{ Gson().toJson(mockAndroidVersions) },
1414
200,
1515
1500
1616
)

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/coroutines/usecase13/MockApi.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ fun mockApi() = createMockApi(
88
MockNetworkInterceptor()
99
.mock(
1010
"http://localhost/recent-android-versions",
11-
Gson().toJson(mockAndroidVersions),
11+
{ Gson().toJson(mockAndroidVersions) },
1212
200,
1313
1000
1414
)
1515
.mock(
1616
"http://localhost/android-version-features/27",
17-
Gson().toJson(mockVersionFeaturesOreo),
17+
{ Gson().toJson(mockVersionFeaturesOreo) },
1818
MockNetworkInterceptor.INTERNAL_SERVER_ERROR_HTTP_CODE,
1919
100
2020
)
2121
.mock(
2222
"http://localhost/android-version-features/28",
23-
Gson().toJson(mockVersionFeaturesPie),
23+
{ Gson().toJson(mockVersionFeaturesPie) },
2424
200,
2525
1000
2626
)
2727
.mock(
2828
"http://localhost/android-version-features/29",
29-
Gson().toJson(mockVersionFeaturesAndroid10),
29+
{ Gson().toJson(mockVersionFeaturesAndroid10) },
3030
200,
3131
1000
3232
)

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/coroutines/usecase14/MockApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fun mockApi() =
1010
MockNetworkInterceptor()
1111
.mock(
1212
"http://localhost/recent-android-versions",
13-
Gson().toJson(mockAndroidVersions),
13+
{ Gson().toJson(mockAndroidVersions) },
1414
200,
1515
5000
1616
)

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/coroutines/usecase15/AnalyticsWorker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AnalyticsWorker(appContext: Context, workerParameters: WorkerParameters) :
2828
MockNetworkInterceptor()
2929
.mock(
3030
"http://localhost/analytics/workmanager-screen-opened",
31-
"true",
31+
{ "true" },
3232
200,
3333
1500
3434
)

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/coroutines/usecase2/MockApi.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ fun mockApi() = createMockApi(
1010
MockNetworkInterceptor()
1111
.mock(
1212
"http://localhost/recent-android-versions",
13-
Gson().toJson(mockAndroidVersions),
13+
{ Gson().toJson(mockAndroidVersions) },
1414
200,
1515
1500
1616
)
1717
.mock(
1818
"http://localhost/android-version-features/29",
19-
Gson().toJson(mockVersionFeaturesAndroid10),
19+
{ Gson().toJson(mockVersionFeaturesAndroid10) },
2020
200,
2121
1500
2222
)

0 commit comments

Comments
 (0)