Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Nov 22, 2024
1 parent 5d834c1 commit fe94350
Show file tree
Hide file tree
Showing 32 changed files with 681 additions and 7 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.compose) apply false
}
12 changes: 6 additions & 6 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ private val gitCommitsCount: Int by lazy {
}

kotlin {
androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}
js {
moduleName = "composeApp"
browser {
Expand All @@ -51,12 +57,6 @@ kotlin {
}
binaries.executable()
}
androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}
jvm()
listOf(
iosX64(),
Expand Down
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ min-sdk = "31"
compile-sdk = "35"
target-sdk = "35"
agp = "8.7.2"

androidx-activity = "1.9.3"
androidx-core-splashscreen = "1.0.1"
androidx-lifecycle = "2.8.4"
wearCompose = "1.4.0"
composeUiTooling = "1.4.0"

google-material = "1.12.0"
google-horologist = "0.6.20"

jetbrains-compose = "1.7.1"
jetbrains-androidx-navigation-compose = "2.8.0-alpha10"
Expand Down Expand Up @@ -36,6 +40,7 @@ kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }

google-material = { module = "com.google.android.material:material", version.ref = "google-material" }
google-horologist-compose-layout = { module = "com.google.android.horologist:horologist-compose-layout", version.ref = "google-horologist" }

jetbrains-androidx-navigation-compose = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "jetbrains-androidx-navigation-compose" }
jetbrains-androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "jetbrains-androidx-lifecycle-viewmodel-compose" }
Expand All @@ -45,6 +50,10 @@ androidx-activity-compose = { module = "androidx.activity:activity-compose", ver
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "androidx-core-splashscreen" }
androidx-lifecycle-viewmodel = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-viewmodel", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime-compose = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
androidx-wear-compose-foundation = { module = "androidx.wear.compose:compose-foundation", version.ref = "wearCompose" }
androidx-wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearCompose" }
androidx-wear-compose-navigation = { module = "androidx.wear.compose:compose-navigation", version.ref = "wearCompose" }
androidx-wear-ui-tooling = { module = "androidx.wear.compose:compose-ui-tooling", version.ref = "composeUiTooling" }

coil3-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil3" }
coil3-network-ktor = { module = "io.coil-kt.coil3:coil-network-ktor", version.ref = "coil3" }
Expand All @@ -67,6 +76,7 @@ napier = { module = "io.github.aakira:napier", version.ref = "napier" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
android-application = { id = "com.android.application", version.ref = "agp" }
compose = { id = "org.jetbrains.compose", version.ref = "jetbrains-compose" }
buildkonfig = { id = "com.codingfeline.buildkonfig", version.ref = "buildkonfig" }
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ dependencyResolutionManagement {
}
}

include(":composeApp")
include(":composeApp")
include(":wearApp")
67 changes: 67 additions & 0 deletions wearApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@file:OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class)

import org.apache.commons.io.output.ByteArrayOutputStream
import java.nio.charset.Charset

plugins {
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.android.application)
alias(libs.plugins.compose)
}

private val gitCommitsCount: Int by lazy {
val stdout = ByteArrayOutputStream()
rootProject.exec {
commandLine("git", "rev-list", "--count", "HEAD")
standardOutput = stdout
}
stdout.toString(Charset.defaultCharset()).trim().toInt()
}

kotlin {
jvmToolchain(21)
}

android {
namespace = "org.michaelbel.template"
compileSdk = libs.versions.compile.sdk.get().toInt()

defaultConfig {
applicationId = "org.michaelbel.template"
minSdk = libs.versions.min.sdk.get().toInt()
targetSdk = libs.versions.target.sdk.get().toInt()
versionName = "1.0.0"
versionCode = gitCommitsCount
}
buildFeatures {
compose = true
}
}

base {
archivesName.set("KmpTemplate-v${android.defaultConfig.versionName}(${android.defaultConfig.versionCode})")
}

dependencies {
implementation(libs.androidx.core.splashscreen)
implementation(libs.google.material)
implementation(libs.google.horologist.compose.layout)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.wear.compose.foundation)
implementation(libs.androidx.wear.compose.material)
implementation(libs.androidx.wear.compose.navigation)
}

tasks.register("printVersionName") {
doLast {
println(android.defaultConfig.versionName)
}
}

tasks.register("printVersionCode") {
doLast {
println(android.defaultConfig.versionCode.toString())
}
}
36 changes: 36 additions & 0 deletions wearApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-feature android:name="android.hardware.type.watch" />

<application
android:name=".WearApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.App.Starting"
tools:ignore="UnusedAttribute">

<uses-library
android:name="com.google.android.wearable"
android:required="true" />

<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />

<activity
android:exported="true"
android:name="org.michaelbel.template.WearMainActivity">
<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,4 @@
package org.michaelbel.template

val TemplateName: String
get() = "WearOS Template"
10 changes: 10 additions & 0 deletions wearApp/src/main/java/org/michaelbel/template/WearApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.michaelbel.template

import android.app.Application

class WearApplication: Application() {

override fun onCreate() {
super.onCreate()
}
}
105 changes: 105 additions & 0 deletions wearApp/src/main/java/org/michaelbel/template/WearMainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
@file:OptIn(ExperimentalHorologistApi::class)

package org.michaelbel.template

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.activity.ComponentActivity
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.navigation.NavHostController
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import androidx.wear.compose.navigation.SwipeDismissableNavHost
import androidx.wear.compose.navigation.composable
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
import com.google.android.horologist.annotations.ExperimentalHorologistApi
import com.google.android.horologist.compose.layout.AppScaffold
import com.google.android.horologist.compose.layout.ScreenScaffold
import com.google.android.horologist.compose.layout.rememberColumnState

class WearMainActivity: ComponentActivity() {

private lateinit var navController: NavHostController

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
setContent {
navController = rememberSwipeDismissableNavController()
WearApp(
navController = navController
)
}
}
}

@Composable
fun WearApp(
navController: NavHostController
) {
AppScaffold {
SwipeDismissableNavHost(
navController = navController,
startDestination = Screen.Home.route
) {
composable(
route = Screen.Home.route
) {
val scrollState = rememberColumnState()
ScreenScaffold(
modifier = Modifier.fillMaxSize(),
scrollState = scrollState
) {

Text(
text = "Home",
modifier = Modifier.fillMaxSize().align(Alignment.Center),
style = MaterialTheme.typography.title1,
textAlign = TextAlign.Center
)
}
}
composable(
route = Screen.Chat.route
) {
val scrollState = rememberColumnState()
ScreenScaffold(
scrollState = scrollState
) {
Text(
text = "Chat",
style = MaterialTheme.typography.title1,
textAlign = TextAlign.Center
)
}
}
composable(
route = Screen.Settings.route
) {
val scrollState = rememberColumnState()
ScreenScaffold(
scrollState = scrollState
) {
Text(
text = "Settings",
style = MaterialTheme.typography.title1,
textAlign = TextAlign.Center
)
}
}
}
}
}

sealed class Screen(
val route: String
) {
data object Home: Screen("home")
data object Chat: Screen("chat")
data object Settings: Screen("settings")
}
30 changes: 30 additions & 0 deletions wearApp/src/main/res/drawable-v24/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
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="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Loading

0 comments on commit fe94350

Please sign in to comment.