Skip to content

Commit

Permalink
Merge pull request #108 from amir1376/feature/improve-add-multi-downl…
Browse files Browse the repository at this point in the history
…oad-page

improve add multiple download page
  • Loading branch information
amir1376 authored Oct 15, 2024
2 parents 5613f6c + 4a49566 commit 3a9272b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ fun ShowAddDownloadDialogs(component: AddDownloadDialogManager) {
}

is AddMultiDownloadComponent -> {
val h = 400
val w = 700
val h = 450
val w = 800
val state = rememberWindowState(
height = h.dp,
width = w.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.abdownloadmanager.desktop.pages.addDownload.multiple.AddMultiItemSaveMode.*
import com.abdownloadmanager.desktop.utils.asState
import com.abdownloadmanager.utils.FileIconProvider
import com.abdownloadmanager.utils.category.Category
import com.abdownloadmanager.utils.category.CategoryManager
import com.abdownloadmanager.utils.category.CategorySelectionMode
Expand Down Expand Up @@ -44,6 +45,9 @@ class AddMultiDownloadComponent(
private val appSettings by inject<AppRepository>()
private val client by inject<DownloaderClient>()
val downloadSystem by inject<DownloadSystem>()
val fileIconProvider: FileIconProvider by inject()


private val _folder = MutableStateFlow(appSettings.saveLocation.value)
val folder = _folder.asStateFlow()
fun setFolder(folder: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.Key
Expand All @@ -23,6 +25,8 @@ import androidx.compose.ui.input.key.onKeyEvent
import androidx.compose.ui.input.pointer.isShiftPressed
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.abdownloadmanager.utils.FileIconProvider
import com.abdownloadmanager.utils.compose.widget.MyIcon

@Composable
fun AddMultiDownloadTable(
Expand All @@ -33,6 +37,7 @@ fun AddMultiDownloadTable(

val lastSelectedId = component.lastSelectedId
val context = AddMultiItemListContext(component, component.isAllSelected)
val iconProvider = component.fileIconProvider
CompositionLocalProvider(
LocalAddMultiItemListContext provides context,
) {
Expand Down Expand Up @@ -129,7 +134,7 @@ fun AddMultiDownloadTable(
it.border(1.dp, Color.Transparent)
}
}
.padding(vertical = 2.dp, horizontal = itemHorizontalPadding)
.padding(vertical = 8.dp, horizontal = itemHorizontalPadding)
) {
content()
}
Expand All @@ -148,7 +153,10 @@ fun AddMultiDownloadTable(
}

AddMultiItemTableCells.Name -> {
NameCell(item)
NameCell(
downloadUiChecker = item,
iconProvider = iconProvider,
)
}

AddMultiItemTableCells.Link -> {
Expand Down Expand Up @@ -194,8 +202,8 @@ sealed class AddMultiItemTableCells : TableCell<DownloadUiChecker> {
return listOf(
Check,
Name,
Link,
SizeCell,
Link,
)
}
}
Expand All @@ -218,17 +226,17 @@ sealed class AddMultiItemTableCells : TableCell<DownloadUiChecker> {

data object Name : AddMultiItemTableCells() {
override val name: String = "Name"
override val size: CellSize = CellSize.Resizeable(120.dp..300.dp, 160.dp)
override val size: CellSize = CellSize.Resizeable(120.dp..1000.dp, 350.dp)
}

data object Link : AddMultiItemTableCells() {
override val name: String = "Link"
override val size: CellSize = CellSize.Resizeable(120.dp..300.dp, 120.dp)
override val size: CellSize = CellSize.Resizeable(120.dp..2000.dp, 240.dp)
}

data object SizeCell : AddMultiItemTableCells() {
override val name: String = "Size"
override val size: CellSize = CellSize.Resizeable(120.dp..180.dp)
override val size: CellSize = CellSize.Resizeable(100.dp..180.dp, 100.dp)
}
}

Expand All @@ -247,23 +255,36 @@ private fun CellText(

@Composable
private fun NameCell(
it: DownloadUiChecker
downloadUiChecker: DownloadUiChecker,
iconProvider: FileIconProvider,
) {
val name by it.name.collectAsState()
CellText(name)
val name by downloadUiChecker.name.collectAsState()
val icon = iconProvider.rememberIcon(name)
Row(
verticalAlignment = Alignment.CenterVertically,
) {
MyIcon(
icon = icon,
contentDescription = null,
modifier = Modifier.size(16.dp).alpha(0.75f)
)
Spacer(Modifier.width(8.dp))
CellText(name)
}

}

@Composable
private fun LinkCell(
downloadChecker: DownloadUiChecker
downloadChecker: DownloadUiChecker,
) {
val credentials by downloadChecker.credentials.collectAsState()
CellText(credentials.link)
}

@Composable
private fun SizeCell(
downloadChecker: DownloadUiChecker
downloadChecker: DownloadUiChecker,
) {
val length by downloadChecker.length.collectAsState()
CellText(
Expand Down

0 comments on commit 3a9272b

Please sign in to comment.