Skip to content

Commit

Permalink
musikr: clarify added/modified timestamp apis
Browse files Browse the repository at this point in the history
Clearly indicate their new millisecond nature.
  • Loading branch information
OxygenCobalt committed Jan 10, 2025
1 parent c359048 commit ae6a043
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SongListFragment :

// Last added -> Format as date
is Sort.Mode.ByDateAdded -> {
val dateAddedMillis = song.dateAdded.secsToMs()
val dateAddedMillis = song.addedMs.secsToMs()
formatterSb.setLength(0)
DateUtils.formatDateRange(
context,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/oxycblt/auxio/list/sort/Sort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ data class Sort(val mode: Mode, val direction: Direction) {
override fun sortSongs(songs: MutableList<Song>, direction: Direction) {
songs.sortBy { it.name }
when (direction) {
Direction.ASCENDING -> songs.sortBy { it.dateAdded }
Direction.DESCENDING -> songs.sortByDescending { it.dateAdded }
Direction.ASCENDING -> songs.sortBy { it.addedMs }
Direction.DESCENDING -> songs.sortByDescending { it.addedMs }
}
}

Expand Down
11 changes: 7 additions & 4 deletions musikr/src/main/java/org/oxycblt/musikr/Music.kt
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ interface Song : Music {
val sampleRateHz: Int
/** The ReplayGain adjustment to apply during playback. */
val replayGainAdjustment: ReplayGainAdjustment
/** The date last modified the audio file was last modified, as a unix epoch timestamp. */
val lastModified: Long
/** The date the audio file was added to the device, as a unix epoch timestamp. */
val dateAdded: Long
/**
* The date last modified the audio file was last modified, in milliseconds since the unix
* epoch.
*/
val modifiedMs: Long
/** The time the audio file was added to the device, in milliseconds since the unix epoch. */
val addedMs: Long
/** Useful information to quickly obtain the album cover. */
val cover: Cover?
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ internal data class CachedSong(
fun fromRawSong(rawSong: RawSong) =
CachedSong(
uri = rawSong.file.uri.toString(),
modifiedMs = rawSong.file.lastModified,
modifiedMs = rawSong.file.modifiedMs,
addedMs = rawSong.addedMs,
// Should be strictly monotonic so we don't prune this
// by accident later.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private class VisibleStoredCache(private val visibleDao: VisibleCacheDao, writeD
BaseStoredCache(writeDao) {
override suspend fun read(file: DeviceFile, covers: Covers): CacheResult {
val song = visibleDao.selectSong(file.uri.toString()) ?: return CacheResult.Miss(file, null)
if (song.modifiedMs != file.lastModified) {
if (song.modifiedMs != file.modifiedMs) {
// We *found* this file earlier, but it's out of date.
// Send back it with the timestamp so it will be re-used.
// The touch timestamp will be updated on write.
Expand Down
2 changes: 1 addition & 1 deletion musikr/src/main/java/org/oxycblt/musikr/fs/DeviceFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ internal data class DeviceFile(
val mimeType: String,
val path: Path,
val size: Long,
val lastModified: Long
val modifiedMs: Long
)
2 changes: 1 addition & 1 deletion musikr/src/main/java/org/oxycblt/musikr/model/AlbumImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AlbumImpl internal constructor(private val core: AlbumCore) : Album {
override val name = preAlbum.name
override val releaseType = preAlbum.releaseType
override val durationMs = core.songs.sumOf { it.durationMs }
override val dateAdded = core.songs.minOf { it.dateAdded }
override val dateAdded = core.songs.minOf { it.addedMs }
override val covers = CoverCollection.from(core.songs.mapNotNull { it.cover })
override val dates: Date.Range? =
core.songs.mapNotNull { it.date }.ifEmpty { null }?.run { Date.Range(min(), max()) }
Expand Down
4 changes: 2 additions & 2 deletions musikr/src/main/java/org/oxycblt/musikr/model/SongImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ internal class SongImpl(private val handle: SongCore) : Song {
override val bitrateKbps = preSong.bitrateKbps
override val sampleRateHz = preSong.sampleRateHz
override val replayGainAdjustment = preSong.replayGainAdjustment
override val lastModified = preSong.lastModified
override val dateAdded = preSong.dateAdded
override val modifiedMs = preSong.modifiedMs
override val addedMs = preSong.addedMs
override val cover = preSong.cover
override val album: Album
get() = handle.resolveAlbum()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ internal data class PreSong(
val bitrateKbps: Int,
val sampleRateHz: Int,
val replayGainAdjustment: ReplayGainAdjustment,
val lastModified: Long,
val dateAdded: Long,
val modifiedMs: Long,
val addedMs: Long,
val cover: Cover?,
val preAlbum: PreAlbum,
val preArtists: List<PreArtist>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ private class TagInterpreterImpl(private val interpretation: Interpretation) : T
path = song.file.path,
size = song.file.size,
format = Format.infer(song.file.mimeType, song.properties.mimeType),
lastModified = song.file.lastModified,
dateAdded = song.addedMs,
modifiedMs = song.file.modifiedMs,
addedMs = song.addedMs,
musicBrainzId = song.tags.musicBrainzId?.toUuidOrNull(),
name = interpretation.naming.name(song.tags.name, song.tags.sortName),
rawName = song.tags.name,
Expand Down

0 comments on commit ae6a043

Please sign in to comment.