Skip to content

Commit

Permalink
Add sample
Browse files Browse the repository at this point in the history
  • Loading branch information
jzeferino committed Apr 9, 2024
1 parent 85b3382 commit e0dda84
Show file tree
Hide file tree
Showing 41 changed files with 633 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ fabric.properties
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# deploymentTargetDropDown
.idea/deploymentTargetDropDown.xml
.idea/assetWizardSettings.xml

### Java ###
# Compiled class file
*.class
Expand Down
39 changes: 31 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
[versions]
kotlin = "1.9.22"
ksp = "1.9.23-1.0.19"
appcompat = "1.6.1"
koin = "3.5.3"
koin-annotations = "1.3.1"
koin-android = "3.5.3"
koin-compose = "3.5.3"
kotlin = "1.9.23"
coroutines = "1.8.0"
kotest = "5.8.1"
ktlint-lib = "1.2.1"
material = "1.6.5"
mvi = "1.7.0"
mvi-compose = "0.0.3"
mvi-kotest = "0.0.2"
activity = "1.8.2"
lifecycle = "2.7.0"
ktlint-gradle = "12.1.0"
android-library = "8.3.0"
android-library = "8.3.1"
maven-publish = "0.25.2"
ui = "1.6.5"

# its beeing used outside this file
ktlint-lib = "1.2.1"

