Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
key: v1-dependencies-{{ checksum "build.gradle" }}

# run tests!
- run: ./gradlew lib:jvmTest
- run: ./gradlew jvmTest

workflows:
build_test:
Expand All @@ -74,6 +74,7 @@ workflows:
branches:
only:
- /^feature.*/
- /^task.*/
- /^bugfix.*/

publish_release_artifacts:
Expand Down
24 changes: 17 additions & 7 deletions buildSrc/src/main/kotlin/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "androidx.constraintlayout:constraintlayout:" + Versions.constraint_layout

/**
* https://developer.android.com/guide/topics/ui/layout/recyclerview
*/
const val recyclerView = "androidx.recyclerview:recyclerview:" + Versions.recycler_view

/**
* https://developer.android.com/testing
*/
Expand All @@ -26,13 +36,13 @@ object Libs {
* https://github.com/robstoll/atrium
*/
const val atrium_cc_en_gb_robstoll_common: String =
"ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:" + Versions.ch_tutteli_atrium
"ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:" + Versions.atrium

/**
* https://github.com/robstoll/atrium
*/
const val atrium_cc_en_gb_robstoll: String = "ch.tutteli.atrium:atrium-cc-en_GB-robstoll:" +
Versions.ch_tutteli_atrium
Versions.atrium

/**
* https://developer.android.com/studio
Expand All @@ -57,12 +67,12 @@ object Libs {
/**
* http://mockk.io
*/
const val mockk_common: String = "io.mockk:mockk-common:" + Versions.io_mockk
const val mockk_common: String = "io.mockk:mockk-common:" + Versions.mockk

/**
* http://mockk.io
*/
const val mockk: String = "io.mockk:mockk:" + Versions.io_mockk
const val mockk: String = "io.mockk:mockk:" + Versions.mockk

/**
* http://junit.org
Expand Down Expand Up @@ -163,11 +173,11 @@ object Libs {
Versions.org_jetbrains_kotlin

const val spek_dsl_jvm: String = "org.spekframework.spek2:spek-dsl-jvm:" +
Versions.org_spekframework_spek2
Versions.spek

const val spek_dsl_metadata: String = "org.spekframework.spek2:spek-dsl-metadata:" +
Versions.org_spekframework_spek2
Versions.spek

const val spek_runner_junit5: String = "org.spekframework.spek2:spek-runner-junit5:" +
Versions.org_spekframework_spek2
Versions.spek
}
11 changes: 8 additions & 3 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Versions {

const val androidx_test_runner: String = "1.2.0"

const val ch_tutteli_atrium: String = "0.8.0"
const val atrium: String = "0.8.0"

const val aapt2: String = "3.5.0-5435860"

Expand All @@ -28,17 +28,22 @@ object Versions {

const val de_fayard_buildsrcversions_gradle_plugin: String = "0.4.2"

const val io_mockk: String = "1.9.3"
const val mockk: String = "1.9.3"

const val junit: String = "4.12"

const val dokka_gradle_plugin: String = "0.9.17" // available: "0.9.18"

const val org_jetbrains_kotlin: String = "1.3.50"

const val org_spekframework_spek2: String = "2.1.0-alpha.0.11+d97ef33"
const val spek: String = "2.1.0-alpha.0.11+d97ef33"
// available: "2.1.0-alpha.0.24+0fdeb6e"

const val constraint_layout = "1.1.3"

const val recycler_view = "1.0.0"


/**
*
* See issue 19: How to update Gradle itself?
Expand Down
1 change: 1 addition & 0 deletions examples/counter/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GROUP=org.reduxkotlin.examples.counter.android
14 changes: 7 additions & 7 deletions examples/counter/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ kotlin {
dependencies {
implementation kotlin("test-common")
implementation kotlin("test-annotations-common")
implementation "org.spekframework.spek2:spek-dsl-metadata:$project.versions.spek"
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:$project.versions.atrium"
implementation "io.mockk:mockk-common:1.9.3"
implementation "org.spekframework.spek2:spek-dsl-metadata:$Versions.spek"
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll-common:$Versions.atrium"
implementation "io.mockk:mockk-common:$Versions.mockk"
}
}

Expand All @@ -56,11 +56,11 @@ kotlin {
dependencies {
implementation kotlin("test")
implementation kotlin("test-junit")
implementation "org.spekframework.spek2:spek-dsl-jvm:$project.versions.spek"
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll:$project.versions.atrium"
implementation "io.mockk:mockk:1.9.3"
implementation "org.spekframework.spek2:spek-dsl-jvm:$Versions.spek"
implementation "ch.tutteli.atrium:atrium-cc-en_GB-robstoll:$Versions.atrium"
implementation "io.mockk:mockk:$Versions.mockk"

runtimeOnly "org.spekframework.spek2:spek-runner-junit5:$project.versions.spek"
runtimeOnly "org.spekframework.spek2:spek-runner-junit5:$Versions.spek"
runtimeOnly 'org.jetbrains.kotlin:kotlin-reflect'
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/counter/common/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GROUP=org.reduxkotlin.examples.counter.common
47 changes: 47 additions & 0 deletions examples/todos/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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")
isDebuggable = true
}
}
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"))
}
1 change: 1 addition & 0 deletions examples/todos/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GROUP=org.reduxkotlin.examples.todos.android
24 changes: 24 additions & 0 deletions examples/todos/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.reduxkotlin.example.todos">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/TodoAppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/TodoAppTheme">
<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,63 @@
package org.reduxkotlin.example.todos

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import org.reduxkotlin.StoreSubscription
import org.reduxkotlin.createStore
import org.reduxkotlin.examples.todos.*

/**
* 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() {
private lateinit var storeSubscription: StoreSubscription
private var adapter = TodoAdapter()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
storeSubscription = store.subscribe { render(store.state) }
btnAddTodo.setOnClickListener {
val todoText = etTodo.text.toString()
etTodo.text.clear()
store.dispatch(AddTodo(todoText))
}
btnSelectAll.setOnClickListener { store.dispatch(SetVisibilityFilter(VisibilityFilter.SHOW_ALL)) }
btnActive.setOnClickListener { store.dispatch(SetVisibilityFilter(VisibilityFilter.SHOW_ACTIVE)) }
btnCompleted.setOnClickListener { store.dispatch(SetVisibilityFilter(VisibilityFilter.SHOW_COMPLETED)) }

recyclerView.adapter = adapter

render(store.state)
}

private fun render(state: AppState) {
adapter.submitList(state.visibleTodos)
setFilterButtons(state.visibilityFilter)
}

private fun setFilterButtons(visibilityFilter: VisibilityFilter) =
when (visibilityFilter) {
VisibilityFilter.SHOW_ALL -> {
btnSelectAll.isSelected = true
btnActive.isSelected = false
btnCompleted.isSelected = false
}
VisibilityFilter.SHOW_ACTIVE -> {
btnActive.isSelected = true
btnSelectAll.isSelected = false
btnCompleted.isSelected = false
}
VisibilityFilter.SHOW_COMPLETED -> {
btnCompleted.isSelected = true
btnSelectAll.isSelected = false
btnActive.isSelected = false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.reduxkotlin.example.todos

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_todo.view.*
import org.reduxkotlin.examples.todos.Todo
import org.reduxkotlin.examples.todos.ToggleTodo
import android.graphics.Paint.STRIKE_THRU_TEXT_FLAG
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter

class TodoAdapter : ListAdapter<Todo, TodoViewHolder>(DiffCallback()) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TodoViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_todo, parent, false)
return TodoViewHolder(view)
}

override fun onBindViewHolder(holder: TodoViewHolder, position: Int) {
holder.bind(getItem(position))
}
}

class TodoViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(todo: Todo) {
if (todo.completed) {
itemView.tvTodo.paintFlags = itemView.tvTodo.paintFlags or STRIKE_THRU_TEXT_FLAG
} else {
itemView.tvTodo.paintFlags =
itemView.tvTodo.paintFlags and STRIKE_THRU_TEXT_FLAG.inv()
}

itemView.tvTodo.text = "• ${todo.text}"
itemView.setOnClickListener { store.dispatch(ToggleTodo(adapterPosition))}
}
}

class DiffCallback : DiffUtil.ItemCallback<Todo>() {
override fun areItemsTheSame(oldItem: Todo, newItem: Todo): Boolean {
return oldItem.id == newItem.id
}

override fun areContentsTheSame(oldItem: Todo, newItem: Todo): Boolean {
return oldItem == newItem
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</vector>
14 changes: 14 additions & 0 deletions examples/todos/android/src/main/res/drawable/btn_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<selector>
<item android:state_selected="true">
<color android:color="?attr/colorAccent"/>
</item>
<item>
<color android:color="@android:color/transparent"/>
</item>
</selector>
</item>
<item android:drawable="?attr/selectableItemBackground"/>
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#010101"
android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z" />
</vector>
Loading