From 7f5c2cc2a06179a463a0f3169ab49e6f036d787a Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Sun, 16 Jun 2024 18:19:51 +0800 Subject: [PATCH] v1.0.12 --- .gitignore | 5 +- .idea/kotlinc.xml | 2 +- .idea/misc.xml | 1 + build.gradle.kts | 19 +- gradle.properties | 6 +- gradle/libs.versions.toml | 12 +- .../view/account/home/AccountHomeView.kt | 176 +++++++++++++++--- 7 files changed, 172 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index b63da45..129f8b9 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,7 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + +.logs +.kotlin diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml index fe63bb6..6d0ee1c 100644 --- a/.idea/kotlinc.xml +++ b/.idea/kotlinc.xml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index eab145f..ef0ea04 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + diff --git a/build.gradle.kts b/build.gradle.kts index ad27cc6..51b57ac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,12 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { alias(libs.plugins.kotlinJvm) alias(libs.plugins.jetbrainsCompose) + alias(libs.plugins.compose.compiler) // https://conveyor.hydraulic.dev/14.0/configs/maven-gradle/#gradle //id("dev.hydraulic.conveyor") version "1.9" idea @@ -14,7 +16,7 @@ val appName = "StopBonus" val appPackage = "love.forte.bonus" val appMenuGroup = "forteApp" val appNameWithPackage = "$appPackage.$appName" -val appVersion = "1.0.11" +val appVersion = "1.0.12" group = appPackage version = appVersion @@ -26,18 +28,19 @@ repositories { } java { - //toolchain.languageVersion.set(JavaLanguageVersion.of(17)) - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + toolchain { + this.languageVersion.set(JavaLanguageVersion.of(17)) + } } -tasks.withType { - kotlinOptions { - jvmTarget = "17" - freeCompilerArgs = freeCompilerArgs + listOf("-Xopt-in=kotlin.RequiresOptIn") +kotlin { + jvmToolchain(17) + compilerOptions { + jvmTarget.set(JvmTarget.JVM_17) } } + dependencies { // Note, if you develop a library, you should use compose.desktop.common. // compose.desktop.currentOs should be used in launcher-sourceSet diff --git a/gradle.properties b/gradle.properties index 19590b4..a6e9ce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,8 +1,6 @@ kotlin.code.style=official #org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -#org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" -#org.gradle.parallel=true -#org.gradle.daemon=true -org.gradle.jvmargs=-Xms1g -Xmx4g -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" +#org.gradle.jvmargs=-Xms1g -Xmx4g -Dfile.encoding=UTF-8 org.gradle.parallel=true org.gradle.daemon=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5a22a92..7d0f1fb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,19 +1,20 @@ [versions] compose = "1.6.3" -compose-plugin = "1.6.1" +compose-plugin = "1.6.10" # Kotlin -kotlin = "1.9.23" -kotlinx-coroutines = "1.8.0" +kotlin = "2.0.0" +kotlinx-coroutines = "1.8.1" kotlinx-serialization = "1.6.3" # logback logback = "1.4.14" # https://github.com/h2database/h2database h2 = "2.2.224" # https://github.com/JetBrains/Exposed -exposed = "0.49.0" +exposed = "0.51.1" # https://github.com/KoalaPlot/koalaplot-core # https://koalaplot.github.io/ -koalaPlot = "0.5.3" +#koalaPlot = "0.5.3" +koalaPlot = "0.6.0" [libraries] @@ -46,6 +47,7 @@ exposed = ["exposed-core", "exposed-dao", "exposed-jdbc", "exposed-javaTime"] [plugins] jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } +compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlinKapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } diff --git a/src/main/kotlin/view/account/home/AccountHomeView.kt b/src/main/kotlin/view/account/home/AccountHomeView.kt index f3b0819..8c51bb5 100644 --- a/src/main/kotlin/view/account/home/AccountHomeView.kt +++ b/src/main/kotlin/view/account/home/AccountHomeView.kt @@ -4,14 +4,52 @@ import FontBTTFamily import FontLXGWNeoXiHeiScreenFamily import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.Crossfade -import androidx.compose.foundation.* +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.focusable +import androidx.compose.foundation.hoverable import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Clear import androidx.compose.material.icons.filled.Home -import androidx.compose.material3.* -import androidx.compose.runtime.* +import androidx.compose.material3.DatePicker +import androidx.compose.material3.DatePickerDialog +import androidx.compose.material3.DisplayMode +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.ElevatedButton +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.ExposedDropdownMenuBox +import androidx.compose.material3.ExposedDropdownMenuDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.LocalTextStyle +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.NavigationDrawerItem +import androidx.compose.material3.OutlinedTextField +import androidx.compose.material3.SelectableDates +import androidx.compose.material3.Slider +import androidx.compose.material3.SliderState +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.material3.TimeInput +import androidx.compose.material3.rememberDatePickerState +import androidx.compose.material3.rememberTimePickerState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -20,16 +58,29 @@ import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.TextUnitType import androidx.compose.ui.unit.dp import androidx.compose.ui.window.PopupProperties -import database.entity.* +import database.entity.Account +import database.entity.BonusRecord +import database.entity.Weapon +import database.entity.WeaponView +import database.entity.Weapons +import database.entity.toView import kotlinx.coroutines.launch import org.jetbrains.exposed.sql.SizedCollection import view.account.AccountViewPage import view.account.AccountViewPageSelector import view.account.PageViewState -import java.time.* +import java.time.Duration +import java.time.Instant +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.Year +import java.time.ZoneId +import java.time.ZoneOffset +import java.time.ZonedDateTime import java.time.format.DateTimeFormatter private const val EMOJI_ANGRY = "\uD83D\uDE21" +private const val EMOJI_CLOCK = "\u23F1" /** * @@ -136,18 +187,29 @@ private fun AccountHome(state: PageViewState) { } ) - val startTimePickerState = rememberTimePickerState(is24Hour = true) - val selectedStartDateMillis = startDatePickerState.selectedDateMillis val selectedStartDateInstant = selectedStartDateMillis?.let { Instant.ofEpochMilli(it) } - val selectedStartDateTime = selectedStartDateInstant?.atZone(ZoneId.systemDefault()) - ?.toLocalDate() - ?.atTime(startTimePickerState.hour, startTimePickerState.minute) + + var startTimePickerValue by remember { mutableStateOf(null) } + + fun selectedStartDateTime(): LocalDateTime? { + val selectedStartDateInstantValue = selectedStartDateInstant + ?: return null + val timeValue = startTimePickerValue + ?: return null + + return selectedStartDateInstantValue.atZone(ZoneId.systemDefault()) + .toLocalDate() + .atTime(timeValue) + } + + val selectedStartDateTime = selectedStartDateTime() + val endDatePickerState = rememberDatePickerState( initialSelectedDateMillis = null, initialDisplayedMonthMillis = selectedStartDateMillis ?: System.currentTimeMillis(), - yearRange = selectedStartDateTime?.let { + yearRange = selectedStartDateTime()?.let { it.year..nowYear.value } ?: nowYear.value..nowYear.value, initialDisplayMode = DisplayMode.Input, @@ -158,19 +220,41 @@ private fun AccountHome(state: PageViewState) { } ) - val endTimePickerState = rememberTimePickerState( - initialHour = nowTime.hour, - initialMinute = nowTime.minute - ) + val selectedEndDateMillis = endDatePickerState.selectedDateMillis + val selectedEndDateInstant = selectedEndDateMillis?.let { Instant.ofEpochMilli(it) } + // val selectedEndDateTime = selectedEndDateInstant?.atZone(ZoneId.systemDefault()) + // ?.toLocalDate() + // ?.atTime(endTimePickerState.hour, endTimePickerState.minute) + + var endTimePickerValue by remember { mutableStateOf(null) } + + fun selectedEndDateTime(): LocalDateTime? { + val selectedEndDateInstantValue = selectedEndDateInstant + ?: return null + val timeValue = endTimePickerValue + ?: return null + + return selectedEndDateInstantValue.atZone(ZoneId.systemDefault()) + .toLocalDate() + .atTime(timeValue) + } + + val selectedEndDateTime = selectedEndDateTime() + + // val endTimePickerState = rememberTimePickerState( + // is24Hour = true, + // initialHour = nowTime.hour, + // initialMinute = nowTime.minute + // ) var weapon by remember { mutableStateOf(null) } val score = remember { SliderState(value = 10f, steps = 8, valueRange = 1f..10f) } - suspend fun clearStates() { + fun clearStates() { startDatePickerState.selectedDateMillis = null - startTimePickerState.settle() + // startTimePickerState.settle() endDatePickerState.selectedDateMillis = null - endTimePickerState.settle() + // endTimePickerState.settle() weapon = null score.value = 10f } @@ -183,10 +267,30 @@ private fun AccountHome(state: PageViewState) { // start date var showSelectStartDate by remember { mutableStateOf(false) } if (showSelectStartDate) { + val nowTime0 = LocalTime.now() + val startTimePickerState = rememberTimePickerState( + is24Hour = true, + initialHour = nowTime0.hour, + initialMinute = nowTime0.minute + ) + DatePickerDialog( onDismissRequest = { showSelectStartDate = false }, + dismissButton = { + TextButton(onClick = { + startDatePickerState.selectedDateMillis = System.currentTimeMillis() + }) { + Text( + "现在$EMOJI_CLOCK", + fontFamily = FontLXGWNeoXiHeiScreenFamily, + ) + } + }, confirmButton = { - TextButton(onClick = { showSelectStartDate = false }) { + TextButton(onClick = { + startTimePickerValue = LocalTime.of(startTimePickerState.hour, startTimePickerState.minute) + showSelectStartDate = false + }) { Text( "就是这时$EMOJI_ANGRY", fontFamily = FontLXGWNeoXiHeiScreenFamily, @@ -195,7 +299,6 @@ private fun AccountHome(state: PageViewState) { }, ) { DatePicker( - modifier = Modifier.padding(20.dp), state = startDatePickerState, title = { Text( @@ -219,7 +322,7 @@ private fun AccountHome(state: PageViewState) { onClick = { showSelectStartDate = true } ) { Text( - "什么时候开始打的\uD83D\uDE21", + "什么时候开始打的$EMOJI_ANGRY$EMOJI_ANGRY", fontFamily = FontLXGWNeoXiHeiScreenFamily, fontSize = TextUnit(50f, TextUnitType.Sp), modifier = Modifier @@ -240,10 +343,30 @@ private fun AccountHome(state: PageViewState) { // end date & time var showEndDateTime by remember { mutableStateOf(false) } if (showEndDateTime) { + val nowTime0 = LocalTime.now() + val endTimePickerState = rememberTimePickerState( + is24Hour = true, + initialHour = nowTime0.hour, + initialMinute = nowTime0.minute + ) + DatePickerDialog( onDismissRequest = { showEndDateTime = false }, + dismissButton = { + TextButton(onClick = { + endDatePickerState.selectedDateMillis = System.currentTimeMillis() + }) { + Text( + "现在$EMOJI_CLOCK", + fontFamily = FontLXGWNeoXiHeiScreenFamily, + ) + } + }, confirmButton = { - TextButton(onClick = { showEndDateTime = false }) { + TextButton(onClick = { + endTimePickerValue = LocalTime.of(endTimePickerState.hour, endTimePickerState.minute) + showEndDateTime = false + }) { Text( "就是这时$EMOJI_ANGRY", fontFamily = FontLXGWNeoXiHeiScreenFamily, @@ -252,7 +375,6 @@ private fun AccountHome(state: PageViewState) { }, ) { DatePicker( - modifier = Modifier.padding(20.dp), state = endDatePickerState, title = { Text( @@ -284,12 +406,6 @@ private fun AccountHome(state: PageViewState) { } } - val selectedEndDateMillis = endDatePickerState.selectedDateMillis - val selectedEndDateInstant = selectedEndDateMillis?.let { Instant.ofEpochMilli(it) } - val selectedEndDateTime = selectedEndDateInstant?.atZone(ZoneId.systemDefault()) - ?.toLocalDate() - ?.atTime(endTimePickerState.hour, endTimePickerState.minute) - AnimatedVisibility(selectedEndDateTime != null) { Text( text = selectedEndDateTime?.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) ?: "",