Skip to content

Commit

Permalink
[optimize|fix]优化首页布局;UiEvent类及其成员所属类别由data class改为普通的class,因为data cla…
Browse files Browse the repository at this point in the history
…ss重写了equals,导致LaunchedEffect无法识别出新的内容相同的事件
  • Loading branch information
SkyD666 committed Sep 23, 2023
1 parent 58da1b7 commit 66286e9
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk 24
targetSdk 34
versionCode 31
versionName "1.5-beta06"
versionName "1.5-beta07"
flavorDimensions = ["versionName"]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/skyd/rays/model/bean/MiniToolBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
data class MiniToolBean(
val title: String,
val icon: ImageVector,
val experimental: Boolean = false,
val action: () -> Unit
) : BaseBean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Science
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.skyd.rays.R
import com.skyd.rays.model.bean.MiniTool1Bean
import com.skyd.rays.ui.component.lazyverticalgrid.adapter.LazyGridAdapter

Expand Down Expand Up @@ -63,6 +67,12 @@ fun MiniTool1Item(
maxLines = 1,
textAlign = TextAlign.Center
)
if (data.experimental) {
Icon(
imageVector = Icons.Default.Science,
contentDescription = stringResource(R.string.mini_tool_experimental),
)
}
}
}
}
46 changes: 14 additions & 32 deletions app/src/main/java/com/skyd/rays/ui/screen/MainScreen.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.skyd.rays.ui.screen

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.pager.rememberPagerState
Expand All @@ -22,8 +20,6 @@ import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationRail
import androidx.compose.material3.NavigationRailItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SearchBarDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
Expand All @@ -44,14 +40,9 @@ const val MAIN_SCREEN_ROUTE = "mainScreen"

@Composable
fun getMainScreenTopBarWindowInsets(): WindowInsets =
if (LocalWindowSizeClass.current.isCompact) WindowInsets(0)
if (LocalWindowSizeClass.current.isCompact) TopAppBarDefaults.windowInsets
else TopAppBarDefaults.windowInsets.only(WindowInsetsSides.End + WindowInsetsSides.Top)

@Composable
fun getMainScreenSearchBarWindowInsets(): WindowInsets =
if (LocalWindowSizeClass.current.isCompact) WindowInsets(0)
else SearchBarDefaults.windowInsets