[libraries]
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
kotest-runner = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotlin-bom = { group = "org.jetbrains.kotlin", name = "kotlin-bom", version.ref = "kotlin" }
adidas-mvi = { group = "com.adidas.mvi", name = "mvi", version.ref = "mvi" }
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
coroutinesCore = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
coroutinesTest = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
kotestRunner = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotlinBom = { group = "org.jetbrains.kotlin", name = "kotlin-bom", version.ref = "kotlin" }
mvi = { group = "com.adidas.mvi", name = "mvi", version.ref = "mvi" }
mviCompose = { group = "com.adidas.mvi", name = "mvi-compose", version.ref = "mvi-compose" }
mviKotest = { group = "com.adidas.mvi", name = "mvi-kotest", version.ref = "mvi-kotest" }
activityCompose = { module = "androidx.activity:activity-compose", version.ref = "activity" }
lifecycleRuntimeCompose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle" }
material = { module = "androidx.compose.material:material", version.ref = "material" }
ui = { module = "androidx.compose.ui:ui", version.ref = "ui" }
koinCore = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koinAndroid = { module = "io.insert-koin:koin-android", version.ref = "koin-android" }
koinAnnotations = { module = "io.insert-koin:koin-annotations", version.ref = "koin-annotations" }
koinKspCompiler = { module = "io.insert-koin:koin-ksp-compiler", version.ref = "koin-annotations" }
koinCompose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin-compose" }

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint-gradle" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish" }
android-library = { id = "com.android.library", version.ref = "android-library" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
JAVACMD=$JAVA_HOME/jre/sh/kotlin
else
JAVACMD=$JAVA_HOME/bin/java
JAVACMD=$JAVA_HOME/bin/kotlin
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Expand All @@ -132,8 +132,8 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
JAVACMD=kotlin
which kotlin >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
Expand All @@ -154,15 +154,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
esac
fi

# Collect all arguments for the java command, stacking in reverse order:
# Collect all arguments for the kotlin command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.

# For Cygwin or MSYS, switch paths to Windows format before running java
# For Cygwin or MSYS, switch paths to Windows format before running kotlin
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
Expand Down Expand Up @@ -193,7 +193,7 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# Collect all arguments for the kotlin command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
Expand Down
4 changes: 2 additions & 2 deletions mvi-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ android {

dependencies {

implementation(platform(libs.kotlin.bom))
implementation(libs.adidas.mvi)
implementation(platform(libs.kotlinBom))
implementation(libs.mvi)
implementation(libs.activityCompose)
implementation(libs.lifecycleRuntimeCompose)
}
4 changes: 2 additions & 2 deletions mvi-kotest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ configure<KtlintExtension> {
}

dependencies {
implementation(libs.kotest.runner)
implementation(libs.adidas.mvi)
implementation(libs.kotestRunner)
implementation(libs.mvi)
}
1 change: 1 addition & 0 deletions mvi-sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
86 changes: 86 additions & 0 deletions mvi-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import com.android.build.gradle.AppExtension
import com.android.build.gradle.TestedExtension
import com.android.build.gradle.api.BaseVariant

plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-kapt")
alias(libs.plugins.ksp)
}

android {
compileSdk = 34

defaultConfig {
minSdk = 24
targetSdk = 34

versionCode = 1
versionName = "1.0"
}

namespace = "com.adidas.mvi.sample"

buildTypes {
release {
isMinifyEnabled = false
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}

composeOptions {
kotlinCompilerExtensionVersion = "1.5.11"
}

buildFeatures {
compose = true
}

extensions.findByType<AppExtension>()?.let {
project.extensions.configure(AppExtension::class.java) {
applyKSP(this@configure, applicationVariants)
}
}
}

private fun <T : BaseVariant> applyKSP(
extension: TestedExtension,
variants: DomainObjectSet<T>,
) {
variants.all {
extension.sourceSets {
getByName(this@all.name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
}

kotlin {
explicitApi()
}

dependencies {
implementation(libs.appcompat)
implementation(libs.activityCompose)
implementation(libs.ui)
implementation(libs.material)

implementation(libs.mvi)
implementation(libs.mviCompose)

implementation(libs.koinCore)
implementation(libs.koinAndroid)
implementation(libs.koinAnnotations)
implementation(libs.koinCompose)
ksp(libs.koinKspCompiler)
}
23 changes: 23 additions & 0 deletions mvi-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name="com.adidas.mvi.sample.app.MviSampleApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name="com.adidas.mvi.sample.MviSampleActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.adidas.mvi.sample

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import com.adidas.mvi.sample.login.ui.LoginScreen

public class MviSampleActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
LoginScreen()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.adidas.mvi.sample.app

import android.app.Application
import com.adidas.mvi.sample.app.di.AppModule
import com.adidas.mvi.sample.login.di.LoginModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
import org.koin.ksp.generated.module

public class MviSampleApplication : Application() {

override fun onCreate() {
super.onCreate()
initializeKoin()
}

private fun initializeKoin() {
startKoin {
androidLogger(Level.ERROR)
androidContext(this@MviSampleApplication)
modules(
AppModule().module,
LoginModule().module
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.adidas.mvi.sample.app.di

import com.adidas.mvi.Logger
import com.adidas.mvi.sample.app.logger.AppReduceLogger
import org.koin.core.annotation.Module
import org.koin.core.annotation.Single

@Module
public class AppModule {

@Single
internal fun provideLogger(): Logger {
return AppReduceLogger()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.adidas.mvi.sample.app.logger

import com.adidas.mvi.Loggable
import com.adidas.mvi.Logger

internal class AppReduceLogger : Logger {

override fun logIntent(intent: Loggable) {
println("Intent: ${getLoggableName(intent)}")
}

override fun logFailedIntent(
intent: Loggable,
throwable: Throwable,
) {
println("[Error]Intent: ${getLoggableName(intent)} Exception: ${throwable::class.qualifiedName}")
throwable.printStackTrace()
}

override fun logTransformedNewState(
transform: Loggable,
previousState: Loggable,
newState: Loggable,
) {
println(
"Reduce: Using: ${getLoggableName(transform)}, On: ${
getLoggableName(
previousState
)
}, To: ${getLoggableName(newState)}"
)
}

override fun logFailedTransformNewState(
transform: Loggable,
state: Loggable,
throwable: Throwable,
) {
println(
"[Error]Reduce: Using: ${getLoggableName(transform)} On:${
getLoggableName(
state
)
} Exception: ${throwable::class.qualifiedName}"
)
throwable.printStackTrace()
}

private fun getLoggableName(loggable: Loggable): String? {
val qualifiedName = loggable::class.qualifiedName
val packageName = loggable.javaClass.`package`?.name

return qualifiedName?.substringAfter("$packageName.") ?: "N/D"
}
}
Loading

0 comments on commit e0dda84

Please sign in to comment.