From 6f31273ee9616a8fd29e9660034000a30d58ce18 Mon Sep 17 00:00:00 2001 From: Patrick Jackson Date: Tue, 17 Sep 2019 22:58:22 -0600 Subject: [PATCH] [WIP] add todo example --- buildSrc/src/main/kotlin/Libs.kt | 10 ++ buildSrc/src/main/kotlin/Versions.kt | 5 + examples/counter/android/gradle.properties | 1 + examples/counter/common/gradle.properties | 1 + examples/todos/android/build.gradle.kts | 46 +++++ examples/todos/android/gradle.properties | 1 + .../android/src/main/AndroidManifest.xml | 24 +++ .../org/reduxkotlin/example/todos/Adapter.kt | 25 +++ .../reduxkotlin/example/todos/MainActivity.kt | 34 ++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../drawable/ic_arrow_downward_white_24dp.xml | 10 ++ .../drawable/ic_arrow_upward_white_24dp.xml | 10 ++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++++ .../src/main/res/layout/activity_main.xml | 65 +++++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes .../android/src/main/res/values/strings.xml | 3 + .../android/src/main/res/values/styles.xml | 5 + examples/todos/common/build.gradle | 96 ++++++++++ examples/todos/common/gradle.properties | 1 + .../org/reduxkotlin/examples/todos/Reducer.kt | 52 ++++++ .../reduxkotlin/examples/todos/ReducerTest.kt | 26 +++ settings.gradle | 4 +- website/i18n/en.json | 148 +++++++++++++++ 34 files changed, 780 insertions(+), 1 deletion(-) create mode 100644 examples/counter/android/gradle.properties create mode 100644 examples/counter/common/gradle.properties create mode 100644 examples/todos/android/build.gradle.kts create mode 100644 examples/todos/android/gradle.properties create mode 100644 examples/todos/android/src/main/AndroidManifest.xml create mode 100644 examples/todos/android/src/main/java/org/reduxkotlin/example/todos/Adapter.kt create mode 100644 examples/todos/android/src/main/java/org/reduxkotlin/example/todos/MainActivity.kt create mode 100644 examples/todos/android/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 examples/todos/android/src/main/res/drawable/ic_arrow_downward_white_24dp.xml create mode 100644 examples/todos/android/src/main/res/drawable/ic_arrow_upward_white_24dp.xml create mode 100644 examples/todos/android/src/main/res/drawable/ic_launcher_background.xml create mode 100644 examples/todos/android/src/main/res/layout/activity_main.xml create mode 100644 examples/todos/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 examples/todos/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 examples/todos/android/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 examples/todos/android/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 examples/todos/android/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 examples/todos/android/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 examples/todos/android/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 examples/todos/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 examples/todos/android/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 examples/todos/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 examples/todos/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 examples/todos/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 examples/todos/android/src/main/res/values/strings.xml create mode 100644 examples/todos/android/src/main/res/values/styles.xml create mode 100644 examples/todos/common/build.gradle create mode 100644 examples/todos/common/gradle.properties create mode 100644 examples/todos/common/src/commonMain/kotlin/org/reduxkotlin/examples/todos/Reducer.kt create mode 100644 examples/todos/common/src/test/kotlin/org/reduxkotlin/examples/todos/ReducerTest.kt create mode 100644 website/i18n/en.json diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 66e3df0..c6b1797 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -12,6 +12,16 @@ object Libs { */ const val appcompat: String = "androidx.appcompat:appcompat:" + Versions.appcompat + /** + * https://developer.android.com/reference/android/support/constraint/ConstraintLayout + */ + const val constraintLayout = "com.android.support.constraint:constraint-layout:" + Versions.constraint_layout + + /** + * https://developer.android.com/guide/topics/ui/layout/recyclerview + */ + const val recyclerView = "com.android.support:recyclerview-v7:" + Versions.reyclerview + /** * https://developer.android.com/testing */ diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 2b923dc..b72f332 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -39,6 +39,11 @@ object Versions { const val org_spekframework_spek2: String = "2.1.0-alpha.0.11+d97ef33" // available: "2.1.0-alpha.0.24+0fdeb6e" + const val constraint_layout = "1.1.2" + + const val reyclerview = "28.0.0" + + /** * * See issue 19: How to update Gradle itself? diff --git a/examples/counter/android/gradle.properties b/examples/counter/android/gradle.properties new file mode 100644 index 0000000..cc9440a --- /dev/null +++ b/examples/counter/android/gradle.properties @@ -0,0 +1 @@ +GROUP=org.reduxkotlin.examples.counter.android diff --git a/examples/counter/common/gradle.properties b/examples/counter/common/gradle.properties new file mode 100644 index 0000000..0ef8249 --- /dev/null +++ b/examples/counter/common/gradle.properties @@ -0,0 +1 @@ +GROUP=org.reduxkotlin.examples.counter.common diff --git a/examples/todos/android/build.gradle.kts b/examples/todos/android/build.gradle.kts new file mode 100644 index 0000000..b6258bb --- /dev/null +++ b/examples/todos/android/build.gradle.kts @@ -0,0 +1,46 @@ +plugins { + id("com.android.application") + kotlin("android") + kotlin("android.extensions") + kotlin("kapt") +} + +android { + compileSdkVersion(29) + defaultConfig { + applicationId = "org.reduxkotlin.example.todos" + minSdkVersion(26) + targetSdkVersion(29) + versionCode = 1 + versionName = "1.0" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + buildTypes { + getByName("release") { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") + } + getByName("debug") { + // MPP libraries don't currently get this resolution automatically + matchingFallbacks = listOf("release") + } + } + packagingOptions { + exclude("META-INF/*.kotlin_module") + } +} + + +dependencies { + implementation(Libs.kotlin_stdlib_jdk8) + implementation(Libs.appcompat) + implementation(Libs.constraintLayout) + implementation(Libs.recyclerView) + + implementation(project(":examples:todos:common")) + implementation(project(":lib")) +} diff --git a/examples/todos/android/gradle.properties b/examples/todos/android/gradle.properties new file mode 100644 index 0000000..1c59888 --- /dev/null +++ b/examples/todos/android/gradle.properties @@ -0,0 +1 @@ +GROUP=org.reduxkotlin.examples.todos.android diff --git a/examples/todos/android/src/main/AndroidManifest.xml b/examples/todos/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..606aef8 --- /dev/null +++ b/examples/todos/android/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/todos/android/src/main/java/org/reduxkotlin/example/todos/Adapter.kt b/examples/todos/android/src/main/java/org/reduxkotlin/example/todos/Adapter.kt new file mode 100644 index 0000000..e7d2a5c --- /dev/null +++ b/examples/todos/android/src/main/java/org/reduxkotlin/example/todos/Adapter.kt @@ -0,0 +1,25 @@ +package org.reduxkotlin.example.todos + +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import org.reduxkotlin.examples.todos.Todo + +class Adapter: RecyclerView.Adapter() { + var todos: List = listOf() + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoViewHolder { + } + + override fun getItemCount(): Int = todos.size + + override fun onBindViewHolder(holder: TodoViewHolder, position: Int) { + } + +} + +class TodoViewHolder(view: View): RecyclerView.ViewHolder(view) { + fun bind(todo: Todo) { + view. + } +} \ No newline at end of file diff --git a/examples/todos/android/src/main/java/org/reduxkotlin/example/todos/MainActivity.kt b/examples/todos/android/src/main/java/org/reduxkotlin/example/todos/MainActivity.kt new file mode 100644 index 0000000..c966002 --- /dev/null +++ b/examples/todos/android/src/main/java/org/reduxkotlin/example/todos/MainActivity.kt @@ -0,0 +1,34 @@ +package org.reduxkotlin.example.todos + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.recyclerview.widget.RecyclerView +import kotlinx.android.synthetic.main.activity_main.* +import org.reduxkotlin.StoreSubscription +import org.reduxkotlin.createStore +import org.reduxkotlin.examples.todos.AppState +import org.reduxkotlin.examples.todos.rootReducer + +/** + * This is a sample of basic redux behavior. + * This is NOT best practice for structuring a multiplatform App. + */ + + +val store = createStore(rootReducer, AppState()) + +class MainActivity: AppCompatActivity() { + lateinit var storeSubscription: StoreSubscription + var adapter: Adapter + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + storeSubscription = store.subscribe { render(store.state) } +// btn_increment.setOnClickListener { store.dispatch(Increment()) } +// btn_decrement.setOnClickListener { store.dispatch(Decrement()) } + } + + private fun render(state: AppState) { + } +} \ No newline at end of file diff --git a/examples/todos/android/src/main/res/drawable-v24/ic_launcher_foreground.xml b/examples/todos/android/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..c7bd21d --- /dev/null +++ b/examples/todos/android/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/examples/todos/android/src/main/res/drawable/ic_arrow_downward_white_24dp.xml b/examples/todos/android/src/main/res/drawable/ic_arrow_downward_white_24dp.xml new file mode 100644 index 0000000..211b0db --- /dev/null +++ b/examples/todos/android/src/main/res/drawable/ic_arrow_downward_white_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/examples/todos/android/src/main/res/drawable/ic_arrow_upward_white_24dp.xml b/examples/todos/android/src/main/res/drawable/ic_arrow_upward_white_24dp.xml new file mode 100644 index 0000000..50bc32c --- /dev/null +++ b/examples/todos/android/src/main/res/drawable/ic_arrow_upward_white_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/examples/todos/android/src/main/res/drawable/ic_launcher_background.xml b/examples/todos/android/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..d5fccc5 --- /dev/null +++ b/examples/todos/android/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/todos/android/src/main/res/layout/activity_main.xml b/examples/todos/android/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..dc3d205 --- /dev/null +++ b/examples/todos/android/src/main/res/layout/activity_main.xml @@ -0,0 +1,65 @@ + + + + + +