Skip to content

Commit

Permalink
Migrate to compose multiplatform 🚀 (#288)
Browse files Browse the repository at this point in the history
* Convert ui core build.gradle to kts

* Migrate ui core to compose multiplatform

* Migrate ui compendium to compose multiplatform

* Migrate monster compendium to compose multiplatform

* Rename monster compendium android module to compose

* Rename android modules to compose

* Add missing enableStrongSkippingMode

* Migrate app module to compose multiplatform

* Add EmptyStateRecovery

* Migrate spell detail android module to compose kmp module

* Create desktop app

* Migrate sync module to compose multiplatform

* Make compose work on iOS

* Make app files internal

* Migrate monster detail module to compose multiplatform

* Make database and back key work on desktop target

* Migrate spell compendium module to compose multiplatform

* Migrate settings module to compose multiplatform

* Create AppWindow composable

* Migrate search module to compose multiplatform

* Migrate monster registration to compose multiplatform

* Migrate monster lore detail to compose multiplatform

* Migrate monster content to compose multiplatform

* Migrate folders modules to compose multiplatform

* Migrate folder preview module to compose multiplatform

* Remove feature state holder modules from app module
  • Loading branch information
alexandregpereira authored Jul 9, 2024
1 parent b858a85 commit 06353fe
Show file tree
Hide file tree
Showing 472 changed files with 2,726 additions and 6,389 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ fastlane/test_output

iOSInjectionProject/

# Hunter JVM database
hunter-database.db
87 changes: 52 additions & 35 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree
import java.time.Instant
Expand Down Expand Up @@ -31,37 +32,12 @@ plugins {

multiplatform {
androidMain {
implementation(project(":core:event"))
implementation(project(":feature:folder-detail:event"))
implementation(project(":feature:folder-list:event"))
implementation(project(":feature:monster-content-manager:event"))
implementation(project(":feature:monster-detail:event"))
implementation(project(":feature:folder-detail:android"))
implementation(project(":feature:folder-insert:android"))
implementation(project(":feature:folder-list:android"))
implementation(project(":feature:folder-preview:android"))
implementation(project(":feature:monster-compendium:android"))
implementation(project(":feature:monster-content-manager:android"))
implementation(project(":feature:monster-detail:android"))
implementation(project(":feature:monster-lore-detail:android"))
implementation(project(":feature:monster-registration:android"))
implementation(project(":feature:sync:android"))
implementation(project(":feature:search:android"))
implementation(project(":feature:settings:android"))
implementation(project(":feature:spell-compendium:android"))
implementation(project(":feature:spell-detail:android"))
implementation(project(":ui:core"))

implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(libs.material)

implementation(libs.koin.android)
implementation(libs.koin.compose)

implementation(libs.bundles.viewmodel.bundle)

implementation(compose.preview)
implementation(libs.compose.activity)

implementation(project.dependencies.platform(libs.firebase.bom))
Expand All @@ -71,20 +47,39 @@ multiplatform {

commonMain {
implementation(project(":core:analytics"))
implementation(project(":core:event"))
implementation(project(":core:localization"))
implementation(project(":core:state-holder"))
implementation(project(":core:ui:state-recovery"))
implementation(project(":domain:app:data"))
implementation(project(":domain:app:core"))
implementation(project(":domain:sync:core"))
implementation(project(":feature:folder-insert:event")) // TODO Remove later
implementation(project(":feature:folder-preview:event")) // TODO Remove later
implementation(project(":feature:monster-lore-detail:event")) // TODO Remove later
implementation(project(":feature:monster-registration:event")) // TODO Remove later
implementation(project(":feature:spell-detail:event")) // TODO Remove later
implementation(project(":feature:monster-compendium:state-holder"))
implementation(project(":feature:monster-detail:state-holder"))
implementation(project(":feature:sync:state-holder"))

implementation(project(":feature:folder-detail:event"))
implementation(project(":feature:folder-list:event"))
implementation(project(":feature:folder-preview:event"))
implementation(project(":feature:monster-content-manager:event"))
implementation(project(":feature:monster-detail:event"))

implementation(project(":feature:folder-detail:compose"))
implementation(project(":feature:folder-insert:compose"))
implementation(project(":feature:folder-list:compose"))
implementation(project(":feature:folder-preview:compose"))
implementation(project(":feature:monster-content-manager:compose"))
implementation(project(":feature:monster-compendium:compose"))
implementation(project(":feature:monster-detail:compose"))
implementation(project(":feature:monster-lore-detail:compose"))
implementation(project(":feature:monster-registration:compose"))
implementation(project(":feature:search:compose"))
implementation(project(":feature:settings:compose"))
implementation(project(":feature:spell-compendium:compose"))
implementation(project(":feature:spell-detail:compose"))
implementation(project(":feature:sync:compose"))

implementation(project(":ui:core"))

implementation(libs.kotlin.coroutines.core)
implementation(libs.koin.core)
implementation(libs.koin.compose)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
Expand All @@ -93,7 +88,11 @@ multiplatform {
implementation(compose.components.uiToolingPreview)
}

jvmMain()
jvmMain {
implementation(compose.desktop.currentOs)
implementation(libs.kotlin.coroutines.desktop)
}

iosMain()

jvmTest {
Expand Down Expand Up @@ -202,6 +201,24 @@ android {
}
}

compose.desktop {
application {
mainClass = "MainKt"

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "br.alexandregpereira.hunter"
packageVersion = "1.0.0"
}
}
}

compose.resources {
publicResClass = false
packageOfResClass = "br.alexandregpereira.hunter.app.ui.resources"
generateResClass = always
}

composeCompiler {
enableStrongSkippingMode = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.compose.ui.test.performTouchInput
import androidx.test.espresso.Espresso
import br.alexandregpereira.hunter.app.MainScreen
import br.alexandregpereira.hunter.app.HunterApp
import org.junit.Rule
import org.junit.Test

Expand All @@ -22,7 +22,7 @@ class FolderListTest {
@Test
fun folderDeletion() {
composeTestRule.setContent {
MainScreen()
HunterApp()
}

composeTestRule.waitUntil(timeoutMillis = 5000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,11 @@
package br.alexandregpereira.hunter.app

import android.app.Application
import br.alexandregpereira.hunter.analytics.di.analyticsModule
import br.alexandregpereira.hunter.data.di.dataModules
import br.alexandregpereira.hunter.detail.di.monsterDetailModule
import br.alexandregpereira.hunter.domain.di.domainModules
import br.alexandregpereira.hunter.event.systembar.bottomBarEventModule
import br.alexandregpereira.hunter.folder.detail.di.folderDetailModule
import br.alexandregpereira.hunter.folder.insert.di.folderInsertModule
import br.alexandregpereira.hunter.folder.list.di.folderListModule
import br.alexandregpereira.hunter.folder.preview.di.folderPreviewModule
import br.alexandregpereira.hunter.localization.di.localizationModule
import br.alexandregpereira.hunter.monster.compendium.di.monsterCompendiumModule
import br.alexandregpereira.hunter.monster.content.di.monsterContentManagerModule
import br.alexandregpereira.hunter.monster.content.preview.di.monsterContentPreviewModule
import br.alexandregpereira.hunter.monster.lore.detail.di.monsterLoreDetailModule
import br.alexandregpereira.hunter.monster.registration.di.monsterRegistrationModule
import br.alexandregpereira.hunter.search.di.searchModule
import br.alexandregpereira.hunter.settings.di.settingsModule
import br.alexandregpereira.hunter.spell.compendium.di.spellCompendiumModule
import br.alexandregpereira.hunter.spell.detail.di.spellDetailModule
import br.alexandregpereira.hunter.sync.di.syncModule
import br.alexandregpereira.hunter.app.di.initKoinModules
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import kotlinx.coroutines.Dispatchers
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.KoinApplication
import org.koin.core.context.startKoin
import org.koin.dsl.module

Expand All @@ -66,39 +44,4 @@ class HunterApplication : Application() {
initKoinModules()
}
}

internal companion object {
private val appModule = module {
factory { Dispatchers.Default }
viewModel { MainViewModel(get(), get(), get(), get(), get(), get(), get(), get()) }
}

fun KoinApplication.initKoinModules() {
modules(domainModules)
modules(dataModules)
modules(
folderDetailModule +
folderInsertModule +
folderListModule +
folderPreviewModule +
monsterLoreDetailModule +
monsterContentManagerModule +
monsterContentPreviewModule +
syncModule +
monsterRegistrationModule +
spellCompendiumModule
)
modules(
analyticsModule,
appModule,
monsterCompendiumModule,
monsterDetailModule,
searchModule,
settingsModule,
spellDetailModule,
bottomBarEventModule,
localizationModule,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val view = createComposeView { contentPadding ->
MainScreen(contentPadding = contentPadding)
HunterApp(contentPadding = contentPadding)
}
setContentView(view)
view.apply {
Expand Down
24 changes: 0 additions & 24 deletions app/src/androidMain/res/drawable/ic_book.xml

This file was deleted.

24 changes: 24 additions & 0 deletions app/src/commonMain/composeResources/drawable/ic_book.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
~ Copyright 2022 Alexandre Gomes Pereira
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#fff" android:pathData="M21,5c-1.11,-0.35 -2.33,-0.5 -3.5,-0.5c-1.95,0 -4.05,0.4 -5.5,1.5c-1.45,-1.1 -3.55,-1.5 -5.5,-1.5S2.45,4.9 1,6v14.65c0,0.25 0.25,0.5 0.5,0.5c0.1,0 0.15,-0.05 0.25,-0.05C3.1,20.45 5.05,20 6.5,20c1.95,0 4.05,0.4 5.5,1.5c1.35,-0.85 3.8,-1.5 5.5,-1.5c1.65,0 3.35,0.3 4.75,1.05c0.1,0.05 0.15,0.05 0.25,0.05c0.25,0 0.5,-0.25 0.5,-0.5V6C22.4,5.55 21.75,5.25 21,5zM21,18.5c-1.1,-0.35 -2.3,-0.5 -3.5,-0.5c-1.7,0 -4.15,0.65 -5.5,1.5V8c1.35,-0.85 3.8,-1.5 5.5,-1.5c1.2,0 2.4,0.15 3.5,0.5V18.5z"/>
<path android:fillColor="#fff" android:pathData="M17.5,10.5c0.88,0 1.73,0.09 2.5,0.26V9.24C19.21,9.09 18.36,9 17.5,9c-1.7,0 -3.24,0.29 -4.5,0.83v1.66C14.13,10.85 15.7,10.5 17.5,10.5z"/>
<path android:fillColor="#fff" android:pathData="M13,12.49v1.66c1.13,-0.64 2.7,-0.99 4.5,-0.99c0.88,0 1.73,0.09 2.5,0.26V11.9c-0.79,-0.15 -1.64,-0.24 -2.5,-0.24C15.8,11.66 14.26,11.96 13,12.49z"/>
<path android:fillColor="#fff" android:pathData="M17.5,14.33c-1.7,0 -3.24,0.29 -4.5,0.83v1.66c1.13,-0.64 2.7,-0.99 4.5,-0.99c0.88,0 1.73,0.09 2.5,0.26v-1.52C19.21,14.41 18.36,14.33 17.5,14.33z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
<path android:fillColor="#fff" android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
<path android:fillColor="#fff" android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
<path android:fillColor="#fff" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2022 Alexandre Gomes Pereira
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package br.alexandregpereira.hunter.app

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.unit.dp
import br.alexandregpereira.hunter.app.di.AppStateRecoveryQualifier
import br.alexandregpereira.hunter.app.ui.AppMainScreen
import br.alexandregpereira.hunter.ui.compose.AppWindow
import br.alexandregpereira.hunter.ui.compose.StateRecoveryLaunchedEffect
import org.koin.compose.KoinContext
import org.koin.compose.koinInject
import org.koin.core.qualifier.named

@Composable
internal fun HunterApp(
contentPadding: PaddingValues = PaddingValues(0.dp),
) = AppWindow {
KoinContext {
StateRecoveryLaunchedEffect(
key = AppStateRecoveryQualifier,
stateRecovery = koinInject(named(AppStateRecoveryQualifier)),
)

val viewModel: MainViewModel = koinInject()
val state by viewModel.state.collectAsState()
AppMainScreen(
state = state,
contentPadding = contentPadding,
onEvent = viewModel::onEvent
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package br.alexandregpereira.hunter.app

import br.alexandregpereira.hunter.localization.Language

interface MainStrings {
internal interface MainStrings {
val compendium: String
val search: String
val folders: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package br.alexandregpereira.hunter.app

sealed class MainViewEvent {
internal sealed class MainViewEvent {
data class BottomNavigationItemClick(val item: BottomBarItem) : MainViewEvent()
}
Loading

0 comments on commit 06353fe

Please sign in to comment.