From c8a48110920600f9e4d868e81c2e89c7e197f75a Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Tue, 9 Apr 2024 21:05:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=86=E5=A4=87=E4=B8=80=E4=B8=AA'=E7=8E=B0?= =?UTF-8?q?=E5=9C=A8=E5=BC=80=E6=89=93'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/view/account/AccountDetailView.kt | 28 +++--- src/main/kotlin/view/account/AccountHome.kt | 2 +- .../kotlin/view/account/AccountViewPage.kt | 53 +++++++++-- .../view/account/home/AccountHomeView.kt | 87 +++++++++++++++---- .../account/record/AccountBonusRecordView.kt | 4 +- .../view/account/stats/StatsPageView.kt | 4 +- .../account/weapon/AccountWeaponPageView.kt | 4 +- 7 files changed, 140 insertions(+), 42 deletions(-) diff --git a/src/main/kotlin/view/account/AccountDetailView.kt b/src/main/kotlin/view/account/AccountDetailView.kt index 4417599..063b79c 100644 --- a/src/main/kotlin/view/account/AccountDetailView.kt +++ b/src/main/kotlin/view/account/AccountDetailView.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.Text import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.NavigationDrawerItem import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -15,7 +14,7 @@ import androidx.compose.ui.unit.dp @Composable inline fun AccountDetailView( state: PageViewState, - pages: List, + pageSelectors: List, selected: AccountViewPage?, crossinline onSelect: (AccountViewPage?) -> Unit ) { @@ -34,17 +33,22 @@ inline fun AccountDetailView( HorizontalDivider(Modifier.fillMaxWidth(.80f).padding(vertical = 20.dp).align(Alignment.CenterHorizontally)) Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { - pages.forEach { page -> - NavigationDrawerItem( - selected = page == selected, - onClick = { onSelect(if (page == selected) null else page) }, - icon = if (page.isMenuIconSupport) { - { - page.menuIcon(state) - } - } else null, - label = { page.menuLabel(state) } + pageSelectors.forEach { page -> + page.navigationDrawerItem( + state = state, + selected = selected, + onSelect = { onSelect(it) } ) + // NavigationDrawerItem( + // selected = page == selected, + // onClick = { onSelect(if (page == selected) null else page) }, + // icon = if (page.isMenuIconSupport) { + // { + // page.menuIcon(state) + // } + // } else null, + // label = { page.menuLabel(state) } + // ) } } diff --git a/src/main/kotlin/view/account/AccountHome.kt b/src/main/kotlin/view/account/AccountHome.kt index b32d324..25c5a78 100644 --- a/src/main/kotlin/view/account/AccountHome.kt +++ b/src/main/kotlin/view/account/AccountHome.kt @@ -49,7 +49,7 @@ class PageViewState( } -val pageViews: List = listOf( +val pageViews: List = listOf( AccountHomeView, AccountWeaponPageView, AccountBonusRecordView, diff --git a/src/main/kotlin/view/account/AccountViewPage.kt b/src/main/kotlin/view/account/AccountViewPage.kt index d89fa0e..c7894ed 100644 --- a/src/main/kotlin/view/account/AccountViewPage.kt +++ b/src/main/kotlin/view/account/AccountViewPage.kt @@ -1,14 +1,57 @@ package view.account -import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.material3.NavigationDrawerItem import androidx.compose.runtime.Composable +interface AccountViewPageSelector { + /** + * 左侧菜单列表中的元素, + * 并用于选择一个page。 + */ + @Composable + fun navigationDrawerItem( + state: PageViewState, + selected: AccountViewPage?, + onSelect: (AccountViewPage?) -> Unit + ) + +} + /** * * @author ForteScarlet */ interface AccountViewPage { + /** + * 右侧主要视图。 + */ + @Composable + fun rightView(state: PageViewState) +} + +/** + * Selector 和 page 结合在一起 + */ +interface SimpleAccountViewPageSelector : AccountViewPageSelector, AccountViewPage { + @Composable + override fun navigationDrawerItem( + state: PageViewState, + selected: AccountViewPage?, + onSelect: (AccountViewPage?) -> Unit + ) { + NavigationDrawerItem( + selected = this == selected, + onClick = { onSelect(if (this == selected) null else this) }, + icon = if (isMenuIconSupport) { + { + menuIcon(state) + } + } else null, + label = { menuLabel(state) } + ) + } + val isMenuIconSupport: Boolean get() = false @@ -18,11 +61,7 @@ interface AccountViewPage { @Composable fun menuLabel(state: PageViewState) +} + - /** - * 右侧主要视图。 - */ - @Composable - fun rightView(state: PageViewState) -} diff --git a/src/main/kotlin/view/account/home/AccountHomeView.kt b/src/main/kotlin/view/account/home/AccountHomeView.kt index be73236..f3b0819 100644 --- a/src/main/kotlin/view/account/home/AccountHomeView.kt +++ b/src/main/kotlin/view/account/home/AccountHomeView.kt @@ -4,11 +4,9 @@ import FontBTTFamily import FontLXGWNeoXiHeiScreenFamily import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.Crossfade -import androidx.compose.foundation.background -import androidx.compose.foundation.focusable +import androidx.compose.foundation.* +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* -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 @@ -26,6 +24,7 @@ import database.entity.* 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.format.DateTimeFormatter @@ -36,25 +35,81 @@ private const val EMOJI_ANGRY = "\uD83D\uDE21" * * @author ForteScarlet */ -object AccountHomeView : AccountViewPage { - - override val isMenuIconSupport: Boolean - get() = true +object AccountHomeView : AccountViewPageSelector { @Composable - override fun menuIcon(state: PageViewState) { - Icon(Icons.Filled.Home, "Home icon") - } + override fun navigationDrawerItem( + state: PageViewState, + selected: AccountViewPage?, + onSelect: (AccountViewPage?) -> Unit + ) { + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween + ) { + NavigationDrawerItem( + modifier = Modifier.fillMaxWidth(.5f), + selected = this == selected, + onClick = { + onSelect(if (AccountHomePage == selected) null else AccountHomePage) + }, + icon = { + menuIcon(state) + }, + label = { + Text("我打了😢", fontFamily = FontLXGWNeoXiHeiScreenFamily) + } + ) - @Composable - override fun menuLabel(state: PageViewState) { - Text("我打了😢", fontFamily = FontLXGWNeoXiHeiScreenFamily) + // TODO + NavigationDrawerItem( + modifier = Modifier.clickable(false) {}.hoverable(remember { MutableInteractionSource() }, false), + selected = false, // TODO + onClick = { + // onSelect(if (thisPage == selected) null else thisPage) + }, + icon = { + menuIcon(state) + }, + label = { + Column { + Text("现在开打😡", fontFamily = FontLXGWNeoXiHeiScreenFamily) + Text( + "(暂不可用)", + fontFamily = FontLXGWNeoXiHeiScreenFamily, + color = MaterialTheme.colorScheme.error + ) + } + } + ) + } } + // override val isMenuIconSupport: Boolean + // get() = true + // + @Composable - override fun rightView(state: PageViewState) { - AccountHome(state) + private fun menuIcon(state: PageViewState) { + Icon(Icons.Filled.Home, "Home icon") } + // + // @Composable + // override fun menuLabel(state: PageViewState) { + // Row { + // Text("我打了😢", fontFamily = FontLXGWNeoXiHeiScreenFamily) + // Text("现在开打😡", fontFamily = FontLXGWNeoXiHeiScreenFamily) + // } + // } + + private data object AccountHomePage : AccountViewPage { + @Composable + override fun rightView(state: PageViewState) { + AccountHome(state) + } + } + + } @OptIn(ExperimentalMaterial3Api::class) diff --git a/src/main/kotlin/view/account/record/AccountBonusRecordView.kt b/src/main/kotlin/view/account/record/AccountBonusRecordView.kt index 89f3fa6..ae03342 100644 --- a/src/main/kotlin/view/account/record/AccountBonusRecordView.kt +++ b/src/main/kotlin/view/account/record/AccountBonusRecordView.kt @@ -35,8 +35,8 @@ import org.jetbrains.exposed.dao.with import org.jetbrains.exposed.sql.SortOrder import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.deleteWhere -import view.account.AccountViewPage import view.account.PageViewState +import view.account.SimpleAccountViewPageSelector import java.time.Duration import java.time.ZoneId @@ -45,7 +45,7 @@ import java.time.ZoneId * * @author ForteScarlet */ -object AccountBonusRecordView : AccountViewPage { +object AccountBonusRecordView : SimpleAccountViewPageSelector { override val isMenuIconSupport: Boolean get() = true diff --git a/src/main/kotlin/view/account/stats/StatsPageView.kt b/src/main/kotlin/view/account/stats/StatsPageView.kt index d9578f9..741f186 100644 --- a/src/main/kotlin/view/account/stats/StatsPageView.kt +++ b/src/main/kotlin/view/account/stats/StatsPageView.kt @@ -8,8 +8,8 @@ import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp -import view.account.AccountViewPage import view.account.PageViewState +import view.account.SimpleAccountViewPageSelector import view.account.stats.StatsType.COUNT import java.time.Year import java.time.YearMonth @@ -20,7 +20,7 @@ import java.time.YearMonth * * @author ForteScarlet */ -object StatsPageView : AccountViewPage { +object StatsPageView : SimpleAccountViewPageSelector { override val isMenuIconSupport: Boolean get() = true diff --git a/src/main/kotlin/view/account/weapon/AccountWeaponPageView.kt b/src/main/kotlin/view/account/weapon/AccountWeaponPageView.kt index fe4c789..9280c79 100644 --- a/src/main/kotlin/view/account/weapon/AccountWeaponPageView.kt +++ b/src/main/kotlin/view/account/weapon/AccountWeaponPageView.kt @@ -29,15 +29,15 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.deleteWhere -import view.account.AccountViewPage import view.account.PageViewState +import view.account.SimpleAccountViewPageSelector /** * * @author ForteScarlet */ -object AccountWeaponPageView : AccountViewPage { +object AccountWeaponPageView : SimpleAccountViewPageSelector { override val isMenuIconSupport: Boolean get() = true