removed wasmJS for now, added back DataStore, just gonna focus on desktop and mobile for now, get more used to everything.
This commit is contained in:
parent
111a55e194
commit
b226c043d0
12 changed files with 94 additions and 91 deletions
|
@ -21,26 +21,6 @@ kotlin {
|
|||
|
||||
jvm("desktop")
|
||||
|
||||
@OptIn(ExperimentalWasmDsl::class)
|
||||
wasmJs {
|
||||
moduleName = "composeApp"
|
||||
browser {
|
||||
val rootDirPath = project.rootDir.path
|
||||
val projectDirPath = project.projectDir.path
|
||||
commonWebpackConfig {
|
||||
outputFileName = "composeApp.js"
|
||||
devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
|
||||
static = (static ?: mutableListOf()).apply {
|
||||
// Serve sources to debug inside browser
|
||||
add(rootDirPath)
|
||||
add(projectDirPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
binaries.executable()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val desktopMain by getting
|
||||
|
||||
|
@ -61,6 +41,8 @@ kotlin {
|
|||
implementation("org.jetbrains.compose.material3:material3:1.7.0") // Or latest version
|
||||
implementation("org.jetbrains.compose.material3:material3-window-size-class:1.7.0") // For window size classes
|
||||
implementation("org.jetbrains.androidx.navigation:navigation-compose:2.7.0-alpha07")
|
||||
api(libs.datastore.preferences)
|
||||
api(libs.datastore)
|
||||
}
|
||||
desktopMain.dependencies {
|
||||
implementation(compose.desktop.currentOs)
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
package com.menagerie.ophelia
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.menagerie.ophelia.ui.theme.OpheliaTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -19,8 +12,13 @@ class MainActivity : ComponentActivity() {
|
|||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
|
||||
|
||||
setContent {
|
||||
MainView()
|
||||
MainView(
|
||||
prefs = remember {
|
||||
createDataStore(application)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.menagerie.ophelia
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
|
||||
fun createDataStore(context: Context): DataStore<Preferences> {
|
||||
return createDataStore {
|
||||
context.filesDir.resolve(DATA_STORE_FILE_NAME).absolutePath
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import com.menagerie.ophelia.sensor.SensorDataManager
|
||||
import com.menagerie.ophelia.sensor.SensorManagerImpl
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
@ -12,7 +14,10 @@ import kotlinx.coroutines.flow.collect
|
|||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun MainView(isLargeScreen: Boolean = false) {
|
||||
fun MainView(
|
||||
isLargeScreen: Boolean = false,
|
||||
prefs: DataStore<Preferences>,
|
||||
) {
|
||||
|
||||
val sensorManager = SensorManagerImpl()
|
||||
|
||||
|
@ -36,5 +41,9 @@ fun MainView(isLargeScreen: Boolean = false) {
|
|||
}
|
||||
}
|
||||
|
||||
App(sensorManager, isLargeScreen)
|
||||
App(
|
||||
sensorManager = sensorManager,
|
||||
isLarge = isLargeScreen,
|
||||
prefs = prefs,
|
||||
)
|
||||
}
|
|
@ -5,12 +5,16 @@ import androidx.compose.animation.SharedTransitionLayout
|
|||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
|
@ -19,10 +23,8 @@ import com.menagerie.ophelia.sensor.SensorManager
|
|||
import com.menagerie.ophelia.model.recipesList
|
||||
import com.menagerie.ophelia.recipesdetails.RecipeDetails
|
||||
import com.menagerie.ophelia.recipeslist.RecipesListScreen
|
||||
import com.menagerie.ophelia.sensor.SensorManager
|
||||
import com.menagerie.ophelia.ui.theme.OpheliaTheme
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
enum class Theme {
|
||||
Auto,
|
||||
|
@ -30,6 +32,8 @@ enum class Theme {
|
|||
Dark
|
||||
}
|
||||
|
||||
val themeKey = stringPreferencesKey("theme")
|
||||
|
||||
enum class DetailListAppScreen {
|
||||
List,
|
||||
Details,
|
||||
|
@ -37,24 +41,34 @@ enum class DetailListAppScreen {
|
|||
|
||||
@OptIn(ExperimentalSharedTransitionApi::class)
|
||||
@Composable
|
||||
fun App(sensorManager: SensorManager?, isLarge: Boolean = false) {
|
||||
fun App(
|
||||
sensorManager: SensorManager?,
|
||||
isLarge: Boolean = false,
|
||||
prefs: DataStore<Preferences>
|
||||
) {
|
||||
|
||||
val navController = rememberNavController()
|
||||
|
||||
var currentTheme by rememberSaveable { mutableStateOf(Theme.Light)}
|
||||
val currentThemeString by prefs
|
||||
.data
|
||||
.map {
|
||||
it[themeKey] ?: Theme.Dark.name
|
||||
}
|
||||
.collectAsState(Theme.Dark.name)
|
||||
var currentTheme by rememberSaveable { mutableStateOf(Theme.Light) }
|
||||
val isDarkTheme: Boolean? = when (currentTheme) {
|
||||
Theme.Dark -> true
|
||||
Theme.Light -> false
|
||||
Theme.Auto -> null
|
||||
}
|
||||
|
||||
val onThemeToggle = {
|
||||
currentTheme = when (currentTheme) {
|
||||
Theme.Auto -> Theme.Light
|
||||
Theme.Light -> Theme.Dark
|
||||
Theme.Dark -> Theme.Auto
|
||||
}
|
||||
}
|
||||
// val onThemeToggle = {
|
||||
// currentTheme = when (currentTheme) {
|
||||
// Theme.Auto -> Theme.Light
|
||||
// Theme.Light -> Theme.Dark
|
||||
// Theme.Dark -> Theme.Auto
|
||||
// }
|
||||
// }
|
||||
|
||||
OpheliaTheme(isDarkTheme ?: isSystemInDarkTheme()) {
|
||||
|
||||
|
@ -86,9 +100,9 @@ fun App(sensorManager: SensorManager?, isLarge: Boolean = false) {
|
|||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// Scaffold {
|
||||
// var showContent by remember { mutableStateOf(false) }
|
||||
// Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
|
@ -113,5 +127,5 @@ fun App(sensorManager: SensorManager?, isLarge: Boolean = false) {
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.menagerie.ophelia
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import okio.Path.Companion.toPath
|
||||
|
||||
fun createDataStore(producePath: () -> String): DataStore<Preferences> {
|
||||
return PreferenceDataStoreFactory.createWithPath(
|
||||
produceFile = { producePath().toPath() }
|
||||
)
|
||||
}
|
||||
|
||||
internal const val DATA_STORE_FILE_NAME = "prefs.preferences_pb"
|
|
@ -3,11 +3,21 @@ package com.menagerie.ophelia
|
|||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.application
|
||||
|
||||
fun main() = application {
|
||||
Window(
|
||||
onCloseRequest = ::exitApplication,
|
||||
title = "Ophelia",
|
||||
) {
|
||||
App(null, true)
|
||||
fun main() {
|
||||
|
||||
val prefs = createDataStore{
|
||||
"settings/files/$DATA_STORE_FILE_NAME"
|
||||
}
|
||||
application {
|
||||
Window(
|
||||
onCloseRequest = ::exitApplication,
|
||||
title = "Ophelia",
|
||||
) {
|
||||
App(
|
||||
sensorManager = null,
|
||||
isLarge = true,
|
||||
prefs = prefs,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package com.menagerie.ophelia
|
||||
|
||||
class WasmPlatform: Platform {
|
||||
override val name: String = "Web with Kotlin/Wasm"
|
||||
}
|
||||
|
||||
actual fun getPlatform(): Platform = WasmPlatform()
|
|
@ -1,12 +0,0 @@
|
|||
package com.menagerie.ophelia
|
||||
|
||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.ui.window.ComposeViewport
|
||||
import kotlinx.browser.document
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
fun main() {
|
||||
ComposeViewport(document.body!!) {
|
||||
App(null, true)
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ophelia</title>
|
||||
<link type="text/css" rel="stylesheet" href="styles.css">
|
||||
<script type="application/javascript" src="composeApp.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
|
@ -1,7 +0,0 @@
|
|||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
|
@ -20,6 +20,7 @@ material3Desktop = "1.3.1"
|
|||
uiTextGoogleFonts = "1.7.5"
|
||||
core = "1.15.0"
|
||||
navigation-compose = "2.7.0-alpha07"
|
||||
datastore = "1.1.1"
|
||||
|
||||
[libraries]
|
||||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
||||
|
@ -39,6 +40,8 @@ androidx-material3-android = { group = "androidx.compose.material3", name = "mat
|
|||
androidx-material3-desktop = { group = "androidx.compose.material3", name = "material3-desktop", version.ref = "material3Desktop" }
|
||||
androidx-ui-text-google-fonts = { group = "androidx.compose.ui", name = "ui-text-google-fonts", version.ref = "uiTextGoogleFonts" }
|
||||
androidx-core = { group = "androidx.core", name = "core", version.ref = "core" }
|
||||
datastore = { module = "androidx.datastore:datastore", version.ref = "datastore" }
|
||||
datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" }
|
||||
|
||||
[plugins]
|
||||
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
||||
|
|
Loading…
Add table
Reference in a new issue