Skip to content

Commit 0a2e765

Browse files
committed
Common flow host and API
Refs: #11
1 parent 8f4ab02 commit 0a2e765

95 files changed

Lines changed: 3402 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/deploymentTargetSelector.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.motorro.commonstatemachine.flow
2+
3+
import com.motorro.commonstatemachine.CommonMachineState
4+
5+
/**
6+
* Common flow data API
7+
*/
8+
interface CommonFlowDataApi<G: Any, U: Any, I, R, F : CommonFlowHost<R>> {
9+
/**
10+
* Creates flow
11+
*/
12+
fun init(flowHost: F, input: I? = null): CommonMachineState<G, U>
13+
14+
/**
15+
* Returns default UI state
16+
*/
17+
fun getDefaultUiState(): U
18+
19+
/**
20+
* Returns back gesture mapping
21+
*/
22+
fun getBackGesture(): G? = null
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.motorro.commonstatemachine.flow
2+
3+
/**
4+
* Common flow host
5+
*/
6+
interface CommonFlowHost<in R> {
7+
/**
8+
* Completes common flow
9+
*/
10+
fun onComplete(result: R? = null)
11+
}

examples/androidcore/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ dependencies {
6666
implementation(platform(libs.compose.bom))
6767

6868
implementation(libs.bundles.compose.core)
69+
implementation(libs.compose.material.icons)
6970
implementation(libs.compose.activity)
7071
implementation(libs.compose.foundation)
7172
implementation(libs.compose.foundation.layouts)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2022 Nikolai Kotchetkov.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
package com.motorro.statemachine.androidcore.compose
15+
16+
import androidx.compose.foundation.background
17+
import androidx.compose.foundation.layout.Arrangement
18+
import androidx.compose.foundation.layout.Column
19+
import androidx.compose.foundation.layout.fillMaxSize
20+
import androidx.compose.foundation.layout.fillMaxWidth
21+
import androidx.compose.foundation.layout.padding
22+
import androidx.compose.foundation.layout.size
23+
import androidx.compose.material.icons.Icons
24+
import androidx.compose.material.icons.rounded.Warning
25+
import androidx.compose.material3.Button
26+
import androidx.compose.material3.Card
27+
import androidx.compose.material3.Icon
28+
import androidx.compose.material3.MaterialTheme
29+
import androidx.compose.material3.Text
30+
import androidx.compose.runtime.Composable
31+
import androidx.compose.ui.Alignment
32+
import androidx.compose.ui.Modifier
33+
import androidx.compose.ui.tooling.preview.Preview
34+
import androidx.compose.ui.unit.dp
35+
import com.motorro.statemachine.androidcore.ui.theme.CommonStateMachineTheme
36+
import java.io.IOException
37+
38+
@Composable
39+
fun Error(error: Throwable, onDismiss: () -> Unit, modifier: Modifier = Modifier) {
40+
Column(
41+
modifier = modifier.fillMaxSize(),
42+
horizontalAlignment = Alignment.CenterHorizontally,
43+
verticalArrangement = Arrangement.Center,
44+
content = {
45+
Icon(
46+
modifier = Modifier.size(255.dp),
47+
imageVector = Icons.Rounded.Warning,
48+
tint = MaterialTheme.colorScheme.error,
49+
contentDescription = "Error",
50+
)
51+
52+
Card(modifier = Modifier
53+
.fillMaxWidth()
54+
.padding(16.dp)
55+
.background(MaterialTheme.colorScheme.errorContainer)
56+
) {
57+
Text(
58+
modifier = Modifier
59+
.padding(16.dp)
60+
.align(Alignment.CenterHorizontally),
61+
text = error.message ?: "Unknown error"
62+
)
63+
}
64+
Button(modifier = Modifier
65+
.fillMaxWidth()
66+
.padding(16.dp),
67+
onClick = onDismiss
68+
) {
69+
Text("Dismiss")
70+
}
71+
}
72+
)
73+
}
74+
75+
@Preview
76+
@Composable
77+
fun ErrorPreview() {
78+
CommonStateMachineTheme {
79+
Error(
80+
error = IOException("Network error"),
81+
onDismiss = {}
82+
)
83+
}
84+
}

examples/androidcore/src/main/java/com/motorro/statemachine/androidcore/compose/Loading.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import androidx.compose.ui.tooling.preview.Preview
2525
import androidx.compose.ui.unit.dp
2626

2727
@Composable
28-
fun Loading() {
28+
fun Loading(modifier: Modifier = Modifier) {
2929
Column(
30-
modifier = Modifier.fillMaxSize(),
30+
modifier = modifier.fillMaxSize(),
3131
horizontalAlignment = Alignment.CenterHorizontally,
3232
verticalArrangement = Arrangement.Center,
3333
content = {

examples/di/api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

examples/di/api/build.gradle.kts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
3+
/*
4+
* Copyright 2026 Nikolai Kotchetkov.
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
plugins {
17+
alias(libs.plugins.android.lib)
18+
alias(libs.plugins.compose)
19+
}
20+
21+
val androidMinSdkVersion: Int by project.extra
22+
val androidCompileSdkVersion: Int by project.extra
23+
24+
android {
25+
compileSdk = androidCompileSdkVersion
26+
27+
defaultConfig {
28+
minSdk = androidMinSdkVersion
29+
30+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
31+
consumerProguardFiles("consumer-rules.pro")
32+
}
33+
34+
buildTypes {
35+
release {
36+
isMinifyEnabled = false
37+
proguardFiles(
38+
getDefaultProguardFile("proguard-android-optimize.txt"),
39+
"proguard-rules.pro"
40+
)
41+
}
42+
}
43+
compileOptions {
44+
sourceCompatibility = JavaVersion.VERSION_17
45+
targetCompatibility = JavaVersion.VERSION_17
46+
isCoreLibraryDesugaringEnabled = true
47+
}
48+
kotlin {
49+
compilerOptions {
50+
jvmTarget.set(JvmTarget.JVM_17)
51+
}
52+
}
53+
buildFeatures {
54+
compose = true
55+
}
56+
namespace = "com.motorro.statemachine.di.api"
57+
}
58+
59+
dependencies {
60+
api(libs.timber)
61+
62+
api(project(":commonstatemachine"))
63+
64+
coreLibraryDesugaring(libs.desugaring)
65+
66+
implementation(libs.kotlin.coroutines.core)
67+
68+
implementation(platform(libs.compose.bom))
69+
70+
implementation(libs.bundles.compose.core)
71+
}

0 commit comments

Comments
 (0)