Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

#35 jetpack compose for android UI #39

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion android-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,31 @@ plugins {

android {
buildFeatures.dataBinding = true
buildFeatures.compose = true

defaultConfig {
applicationId = "org.example.app"

minSdkVersion(21)
versionCode = 1
versionName = "0.1.0"

val url = "https://newsapi.org/v2/"
buildConfigField("String", "BASE_URL", "\"$url\"")
}

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

kotlinOptions {
jvmTarget = "1.8"
}

composeOptions {
kotlinCompilerVersion = "1.5.21"
kotlinCompilerExtensionVersion = "1.0.1"
}
}

kapt {
Expand All @@ -40,6 +55,14 @@ dependencies {
implementation(libs.swipeRefreshLayout)
implementation(libs.mokoMvvmDataBinding)

// Compose
implementation(libs.composeActivity)
implementation(libs.composeMaterial)
implementation(libs.composeAnimation)
implementation(libs.composeUi)
implementation(libs.composeLifecycleViewmodel)
androidTestImplementation(libs.composeTest)

// Hilt
implementation(libs.hilt)
kapt(libs.hiltCompiler)
Expand Down
1 change: 1 addition & 0 deletions android-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
</intent-filter>
</activity>
<activity android:name=".view.NewsActivity" />
<activity android:name=".view.NewsActivityCompose" />
</application>
</manifest>
48 changes: 48 additions & 0 deletions android-app/src/main/java/org/example/app/view/ConfigActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
package org.example.app.view

import android.content.Intent
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import androidx.lifecycle.ViewModelProvider
import dagger.hilt.android.AndroidEntryPoint
import dev.icerock.moko.mvvm.MvvmEventsActivity
Expand Down Expand Up @@ -40,6 +52,42 @@ class ConfigActivity :

// route called by EventsDispatcher from ViewModel (https://github.com/icerockdev/moko-mvvm)
override fun routeToNews() {
setContent{
testConfigActivity()
}
Intent(this, NewsActivity::class.java).also { startActivity(it) }
}
}

@Composable
fun testConfigActivity() {
Column(modifier = Modifier
.fillMaxWidth()
.padding(20.dp),
) {
val textState1 = remember { mutableStateOf(TextFieldValue()) }
TextField(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp),
value = textState1.value,
onValueChange = { textState1.value = it }
)

val textState2 = remember { mutableStateOf(TextFieldValue()) }
TextField(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp),
value = textState2.value,
onValueChange = { textState2.value = it }
)

Button(
modifier = Modifier
.fillMaxWidth()
.padding(4.dp),
onClick = { }) {
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.example.app.view

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Text

class ConfigActivityCompose : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Text("ConfigActivityCompose")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.example.app.view

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Text

class NewsActivityCompose : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Text("NewsActivityCompose")
}
}
}
10 changes: 9 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ napierVersion = "1.5.0"
testCoreVersion = "1.3.0"
robolectricVersion = "4.6.1"
multidexVersion = "2.0.1"

composeVersion = "1.0.1"
composeActivityVersion = "1.3.1"
composeLifecycleViewmodelVersion = "1.0.0-alpha07"

[libraries]
appCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidAppCompatVersion" }
Expand Down Expand Up @@ -86,3 +88,9 @@ mokoUnitsTest = { module = "dev.icerock.moko:units-test", version.ref = "mokoUni
multiplatformSettingsTest = { module = "com.russhwolf:multiplatform-settings-test", version.ref = "multiplatformSettingsVersion" }
ktorClientMock = { module = "io.ktor:ktor-client-mock", version.ref = "ktorClientVersion" }
multidex = { module = "androidx.multidex:multidex", version.ref = "multidexVersion" }
composeUi = { module = "androidx.compose.ui:ui", version.ref = "composeVersion" }
composeAnimation = { module = "androidx.compose.animation:animation", version.ref = "composeVersion" }
composeLifecycleViewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "composeLifecycleViewmodelVersion" }
composeMaterial = { module = "androidx.compose.material:material", version.ref = "composeVersion" }
composeActivity = { module = "androidx.activity:activity-compose", version.ref = "composeActivityVersion" }
composeTest = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "composeVersion" }