Skip to content

Commit

Permalink
Update sample apps
Browse files Browse the repository at this point in the history
  • Loading branch information
zsmb13 committed May 16, 2024
1 parent 6f15191 commit 7b58e04
Show file tree
Hide file tree
Showing 33 changed files with 179 additions and 94 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,16 @@ To get the bundle of arguments from an entry, use `requireArguments`:
val args: Bundle = navBackStackEntry.requireArguments()
```

Here's an example of using this with Compose, in combination with the [Bundle extensions](#bundle):
Here's an example of using this with Compose Navigation, in combination with the [Bundle extensions](#bundle):

```kotlin
composable("detail/{objectId}") { backStackEntry ->
composable(
"detail/{objectId}",
arguments = listOf(navArgument("objectId") { type = NavType.IntType }),
) { backStackEntry ->
val args = backStackEntry.requireArguments()
val objectId = args.requireInt("objectId")
DetailScreen(navController, objectId)
// UI implementation
}
```

Expand Down
11 changes: 0 additions & 11 deletions app/src/androidMain/kotlin/co/zsmb/requirektx/MainActivity.kt

This file was deleted.

18 changes: 0 additions & 18 deletions app/src/androidMain/res/layout/activity_main.xml

This file was deleted.

16 changes: 0 additions & 16 deletions app/src/androidMain/res/values-night/themes.xml

This file was deleted.

10 changes: 0 additions & 10 deletions app/src/androidMain/res/values/colors.xml

This file was deleted.

3 changes: 0 additions & 3 deletions app/src/androidMain/res/values/strings.xml

This file was deleted.

16 changes: 0 additions & 16 deletions app/src/androidMain/res/values/themes.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

apiValidation {
ignoredProjects += listOf(
"app",
"sample",
"requirektx-test-helper",
)
klib {
Expand Down
15 changes: 9 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[versions]
androidx-activityCompose = "1.9.0"
agp = "8.2.2"
androidTools = "31.4.0"
appcompat = "1.6.1"
binary-compat-validator = "0.15.0-Beta.2"
constraintlayout = "2.1.4"
compose-multiplatform = "1.6.10-rc03"
core-ktx = "1.13.1"
core-bundle = "1.0.0-rc01"
junit = "4.13.2"
junit-jupiter-api = "5.9.2"
kotlin = "2.0.0-RC3"
material = "1.12.0"
maven-publish = "0.28.0"
navigation-runtime = "2.7.0-alpha04"
navigationCompose = "2.7.0-alpha04"
robolectric = "4.12.1"
work-runtime = "2.9.0"

[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
android-gradle-plugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
android-tools-common = { group = "com.android.tools", name = "common", version.ref = "androidTools" }
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
core-bundle = { module = "org.jetbrains.androidx.core:core-bundle", version.ref = "core-bundle" }
core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" }
junit = { module = "junit:junit", version.ref = "junit" }
Expand All @@ -28,17 +28,20 @@ junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", vers
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter-api" }
kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
material = { module = "com.google.android.material:material", version.ref = "material" }
maven-publish = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish" }
navigation-runtime = { module = "org.jetbrains.androidx.navigation:navigation-runtime", version.ref = "navigation-runtime" }
navigation-compose = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
navigation-runtime = { module = "org.jetbrains.androidx.navigation:navigation-runtime", version.ref = "navigationCompose" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
work-runtime = { module = "androidx.work:work-runtime", version.ref = "work-runtime" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
binaryCompatValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compat-validator" }
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
composeMultiplatform = { id = "org.jetbrains.compose", version.ref = "compose-multiplatform" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish" }

requireKtxLibrary = { id = "co.zsmb.requirektx.library", version = "unspecified" }
requireKtxPublishing = { id = "co.zsmb.requirektx.publishing", version = "unspecified" }
4 changes: 4 additions & 0 deletions requirektx-bundle/api/jvm/requirektx-bundle.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
public final class BlaKt {
public static final fun publicjvmapi ()V
}

public final class co/zsmb/requirektx/BundleArrayListKt {
public static final fun getIntegerArrayListOrNull (Landroidx/core/bundle/Bundle;Ljava/lang/String;)Ljava/util/ArrayList;
public static final fun getStringArrayListOrNull (Landroidx/core/bundle/Bundle;Ljava/lang/String;)Ljava/util/ArrayList;
Expand Down
3 changes: 3 additions & 0 deletions requirektx-bundle/src/jvmMain/kotlin/bla.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public fun publicjvmapi() {

}
File renamed without changes.
34 changes: 28 additions & 6 deletions app/build.gradle.kts → sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidApplication)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.composeMultiplatform)
}

kotlin {
Expand All @@ -11,18 +13,32 @@ kotlin {
}
}
}

jvm("desktop")

sourceSets {
androidMain.dependencies {
implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(libs.material)
implementation(libs.constraintlayout)
val desktopMain by getting

commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.uiToolingPreview)

implementation(libs.navigation.compose)

implementation(project(":requirektx-bundle"))
implementation(project(":requirektx-intent"))
implementation(project(":requirektx-navigation"))
}
androidMain.dependencies {
implementation(project(":requirektx-intent"))
implementation(project(":requirektx-work"))

implementation(libs.androidx.activity.compose)
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
}
}
}
Expand Down Expand Up @@ -57,3 +73,9 @@ android {
}
}
}

compose.desktop {
application {
mainClass = "co.zsmb.requirektx.MainKt"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.RequireKTX">
android:theme="@android:style/Theme.Material.Light.NoActionBar">
<activity android:name="co.zsmb.requirektx.MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Expand Down
14 changes: 14 additions & 0 deletions sample/src/androidMain/kotlin/co/zsmb/requirektx/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package co.zsmb.requirektx

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.bundle.Bundle

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
App()
}
}
}
3 changes: 3 additions & 0 deletions sample/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">requireKTX sample</string>
</resources>
94 changes: 94 additions & 0 deletions sample/src/commonMain/kotlin/co/zsmb/requirektx/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package co.zsmb.requirektx

import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.*
import androidx.compose.ui.unit.sp
import androidx.navigation.NavType
import androidx.navigation.navArgument
import org.jetbrains.compose.ui.tooling.preview.Preview

@Composable
fun App() {
val navController: NavHostController = rememberNavController()
NavHost(
navController,
startDestination = "home"
) {
composable("home") {
Home(onSelectNumber = { number -> navController.navigate("detail/$number") })
}
composable(
"detail/{param}",
arguments = listOf(navArgument("param") { type = NavType.IntType }),
) { backStackEntry ->
val args = backStackEntry.requireArguments()
val number = args.requireInt("param")
Detail(number = number, onNavigateBack = { navController.popBackStack() })
}
}
}

@Composable
@Preview
fun DetailPreview() {
Detail(42, {})
}

@Composable
fun Detail(number: Int, onNavigateBack: () -> Unit) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
IconButton(onClick = { onNavigateBack() }, modifier = Modifier.align(Alignment.TopStart)) {
Icon(Icons.AutoMirrored.Default.ArrowBack, "Back")
}
Text("Your number was $number", fontSize = 20.sp)
}
}

@Composable
@Preview
fun HomePreview() {
Home(onSelectNumber = {})
}

@Preview
@Composable
fun Home(onSelectNumber: (Int) -> Unit) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Enter a number", fontSize = 24.sp)

Spacer(Modifier.height(20.dp))

var inputState by remember { mutableStateOf("") }
val number = inputState.toIntOrNull()

TextField(
value = inputState,
onValueChange = { inputState = it },
)

Spacer(Modifier.height(20.dp))

Button(
onClick = { onSelectNumber(number!!) },
enabled = number != null,
) {
Text("Send")
}
}
}

13 changes: 13 additions & 0 deletions sample/src/desktopMain/kotlin/co/zsmb/requirektx/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package co.zsmb.requirektx

import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application

fun main() = application {
Window(
onCloseRequest = ::exitApplication,
title = "requireKTX sample",
) {
App()
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencyResolutionManagement {
rootProject.name = "requireKTX"

include(
":app",
":sample",
":requirektx-test-helper",
":requirektx-bundle",
":requirektx-intent",
Expand Down

0 comments on commit 7b58e04

Please sign in to comment.