Skip to content

Commit

Permalink
app: local: Sort songs and folders
Browse files Browse the repository at this point in the history
* We sort in UI instead of view model as the directory trees have their own nuances and I do not feel like
   torturing myself with database gymnastics today
* Song folders are only sortable by name
  • Loading branch information
mikooomich committed Jun 13, 2024
1 parent 069f880 commit 33b9848
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.dd3boh.outertune.utils.rememberEnumPreference
import com.dd3boh.outertune.utils.rememberPreference
import com.dd3boh.outertune.viewmodels.LibrarySongsViewModel
import com.dd3boh.outertune.ui.utils.ItemWrapper
import java.time.ZoneOffset
import java.util.Stack

@SuppressLint("StateFlowValueCalledInComposition")
Expand Down Expand Up @@ -108,6 +109,27 @@ fun LibrarySongsFolderScreen(
}

val wrappedSongs = currDir.files.map { item -> ItemWrapper(item) }.toMutableList()

// sort songs
wrappedSongs.sortBy {
when (sortType) {
SongSortType.CREATE_DATE -> it.item.song.inLibrary?.toEpochSecond(ZoneOffset.UTC).toString()
SongSortType.NAME -> it.item.song.title
SongSortType.ARTIST -> it.item.artists.firstOrNull()?.name
SongSortType.PLAY_TIME -> it.item.song.totalPlayTime.toString()
}
}
if (sortDescending) {
wrappedSongs.reverse()
}

// sort folders
currDir.subdirs.sortBy { it.currentDir } // only sort by name

if (sortDescending) {
currDir.subdirs.reverse()
}

var selection by remember {
mutableStateOf(false)
}
Expand Down

0 comments on commit 33b9848

Please sign in to comment.