Skip to content

Commit

Permalink
running on android
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Nov 8, 2023
1 parent a46fefb commit 74454a1
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/android/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:name=".App">
<activity
android:exported="true"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
Expand Down
28 changes: 28 additions & 0 deletions app/android/src/androidMain/kotlin/dev/datlag/burningseries/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.datlag.burningseries

import androidx.multidex.MultiDexApplication
import dev.datlag.burningseries.module.NetworkModule
import io.github.aakira.napier.DebugAntilog
import io.github.aakira.napier.Napier
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.bindSingleton

class App : MultiDexApplication(), DIAware {

override val di: DI = DI {
bindSingleton {
applicationContext
}

import(NetworkModule.di)
}

override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) {
Napier.base(DebugAntilog())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dev.datlag.burningseries

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.CompositionLocalProvider
import androidx.core.view.WindowCompat
import com.arkivanov.decompose.DefaultComponentContext
import com.arkivanov.essenty.lifecycle.Lifecycle
import com.arkivanov.essenty.lifecycle.LifecycleOwner
import com.arkivanov.essenty.lifecycle.essentyLifecycle
import dev.datlag.burningseries.common.lifecycle.LocalLifecycleOwner
import dev.datlag.burningseries.ui.navigation.NavHostComponent
import io.kamel.core.config.KamelConfig
import io.kamel.core.config.takeFrom
import io.kamel.image.config.Default
import io.kamel.image.config.LocalKamelConfig
import io.kamel.image.config.resourcesFetcher
import io.kamel.image.config.resourcesIdMapper

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)
enableEdgeToEdge()

val di = ((applicationContext as? App) ?: (application as App)).di
val imageConfig = KamelConfig {
takeFrom(KamelConfig.Default)
resourcesFetcher(this@MainActivity)
resourcesIdMapper(this@MainActivity)
}

val lifecycleOwner = object : LifecycleOwner {
override val lifecycle: Lifecycle = essentyLifecycle()
}

val root = NavHostComponent(
componentContext = DefaultComponentContext(
lifecycle = lifecycleOwner.lifecycle
),
di = di
)

setContent {
CompositionLocalProvider(
LocalKamelConfig provides imageConfig,
LocalLifecycleOwner provides lifecycleOwner
) {
App(di) {
root.render()
}
}
}
}
}
3 changes: 0 additions & 3 deletions app/android/src/androidMain/res/values/strings.xml

This file was deleted.

7 changes: 7 additions & 0 deletions app/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ kotlin {
}
}
val androidMain by getting {
dependsOn(commonMain)
apply(plugin = "kotlin-parcelize")

dependencies {
Expand All @@ -88,6 +89,8 @@ kotlin {
}
}
val desktopMain by getting {
dependsOn(commonMain)

dependencies {
api(compose.desktop.currentOs)
api(libs.coroutines.swing)
Expand All @@ -96,6 +99,10 @@ kotlin {
api(libs.ktor.jvm)
}
}

val iosMain by getting {
dependsOn(commonMain)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import androidx.compose.runtime.Composable

@Composable
actual fun SystemProvider(content: @Composable () -> Unit) {
content()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
package dev.datlag.burningseries.module

import io.ktor.client.*
import io.ktor.client.engine.okhttp.*
import org.kodein.di.DI
import org.kodein.di.bindSingleton

actual object PlatformModule {
actual val di: DI.Module
get() = TODO("Not yet implemented")

private const val NAME = "PlatformModuleAndroid"

actual val di: DI.Module = DI.Module(NAME) {
bindSingleton {
HttpClient(OkHttp) {
engine {
config {
followRedirects(true)
}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import androidx.compose.runtime.Composable

@Composable
actual fun SystemProvider(content: @Composable () -> Unit) {
content()
}
5 changes: 5 additions & 0 deletions app/shared/src/iosMain/kotlin/main.ios.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import androidx.compose.ui.window.ComposeUIViewController

fun MainViewController() = ComposeUIViewController {

}
4 changes: 0 additions & 4 deletions network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ kotlin {
api(libs.ktsoup.ktor)
}
}

val androidMain by getting {
dependsOn(jvmMain.get())
}
}
}

Expand Down

0 comments on commit 74454a1

Please sign in to comment.