@Composable
fun MainScreen() {
val windowSizeClass = LocalWindowSizeClass.current
Expand All @@ -67,28 +58,19 @@ fun MainScreen() {
}
)
}
val contentPager = @Composable {
ContentPager(pagerState = pagerState)
val contentPager: @Composable (modifier: Modifier) -> Unit = @Composable { modifier ->
ContentPager(modifier = modifier, pagerState = pagerState)
}

Scaffold(
bottomBar = if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) {
navigationBarOrRail
} else {
{}
if (windowSizeClass.isCompact) {
Column {
contentPager(modifier = Modifier.weight(1f))
navigationBarOrRail()
}
) { innerPadding ->
if (windowSizeClass.widthSizeClass != WindowWidthSizeClass.Compact) {
Row(modifier = Modifier.fillMaxSize()) {
navigationBarOrRail()
Box(modifier = Modifier.weight(1f)) {
contentPager()
}
}
} else {
Box(modifier = Modifier.padding(innerPadding)) {
contentPager()
}
} else {
Row {
navigationBarOrRail()
contentPager(modifier = Modifier.weight(1f))
}
}
}
Expand Down Expand Up @@ -139,10 +121,10 @@ private fun NavigationBarOrRail(
}

@Composable
private fun ContentPager(pagerState: PagerState) {
private fun ContentPager(modifier: Modifier, pagerState: PagerState) {
HorizontalPager(
state = pagerState,
modifier = Modifier.fillMaxSize(),
modifier = modifier,
userScrollEnabled = false
) { page ->
when (page) {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/skyd/rays/ui/screen/add/AddEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package com.skyd.rays.ui.screen.add
import com.skyd.rays.base.IUiEvent
import com.skyd.rays.model.bean.StickerWithTags

data class AddEvent(
class AddEvent(
val getStickersWithTagsUiEvent: GetStickersWithTagsUiEvent? = null,
val addStickersResultUiEvent: AddStickersResultUiEvent? = null,
val recognizeTextUiEvent: RecognizeTextUiEvent? = null,
) : IUiEvent

sealed class GetStickersWithTagsUiEvent {
data class Success(val stickerWithTags: StickerWithTags) : GetStickersWithTagsUiEvent()
class Success(val stickerWithTags: StickerWithTags) : GetStickersWithTagsUiEvent()
object Init : GetStickersWithTagsUiEvent()
object Failed : GetStickersWithTagsUiEvent()
}

sealed class AddStickersResultUiEvent {
object Duplicate : AddStickersResultUiEvent()
data class Success(val stickerUuid: String) : AddStickersResultUiEvent()
class Success(val stickerUuid: String) : AddStickersResultUiEvent()
}

sealed class RecognizeTextUiEvent {
data class Success(val texts: Set<String>) : RecognizeTextUiEvent()
class Success(val texts: Set<String>) : RecognizeTextUiEvent()
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/skyd/rays/ui/screen/home/HomeEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.skyd.rays.ui.screen.home

import com.skyd.rays.base.IUiEvent

data class HomeEvent(
class HomeEvent(
val homeResultUiEvent: HomeResultUiEvent? = null,
) : IUiEvent

sealed class HomeResultUiEvent {
data class Success(val successCount: Int) : HomeResultUiEvent()
class Success(val successCount: Int) : HomeResultUiEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
homeResultUiEvent.successCount,
homeResultUiEvent.successCount
),
key2 = homeResultUiEvent
key2 = homeResultUiEvent,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import com.skyd.rays.ui.local.LocalNavController
import com.skyd.rays.ui.local.LocalShowPopularTags
import com.skyd.rays.ui.local.LocalWindowSizeClass
import com.skyd.rays.ui.screen.add.ADD_SCREEN_ROUTE
import com.skyd.rays.ui.screen.getMainScreenSearchBarWindowInsets
import com.skyd.rays.ui.screen.home.HomeIntent
import com.skyd.rays.ui.screen.home.HomeState
import com.skyd.rays.ui.screen.home.HomeViewModel
Expand Down Expand Up @@ -138,7 +137,6 @@ fun RaysSearchBar(
.padding(horizontal = searchBarHorizontalPadding)
) {
SearchBar(
windowInsets = getMainScreenSearchBarWindowInsets(),
onQueryChange = onQueryChange,
query = query,
onSearch = { keyword ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.skyd.rays.ui.screen.minitool

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
Expand All @@ -8,19 +9,23 @@ import androidx.compose.material.icons.filled.Style
import androidx.compose.material3.Scaffold
import androidx.compose.material3.ScaffoldDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.skyd.rays.R
import com.skyd.rays.ext.plus
import com.skyd.rays.ext.screenIsLand
import com.skyd.rays.model.bean.MiniTool1Bean
import com.skyd.rays.ui.component.RaysIconButton
import com.skyd.rays.ui.component.RaysTopBar
import com.skyd.rays.ui.component.RaysTopBarStyle
import com.skyd.rays.ui.component.lazyverticalgrid.RaysLazyVerticalGrid
import com.skyd.rays.ui.component.lazyverticalgrid.adapter.LazyGridAdapter
import com.skyd.rays.ui.component.lazyverticalgrid.adapter.proxy.MiniTool1Proxy
Expand All @@ -32,12 +37,15 @@ const val MINI_TOOL_SCREEN_ROUTE = "miniToolScreen"

@Composable
fun MiniToolScreen() {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val navController = LocalNavController.current
val context = LocalContext.current

Scaffold(
topBar = {
RaysTopBar(
style = RaysTopBarStyle.Large,
scrollBehavior = scrollBehavior,
title = { Text(text = stringResource(id = R.string.mini_tool_screen_name)) },
navigationIcon = {
RaysIconButton(imageVector = Icons.Default.Extension, onClick = { })
Expand All @@ -61,6 +69,7 @@ fun MiniToolScreen() {
MiniTool1Bean(
title = stringResource(R.string.style_transfer_screen_name),
icon = Icons.Default.Style,
experimental = true,
action = { navController.navigate(STYLE_TRANSFER_SCREEN_ROUTE) }
),
)
Expand All @@ -71,10 +80,12 @@ fun MiniToolScreen() {
)
}
RaysLazyVerticalGrid(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
dataList = miniToolList,
adapter = adapter,
contentPadding = it
contentPadding = it + PaddingValues(vertical = 10.dp),
)
}
}
14 changes: 12 additions & 2 deletions app/src/main/java/com/skyd/rays/ui/screen/more/MoreScreen.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.skyd.rays.ui.screen.more

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
Expand All @@ -11,19 +12,23 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.ScaffoldDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.skyd.rays.R
import com.skyd.rays.ext.plus
import com.skyd.rays.ext.screenIsLand
import com.skyd.rays.model.bean.More1Bean
import com.skyd.rays.ui.component.RaysIconButton
import com.skyd.rays.ui.component.RaysTopBar
import com.skyd.rays.ui.component.RaysTopBarStyle
import com.skyd.rays.ui.component.lazyverticalgrid.RaysLazyVerticalGrid
import com.skyd.rays.ui.component.lazyverticalgrid.adapter.LazyGridAdapter
import com.skyd.rays.ui.component.lazyverticalgrid.adapter.proxy.More1Proxy
Expand All @@ -38,12 +43,15 @@ import com.skyd.rays.ui.screen.settings.data.importexport.IMPORT_EXPORT_SCREEN_R

@Composable
fun MoreScreen() {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val navController = LocalNavController.current
val context = LocalContext.current

Scaffold(
topBar = {
RaysTopBar(
style = RaysTopBarStyle.Large,
scrollBehavior = scrollBehavior,
title = { Text(text = stringResource(id = R.string.more_screen_name)) },
navigationIcon = { RaysIconButton(imageVector = Icons.Default.Egg, onClick = { }) },
windowInsets = getMainScreenTopBarWindowInsets(),
Expand Down Expand Up @@ -101,10 +109,12 @@ fun MoreScreen() {
)
}
RaysLazyVerticalGrid(
modifier = Modifier.fillMaxSize(),
modifier = Modifier
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
dataList = moreList,
adapter = adapter,
contentPadding = it
contentPadding = it + PaddingValues(vertical = 10.dp),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.skyd.rays.ui.screen.settings.api.apigrant

import com.skyd.rays.base.IUiEvent

data class ApiGrantEvent(
class ApiGrantEvent(
val addPackageNameUiEvent: AddPackageNameUiEvent? = null,
) : IUiEvent

sealed class AddPackageNameUiEvent {
object Success : AddPackageNameUiEvent()
data class Failed(val msg: String) : AddPackageNameUiEvent()
class Failed(val msg: String) : AddPackageNameUiEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.skyd.rays.ui.screen.settings.data

import com.skyd.rays.base.IUiEvent

data class DataEvent(
class DataEvent(
val deleteAllResultUiEvent: DeleteAllResultUiEvent? = null,
) : IUiEvent

sealed class DeleteAllResultUiEvent {
data class Success(val time: Long) : DeleteAllResultUiEvent()
class Success(val time: Long) : DeleteAllResultUiEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.skyd.rays.ui.screen.settings.data.importexport.cloud.webdav
import com.skyd.rays.base.IUiEvent
import com.skyd.rays.model.bean.WebDavInfo

data class WebDavEvent(
class WebDavEvent(
val uploadResultUiEvent: UploadResultUiEvent? = null,
val downloadResultUiEvent: DownloadResultUiEvent? = null,
) : IUiEvent

sealed class UploadResultUiEvent {
data class Success(val result: WebDavInfo) : UploadResultUiEvent()
class Success(val result: WebDavInfo) : UploadResultUiEvent()
}

sealed class DownloadResultUiEvent {
data class Success(val result: WebDavInfo) : DownloadResultUiEvent()
class Success(val result: WebDavInfo) : DownloadResultUiEvent()
}
Loading

0 comments on commit 66286e9

Please sign in to comment.