Skip to content

Commit

Permalink
准备一个'现在开打'
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Apr 9, 2024
1 parent 33320a0 commit c8a4811
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 42 deletions.
28 changes: 16 additions & 12 deletions src/main/kotlin/view/account/AccountDetailView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +14,7 @@ import androidx.compose.ui.unit.dp
@Composable
inline fun AccountDetailView(
state: PageViewState,
pages: List<AccountViewPage>,
pageSelectors: List<AccountViewPageSelector>,
selected: AccountViewPage?,
crossinline onSelect: (AccountViewPage?) -> Unit
) {
Expand All @@ -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) }
// )
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/view/account/AccountHome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PageViewState(

}

val pageViews: List<AccountViewPage> = listOf(
val pageViews: List<AccountViewPageSelector> = listOf(
AccountHomeView,
AccountWeaponPageView,
AccountBonusRecordView,
Expand Down
53 changes: 46 additions & 7 deletions src/main/kotlin/view/account/AccountViewPage.kt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -18,11 +61,7 @@ interface AccountViewPage {

@Composable
fun menuLabel(state: PageViewState)
}


/**
* 右侧主要视图。
*/
@Composable
fun rightView(state: PageViewState)

}
87 changes: 71 additions & 16 deletions src/main/kotlin/view/account/home/AccountHomeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/view/account/record/AccountBonusRecordView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -45,7 +45,7 @@ import java.time.ZoneId
*
* @author ForteScarlet
*/
object AccountBonusRecordView : AccountViewPage {
object AccountBonusRecordView : SimpleAccountViewPageSelector {

override val isMenuIconSupport: Boolean
get() = true
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/view/account/stats/StatsPageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +20,7 @@ import java.time.YearMonth
*
* @author ForteScarlet
*/
object StatsPageView : AccountViewPage {
object StatsPageView : SimpleAccountViewPageSelector {

override val isMenuIconSupport: Boolean
get() = true
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/view/account/weapon/AccountWeaponPageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c8a4811

Please sign in to comment.