mirror of
https://github.com/amir1376/ab-download-manager.git
synced 2025-02-20 11:43:24 +08:00
Merge pull request #235 from amir1376/improve/sorting-logic
Improve/sorting table cell logic
This commit is contained in:
commit
041a0ecd3e
@ -11,7 +11,7 @@ import ir.amirab.util.compose.asStringSource
|
||||
sealed interface TranslatorsCells : TableCell<LanguageTranslationInfo> {
|
||||
data object LanguageName : TranslatorsCells,
|
||||
SortableCell<LanguageTranslationInfo> {
|
||||
override fun sortBy(item: LanguageTranslationInfo): Comparable<*> = item.locale
|
||||
override fun comparator(): Comparator<LanguageTranslationInfo> = compareBy { it.locale }
|
||||
override val id: String = "language"
|
||||
override val name: StringSource = Res.string.language.asStringSource()
|
||||
override val size: CellSize = CellSize.Resizeable(100.dp..1000.dp, 200.dp)
|
||||
|
@ -12,22 +12,26 @@ import ir.amirab.util.compose.asStringSource
|
||||
sealed interface LibraryCells : TableCell<Library> {
|
||||
data object Name : LibraryCells,
|
||||
SortableCell<Library> {
|
||||
override fun sortBy(item: Library): Comparable<*> = item.name
|
||||
override fun comparator(): Comparator<Library> = compareBy { it.name }
|
||||
override val id: String = "Name"
|
||||
override val name: StringSource = Res.string.name.asStringSource()
|
||||
override val size: CellSize = CellSize.Resizeable(100.dp..1000.dp,250.dp)
|
||||
override val size: CellSize = CellSize.Resizeable(100.dp..1000.dp, 250.dp)
|
||||
}
|
||||
|
||||
data object Author : LibraryCells,
|
||||
SortableCell<Library> {
|
||||
override fun sortBy(item: Library): Comparable<*> = item.licenses.firstOrNull()?.name.orEmpty()
|
||||
override fun comparator(): Comparator<Library> = compareBy { item ->
|
||||
item.licenses.firstOrNull()?.name.orEmpty()
|
||||
}
|
||||
|
||||
override val id: String = "Author"
|
||||
override val name: StringSource = Res.string.author.asStringSource()
|
||||
override val size: CellSize = CellSize.Resizeable(100.dp..200.dp, 150.dp)
|
||||
}
|
||||
|
||||
data object License : LibraryCells,
|
||||
SortableCell<Library> {
|
||||
override fun sortBy(item: Library): Comparable<*> = item.licenses.firstOrNull()?.name.orEmpty()
|
||||
override fun comparator(): Comparator<Library> = compareBy { it.licenses.firstOrNull()?.name.orEmpty() }
|
||||
|
||||
override val id: String = "License"
|
||||
override val name: StringSource = Res.string.license.asStringSource()
|
||||
|
@ -26,15 +26,11 @@ import androidx.compose.ui.input.key.*
|
||||
import androidx.compose.ui.input.pointer.*
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.abdownloadmanager.resources.Res
|
||||
import com.abdownloadmanager.resources.*
|
||||
import com.abdownloadmanager.utils.FileIconProvider
|
||||
import com.abdownloadmanager.utils.category.CategoryManager
|
||||
import com.abdownloadmanager.utils.category.rememberCategoryOf
|
||||
import ir.amirab.downloader.monitor.*
|
||||
import ir.amirab.util.compose.resources.myStringResource
|
||||
import ir.amirab.downloader.monitor.IDownloadItemState
|
||||
import ir.amirab.downloader.monitor.remainingOrNull
|
||||
import ir.amirab.downloader.monitor.speedOrNull
|
||||
import ir.amirab.downloader.monitor.statusOrFinished
|
||||
import ir.amirab.util.compose.StringSource
|
||||
import ir.amirab.util.compose.asStringSource
|
||||
import kotlinx.coroutines.delay
|
||||
@ -312,7 +308,7 @@ sealed interface DownloadListCells : TableCell<IDownloadItemState> {
|
||||
|
||||
data object Name : DownloadListCells,
|
||||
SortableCell<IDownloadItemState> {
|
||||
override fun sortBy(item: IDownloadItemState): Comparable<*> = item.name
|
||||
override fun comparator(): Comparator<IDownloadItemState> = compareBy { it.name }
|
||||
|
||||
override val id: String = "Name"
|
||||
override val name: StringSource = Res.string.name.asStringSource()
|
||||
@ -321,7 +317,16 @@ sealed interface DownloadListCells : TableCell<IDownloadItemState> {
|
||||
|
||||
data object Status : DownloadListCells,
|
||||
SortableCell<IDownloadItemState> {
|
||||
override fun sortBy(item: IDownloadItemState): Comparable<*> = item.statusOrFinished().order
|
||||
override fun comparator(): Comparator<IDownloadItemState> = compareBy(
|
||||
{
|
||||
it.statusOrFinished().order
|
||||
}, {
|
||||
when (it) {
|
||||
is CompletedDownloadItemState -> 100
|
||||
is ProcessingDownloadItemState -> it.percent ?: 0
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
override val id: String = "Status"
|
||||
override val name: StringSource = Res.string.status.asStringSource()
|
||||
@ -330,7 +335,7 @@ sealed interface DownloadListCells : TableCell<IDownloadItemState> {
|
||||
|
||||
data object Size : DownloadListCells,
|
||||
SortableCell<IDownloadItemState> {
|
||||
override fun sortBy(item: IDownloadItemState): Comparable<*> = item.contentLength
|
||||
override fun comparator(): Comparator<IDownloadItemState> = compareBy { it.contentLength }
|
||||
|
||||
override val id: String = "Size"
|
||||
override val name: StringSource = Res.string.size.asStringSource()
|
||||
@ -339,7 +344,7 @@ sealed interface DownloadListCells : TableCell<IDownloadItemState> {
|
||||
|
||||
data object Speed : DownloadListCells,
|
||||
SortableCell<IDownloadItemState> {
|
||||
override fun sortBy(item: IDownloadItemState): Comparable<*> = item.speedOrNull() ?: 0L
|
||||
override fun comparator(): Comparator<IDownloadItemState> = compareBy { it.speedOrNull() ?: 0L }
|
||||
|
||||
override val id: String = "Speed"
|
||||
override val name: StringSource = Res.string.speed.asStringSource()
|
||||
@ -348,7 +353,7 @@ sealed interface DownloadListCells : TableCell<IDownloadItemState> {
|
||||
|
||||
data object TimeLeft : DownloadListCells,
|
||||
SortableCell<IDownloadItemState> {
|
||||
override fun sortBy(item: IDownloadItemState): Comparable<*> = item.remainingOrNull() ?: Long.MAX_VALUE
|
||||
override fun comparator(): Comparator<IDownloadItemState> = compareBy { it.remainingOrNull() ?: Long.MAX_VALUE }
|
||||
|
||||
override val id: String = "Time Left"
|
||||
override val name: StringSource = Res.string.time_left.asStringSource()
|
||||
@ -357,7 +362,7 @@ sealed interface DownloadListCells : TableCell<IDownloadItemState> {
|
||||
|
||||
data object DateAdded : DownloadListCells,
|
||||
SortableCell<IDownloadItemState> {
|
||||
override fun sortBy(item: IDownloadItemState): Comparable<*> = item.dateAdded
|
||||
override fun comparator(): Comparator<IDownloadItemState> = compareBy { it.dateAdded }
|
||||
|
||||
override val id: String = "Date Added"
|
||||
override val name: StringSource = Res.string.date_added.asStringSource()
|
||||
|
@ -66,7 +66,7 @@ interface CustomCellRenderer {
|
||||
}
|
||||
|
||||
interface SortableCell<Item> : TableCell<Item> {
|
||||
fun sortBy(item: Item): Comparable<*>
|
||||
fun comparator(): Comparator<Item>
|
||||
}
|
||||
|
||||
|
||||
@ -368,7 +368,7 @@ class TableState<Item, Cell : TableCell<Item>>(
|
||||
list
|
||||
} else {
|
||||
list.sortedWith(
|
||||
compareBy(sortedBy.cell::sortBy)
|
||||
sortedBy.cell.comparator()
|
||||
.let {
|
||||
if (sortedBy.isUp()) {
|
||||
it.reversed()
|
||||
|
Loading…
x
Reference in New Issue
Block a user