Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Android samples to Jetpack Compose. #64

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Expand Up @@ -3,6 +3,7 @@ buildscript {
google()
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}
dependencies {
classpath(deps.Android.Gradle.Plugin)
Expand Down
19 changes: 14 additions & 5 deletions buildSrc/src/main/kotlin/deps/deps.kt
@@ -1,14 +1,23 @@
package deps


object Android {
object Gradle : Group("com.android.tools.build", "3.5.1") {
object Gradle : Group("com.android.tools.build", "4.0.0-alpha01") {
val Plugin = artifact("gradle")
}

object X {
object AppCompat : Group("androidx.appcompat", "1.1.0") {
val Core = artifact("appcompat")
val AppCompat = dependency("androidx.appcompat", "appcompat", "1.1.0")

object Compose : Group("androidx.compose", "0.1.0-dev02") {
val Compiler = artifact("compose-compiler")
val Runtime = artifact("compose-runtime")
}

object UI : Group("androidx.ui", "0.1.0-dev02") {
val Framework = artifact("ui-framework")
val Layout = artifact("ui-layout")
val Material = artifact("ui-material")
val Tooling = artifact("ui-tooling")
}
}
}
Expand All @@ -19,7 +28,7 @@ object Dokka : Group("org.jetbrains.dokka", "0.9.18") {
}
}

object Kotlin : Group("org.jetbrains.kotlin", "1.3.50") {
object Kotlin : Group("org.jetbrains.kotlin", "1.3.60-eap-25") {
object Coroutines : Group("org.jetbrains.kotlinx", "1.3.2") {
val Android = artifact("kotlinx-coroutines-android")

Expand Down
1 change: 1 addition & 0 deletions oolong/build.gradle.kts
Expand Up @@ -13,6 +13,7 @@ plugins {
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}

kotlin {
Expand Down
18 changes: 17 additions & 1 deletion samples/counter/android/build.gradle.kts
Expand Up @@ -7,6 +7,7 @@ repositories {
google()
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}

android {
Expand All @@ -18,15 +19,30 @@ android {
versionCode = 1
versionName = "1.0"
}
buildFeatures {
compose = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
packagingOptions {
exclude("META-INF/*.kotlin_module")
}
}

dependencies {
implementation(project(":samples:counter:core"))
implementation(deps.Android.X.AppCompat)
implementation(deps.Android.X.UI.Framework)
implementation(deps.Android.X.UI.Tooling)
implementation(deps.Android.X.UI.Layout)
implementation(deps.Android.X.UI.Material)
implementation(deps.Android.X.Compose.Runtime)
implementation(deps.Kotlin.StdLib.Jvm)
implementation(deps.Kotlin.Coroutines.Core.Jvm)
implementation(deps.Kotlin.Coroutines.Android)
implementation(deps.Android.X.AppCompat.Core)
}
1 change: 1 addition & 0 deletions samples/counter/android/gradle.properties
@@ -0,0 +1 @@
android.useAndroidX=true
38 changes: 38 additions & 0 deletions samples/counter/android/src/main/java/sample/counter/Counter.kt
@@ -0,0 +1,38 @@
package sample.counter

import androidx.compose.Composable
import androidx.ui.core.Text
import androidx.ui.core.dp
import androidx.ui.layout.Center
import androidx.ui.layout.Column
import androidx.ui.layout.Spacing
import androidx.ui.material.Button
import androidx.ui.material.MaterialTheme
import counter.Counter
import oolong.Dispatch

@Composable
fun Counter(props: Counter.Props, dispatch: Dispatch<Counter.Msg>) {
MaterialTheme {
Center {
Column {
Center {
Button(onClick = { dispatch(props.onDecrement()) }) {
Text("-")
}
}
Center {
Text(
text = "${props.count}",
modifier = Spacing(16.dp)
)
}
Center {
Button(onClick = { dispatch(props.onIncrement()) }) {
Text("+")
}
}
}
}
}
}

This file was deleted.

Expand Up @@ -2,22 +2,19 @@ package sample.counter

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.ui.core.setContent
import counter.Counter
import oolong.Oolong

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val counterView = findViewById<CounterView>(R.id.counter_view)

Oolong.runtime(
Counter.init,
Counter.update,
Counter.view,
counterView::render
{ props, dispatch -> setContent { Counter(props, dispatch) } }
)
}

Expand Down
11 changes: 0 additions & 11 deletions samples/counter/android/src/main/res/layout/activity_main.xml

This file was deleted.

33 changes: 0 additions & 33 deletions samples/counter/android/src/main/res/layout/counter_view.xml

This file was deleted.

3 changes: 3 additions & 0 deletions samples/counter/android/src/main/res/values/styles.xml
Expand Up @@ -3,6 +3,9 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
Expand Down
1 change: 1 addition & 0 deletions samples/counter/core/build.gradle.kts
Expand Up @@ -8,6 +8,7 @@ plugins {
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}

kotlin {
Expand Down
19 changes: 18 additions & 1 deletion samples/random/android/build.gradle.kts
Expand Up @@ -7,6 +7,7 @@ repositories {
google()
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}

android {
Expand All @@ -18,14 +19,30 @@ android {
versionCode = 1
versionName = "1.0"
}
buildFeatures {
compose = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
packagingOptions {
exclude("META-INF/*.kotlin_module")
}
}

dependencies {
implementation(project(":samples:random:core"))
implementation(deps.Android.X.AppCompat)
implementation(deps.Android.X.UI.Framework)
implementation(deps.Android.X.UI.Tooling)
implementation(deps.Android.X.UI.Layout)
implementation(deps.Android.X.UI.Material)
implementation(deps.Android.X.Compose.Runtime)
implementation(deps.Kotlin.StdLib.Jvm)
implementation(deps.Kotlin.Coroutines.Core.Jvm)
implementation(deps.Kotlin.Coroutines.Android)
implementation(deps.Android.X.AppCompat.Core)
}
1 change: 1 addition & 0 deletions samples/random/android/gradle.properties
@@ -0,0 +1 @@
android.useAndroidX=true
Expand Up @@ -2,22 +2,19 @@ package sample.random

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.ui.core.setContent
import oolong.Oolong
import random.Random

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val randomView = findViewById<RandomView>(R.id.random_view)

Oolong.runtime(
Random.init,
Random.update,
Random.view,
randomView::render
{ props, dispatch -> setContent { Random(props, dispatch) } }
)
}

Expand Down
33 changes: 33 additions & 0 deletions samples/random/android/src/main/java/sample/random/Random.kt
@@ -0,0 +1,33 @@
package sample.random

import androidx.compose.Composable
import androidx.ui.core.Text
import androidx.ui.core.dp
import androidx.ui.layout.Center
import androidx.ui.layout.Column
import androidx.ui.layout.Spacing
import androidx.ui.material.Button
import androidx.ui.material.MaterialTheme
import random.Random
import oolong.Dispatch

@Composable
fun Random(props: Random.Props, dispatch: Dispatch<Random.Msg>) {
MaterialTheme {
Center {
Column {
Center {
Text(
text = "${props.dieFace}",
modifier = Spacing(16.dp)
)
}
Center {
Button(onClick = { dispatch(props.onRoll()) }) {
Text("Roll")
}
}
}
}
}
}
30 changes: 0 additions & 30 deletions samples/random/android/src/main/java/sample/random/RandomView.kt

This file was deleted.