-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a16df04
commit 253c946
Showing
12 changed files
with
169 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
androidApp/src/main/java/com/mirego/kmp/boilerplate/MainActivity.kt
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
androidApp/src/main/java/com/mirego/kmp/boilerplate/app/AndroidApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mirego.kmp.boilerplate.app | ||
|
||
import android.app.Application | ||
import com.mirego.kmp.boilerplate.app.bootstrap.AndroidBootstrap | ||
import com.mirego.kmp.boilerplate.bootstrap.Bootstrapper | ||
|
||
class AndroidApplication : Application() { | ||
val bootstrapper = Bootstrapper() | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
bootstrapper.initDependencies(AndroidBootstrap(this)) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
androidApp/src/main/java/com/mirego/kmp/boilerplate/app/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.mirego.kmp.boilerplate.app | ||
|
||
import android.os.Bundle | ||
import androidx.activity.compose.setContent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.WindowCompat | ||
import com.mirego.kmp.boilerplate.app.ui.application.ApplicationView | ||
import com.mirego.kmp.boilerplate.bootstrap.Bootstrapper | ||
import com.mirego.kmp.boilerplate.trikot.viewmodels.declarative.compose.getInitialViewModel | ||
import com.mirego.kmp.boilerplate.viewmodel.application.ApplicationViewModel | ||
|
||
class MainActivity : AppCompatActivity() { | ||
private val bootstrapper: Bootstrapper | ||
get() = (applicationContext as AndroidApplication).bootstrapper | ||
|
||
private val viewModel: ApplicationViewModel by lazy { | ||
getInitialViewModel { | ||
bootstrapper.applicationViewModel() | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
WindowCompat.setDecorFitsSystemWindows(window, false) | ||
setContent { | ||
ApplicationView(applicationViewModel = viewModel) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
androidApp/src/main/java/com/mirego/kmp/boilerplate/app/bootstrap/AndroidBootstrap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mirego.kmp.boilerplate.app.bootstrap | ||
|
||
import android.content.Context | ||
import com.mirego.kmp.boilerplate.app.resources.AndroidImageProvider | ||
import com.mirego.kmp.boilerplate.bootstrap.AppEnvironment | ||
import com.mirego.kmp.boilerplate.bootstrap.Bootstrap | ||
import com.mirego.kmp.boilerplate.common.BuildConfig | ||
import com.mirego.trikot.kword.android.AndroidKWord | ||
import com.mirego.trikot.viewmodels.declarative.configuration.TrikotViewModelDeclarative | ||
import java.util.Locale | ||
|
||
class AndroidBootstrap(context: Context) : Bootstrap { | ||
|
||
override val appInformation = AppInformationImpl(context) | ||
|
||
override val environment = when (BuildConfig.FLAVOR.lowercase()) { | ||
"ci" -> AppEnvironment.DEV | ||
"store" -> AppEnvironment.PRODUCTION | ||
else -> AppEnvironment.PRODUCTION | ||
} | ||
|
||
init { | ||
if (Locale.getDefault().language.lowercase() == "fr") { | ||
AndroidKWord.setCurrentLanguageCode("fr") | ||
} else { | ||
AndroidKWord.setCurrentLanguageCode("en") | ||
} | ||
|
||
TrikotViewModelDeclarative.initialize( | ||
imageProvider = AndroidImageProvider() | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
androidApp/src/main/java/com/mirego/kmp/boilerplate/app/bootstrap/AppInformationImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.mirego.kmp.boilerplate.app.bootstrap | ||
|
||
import android.content.Context | ||
import com.mirego.kmp.boilerplate.bootstrap.AppInformation | ||
import com.mirego.kmp.boilerplate.common.BuildConfig | ||
import com.mirego.kmp.boilerplate.model.Language | ||
import com.mirego.kmp.boilerplate.model.Locale | ||
|
||
class AppInformationImpl(context: Context) : AppInformation { | ||
override val locale: Locale = Locale( | ||
if (java.util.Locale.getDefault().language.lowercase() == "fr") Language.FRENCH else Language.ENGLISH, | ||
java.util.Locale.getDefault().country | ||
) | ||
|
||
override val versionNumber: String = "${BuildConfig.VERSION_NAME}.${BuildConfig.VERSION_CODE}" | ||
override val diskCachePath: String = context.cacheDir.toString() | ||
} |
9 changes: 9 additions & 0 deletions
9
androidApp/src/main/java/com/mirego/kmp/boilerplate/app/resources/AndroidImageProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.mirego.kmp.boilerplate.app.resources | ||
|
||
import android.content.Context | ||
import com.mirego.trikot.viewmodels.declarative.configuration.VMDImageProvider | ||
import com.mirego.trikot.viewmodels.declarative.properties.VMDImageResource | ||
|
||
class AndroidImageProvider : VMDImageProvider { | ||
override fun resourceIdForResource(resource: VMDImageResource, context: Context) = null | ||
} |
13 changes: 13 additions & 0 deletions
13
androidApp/src/main/java/com/mirego/kmp/boilerplate/app/ui/application/ApplicationView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mirego.kmp.boilerplate.app.ui.application | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import com.mirego.kmp.boilerplate.app.ui.root.RootView | ||
import com.mirego.kmp.boilerplate.viewmodel.application.ApplicationViewModel | ||
import com.mirego.trikot.viewmodels.declarative.compose.extensions.observeAsState | ||
|
||
@Composable | ||
fun ApplicationView(applicationViewModel: ApplicationViewModel) { | ||
val viewModel: ApplicationViewModel by applicationViewModel.observeAsState() | ||
RootView(rootViewModel = viewModel.rootViewModel) | ||
} |
13 changes: 13 additions & 0 deletions
13
androidApp/src/main/java/com/mirego/kmp/boilerplate/app/ui/root/RootView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mirego.kmp.boilerplate.app.ui.root | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import com.mirego.kmp.boilerplate.viewmodel.root.RootViewModel | ||
import com.mirego.trikot.viewmodels.declarative.compose.extensions.observeAsState | ||
|
||
@Composable | ||
fun RootView(rootViewModel: RootViewModel) { | ||
val viewModel: RootViewModel by rootViewModel.observeAsState() | ||
Text(text = "Hi") | ||
} |
25 changes: 25 additions & 0 deletions
25
...kmp/boilerplate/trikot/viewmodels/declarative/compose/VMDViewModelStoreOwnerExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mirego.kmp.boilerplate.trikot.viewmodels.declarative.compose | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.ViewModelStoreOwner | ||
import com.mirego.trikot.viewmodels.declarative.viewmodel.VMDViewModel | ||
|
||
/** | ||
* Use this method to get the initial VMDViewModel. This will make sure that it survives Activity recreation by wrapping it in a androidx.lifecycle.ViewModel | ||
*/ | ||
@Suppress("UNCHECKED_CAST") | ||
fun <VMD : VMDViewModel> ViewModelStoreOwner.getInitialViewModel(factory: () -> VMD): VMD = | ||
ViewModelProvider( | ||
viewModelStore, | ||
ViewModelProviderFactory(factory) | ||
)[ViewModelWrapper::class.java].wrappedViewModel as VMD | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
private class ViewModelProviderFactory<VMD : VMDViewModel>(private val factory: () -> VMD) : ViewModelProvider.Factory { | ||
override fun <VM : ViewModel> create(modelClass: Class<VM>): VM { | ||
return ViewModelWrapper(factory()) as VM | ||
} | ||
} | ||
|
||
class ViewModelWrapper<VMD : VMDViewModel>(val wrappedViewModel: VMD) : ViewModel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters