Merge pull request #71 from amir1376/feat/improve-home-page

feat/improve home page
This commit is contained in:
AmirHossein Abdolmotallebi 2024-09-12 08:48:27 +03:30 committed by GitHub
commit 7b15b3fa69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 17 deletions

View File

@ -18,7 +18,9 @@ import com.abdownloadmanager.desktop.utils.action.simpleAction
import com.abdownloadmanager.desktop.utils.mvi.ContainsEffects import com.abdownloadmanager.desktop.utils.mvi.ContainsEffects
import com.abdownloadmanager.desktop.utils.mvi.supportEffects import com.abdownloadmanager.desktop.utils.mvi.supportEffects
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.coerceIn
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.ComponentContext import com.arkivanov.decompose.ComponentContext
import ir.amirab.downloader.downloaditem.DownloadCredentials import ir.amirab.downloader.downloaditem.DownloadCredentials
@ -49,7 +51,7 @@ sealed interface HomeEffects {
data object BringToFront : HomeEffects data object BringToFront : HomeEffects
data class DeleteItems( data class DeleteItems(
val list: List<Long> val list: List<Long>,
) : HomeEffects ) : HomeEffects
} }
@ -269,12 +271,25 @@ class HomeComponent(
) )
val windowSize = _windowSize.asStateFlow() val windowSize = _windowSize.asStateFlow()
fun setWindowSize(dpSize: DpSize) { fun setWindowSize(dpSize: DpSize) {
_windowSize.update { dpSize } _windowSize.value = dpSize
}
private val _categoriesWidth = homePageStateToPersist.mapTwoWayStateFlow(
map = {
it.categoriesWidth.dp.coerceIn(CATEGORIES_SIZE_RANGE)
},
unMap = {
copy(categoriesWidth = it.coerceIn(CATEGORIES_SIZE_RANGE).value)
}
)
val categoriesWidth = _categoriesWidth.asStateFlow()
fun setCategoriesWidth(updater: (Dp) -> Dp) {
_categoriesWidth.value = updater(_categoriesWidth.value)
} }
private fun requestDelete( private fun requestDelete(
downloadList: List<Long> downloadList: List<Long>,
) { ) {
sendEffect(HomeEffects.DeleteItems(downloadList)) sendEffect(HomeEffects.DeleteItems(downloadList))
} }
@ -645,4 +660,8 @@ class HomeComponent(
"DELETE" to downloadActions.deleteAction "DELETE" to downloadActions.deleteAction
"ctrl I" to downloadActions.openDownloadDialogAction "ctrl I" to downloadActions.openDownloadDialogAction
} }
companion object {
val CATEGORIES_SIZE_RANGE = 0.dp..500.dp
}
} }

View File

@ -22,7 +22,6 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import com.abdownloadmanager.desktop.ui.widget.Text import com.abdownloadmanager.desktop.ui.widget.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import com.abdownloadmanager.desktop.utils.externaldraggable.*
import com.abdownloadmanager.desktop.utils.externaldraggable.onExternalDrag import com.abdownloadmanager.desktop.utils.externaldraggable.onExternalDrag
import androidx.compose.ui.* import androidx.compose.ui.*
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
@ -111,21 +110,24 @@ fun HomePage(component: HomeComponent) {
Spacer(Modifier.height(4.dp)) Spacer(Modifier.height(4.dp))
TopBar(component) TopBar(component)
Spacer(Modifier.height(6.dp)) Spacer(Modifier.height(6.dp))
Spacer(Modifier.fillMaxWidth() Spacer(
.height(1.dp) Modifier.fillMaxWidth()
.background(myColors.surface) .height(1.dp)
.background(myColors.surface)
) )
Row() { Row() {
var width by remember { mutableStateOf(170.dp) } val categoriesWidth by component.categoriesWidth.collectAsState()
Categories(Modifier.padding(top = 8.dp) Categories(
.width(width), component Modifier.padding(top = 8.dp)
.width(categoriesWidth), component
) )
Spacer(Modifier.size(8.dp)) Spacer(Modifier.size(8.dp))
//split pane //split pane
Handle(Modifier.width(5.dp) Handle(
.fillMaxHeight() Modifier.width(5.dp)
) { .fillMaxHeight()
width += it ) { delta ->
component.setCategoriesWidth { it + delta }
} }
Column(Modifier.weight(1f)) { Column(Modifier.weight(1f)) {
Row( Row(
@ -262,7 +264,7 @@ private fun ShowDeletePrompts(
ActionButton( ActionButton(
text = "Delete", text = "Delete",
onClick = onConfirm, onClick = onConfirm,
borderColor = SolidColor(myColors.error ), borderColor = SolidColor(myColors.error),
contentColor = myColors.error, contentColor = myColors.error,
) )
Spacer(Modifier.width(8.dp)) Spacer(Modifier.width(8.dp))
@ -274,7 +276,7 @@ private fun ShowDeletePrompts(
@Stable @Stable
class DeletePromptState( class DeletePromptState(
val downloadList: List<Long> val downloadList: List<Long>,
) { ) {
var alsoDeleteFile by mutableStateOf(false) var alsoDeleteFile by mutableStateOf(false)
} }

View File

@ -17,6 +17,7 @@ import org.koin.core.component.inject
data class HomePageStateToPersist( data class HomePageStateToPersist(
val downloadListState: TableState.SerializableTableState? = null, val downloadListState: TableState.SerializableTableState? = null,
val windowSize: Pair<Float, Float> = 1000f to 500f, val windowSize: Pair<Float, Float> = 1000f to 500f,
val categoriesWidth: Float = 170f,
) { ) {
class ConfigLens(prefix: String) : Lens<MapConfig, HomePageStateToPersist>, class ConfigLens(prefix: String) : Lens<MapConfig, HomePageStateToPersist>,
KoinComponent { KoinComponent {
@ -25,6 +26,7 @@ data class HomePageStateToPersist(
class Keys(prefix: String) { class Keys(prefix: String) {
val windowWidth = floatKeyOf("${prefix}window.width") val windowWidth = floatKeyOf("${prefix}window.width")
val windowHeight = floatKeyOf("${prefix}window.height") val windowHeight = floatKeyOf("${prefix}window.height")
val categoriesWidth = floatKeyOf("${prefix}categories.width")
val downloadListTableState = keyOfEncoded<TableState.SerializableTableState>("${prefix}downloadListState") val downloadListTableState = keyOfEncoded<TableState.SerializableTableState>("${prefix}downloadListState")
} }
@ -34,6 +36,7 @@ data class HomePageStateToPersist(
return with(json) { return with(json) {
HomePageStateToPersist( HomePageStateToPersist(
downloadListState = source.getDecoded(keys.downloadListTableState), downloadListState = source.getDecoded(keys.downloadListTableState),
categoriesWidth = source.get(keys.categoriesWidth) ?: default.categoriesWidth,
windowSize = run { windowSize = run {
val width = source.get(keys.windowWidth) val width = source.get(keys.windowWidth)
val height = source.get(keys.windowHeight) val height = source.get(keys.windowHeight)
@ -51,6 +54,7 @@ data class HomePageStateToPersist(
with(json) { with(json) {
source.put(keys.windowWidth, focus.windowSize.first) source.put(keys.windowWidth, focus.windowSize.first)
source.put(keys.windowHeight, focus.windowSize.second) source.put(keys.windowHeight, focus.windowSize.second)
source.put(keys.categoriesWidth, focus.categoriesWidth)
source.putEncodedNullable(keys.downloadListTableState, focus.downloadListState) source.putEncodedNullable(keys.downloadListTableState, focus.downloadListState)
} }
return source return source

View File

@ -3,6 +3,7 @@ package com.abdownloadmanager.desktop.pages.home
import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.WindowPosition import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.rememberWindowState import androidx.compose.ui.window.rememberWindowState
import com.abdownloadmanager.desktop.actions.LocalShortCutManager import com.abdownloadmanager.desktop.actions.LocalShortCutManager
@ -43,7 +44,9 @@ fun HomeWindow(
} }
) { ) {
LaunchedEffect(windowState.size) { LaunchedEffect(windowState.size) {
homeComponent.setWindowSize(windowState.size) if (!windowState.isMinimized && windowState.placement == WindowPlacement.Floating) {
homeComponent.setWindowSize(windowState.size)
}
} }
window.minimumSize = Dimension( window.minimumSize = Dimension(
400, 400 400, 400