mirror of
https://github.com/Boof2015/astra-mobile.git
synced 2026-08-19 20:20:18 +02:00
fix slider not working correctly
This commit is contained in:
+22
-24
@@ -117,6 +117,7 @@ class AstraLibraryRepository private constructor(
|
||||
val catalogOpen = openCatalogDatabaseWithRecovery()
|
||||
catalogDatabase = catalogOpen
|
||||
val dao = catalogOpen.catalogDao()
|
||||
val existingMeta = dao.getMeta()
|
||||
dao.insertMeta(
|
||||
CatalogMetaEntity(
|
||||
revision = 0,
|
||||
@@ -124,6 +125,9 @@ class AstraLibraryRepository private constructor(
|
||||
updatedAt = System.currentTimeMillis(),
|
||||
),
|
||||
)
|
||||
if (existingMeta != null && existingMeta.collationVersion < COLLATION_VERSION) {
|
||||
dao.migrateSectionLabels(COLLATION_VERSION, System.currentTimeMillis())
|
||||
}
|
||||
dao.discardAbandonedGenerations()
|
||||
reconcileUserFacts()
|
||||
|
||||
@@ -2048,7 +2052,7 @@ class AstraLibraryRepository private constructor(
|
||||
"albums" -> {
|
||||
val rows = dao.getAllAlbumSummaries(revision).filter { includeSingles || !it.isSingle }
|
||||
rows.groupBy { row ->
|
||||
if (sort == "artist") SortKeys.sectionLabel(row.artist) else row.sectionLabel
|
||||
if (sort == "artist") SortKeys.sectionLabel(row.artist) else SortKeys.sectionLabel(row.album)
|
||||
}.map { (label, section) ->
|
||||
if (sort == "artist") {
|
||||
val first = section.minWith(compareBy<AlbumSummaryEntity>({ it.artistSortKey }, { it.nameSortKey }, { it.identityKey }))
|
||||
@@ -2071,7 +2075,7 @@ class AstraLibraryRepository private constructor(
|
||||
val mode = if (groupingMode == "fileTags") "fileTags" else "astra"
|
||||
dao.getAllArtistSummaries(revision, mode)
|
||||
.filter { includeCollaborations || !it.isCollaboration }
|
||||
.groupBy(ArtistSummaryEntity::sectionLabel)
|
||||
.groupBy { row -> SortKeys.sectionLabel(row.artist) }
|
||||
.map { (label, section) ->
|
||||
val first = section.minWith(compareBy<ArtistSummaryEntity>({ it.nameSortKey }, { it.artistKey }))
|
||||
label to TrackPageCursor(
|
||||
@@ -2082,31 +2086,25 @@ class AstraLibraryRepository private constructor(
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
dao.getAllActiveTracksForNativeMatching()
|
||||
.groupBy { row ->
|
||||
if (sort == "artist") SortKeys.sectionLabel(row.artist) else row.sectionLabel
|
||||
}
|
||||
.map { (label, section) ->
|
||||
val first = if (sort == "artist") {
|
||||
section.minWith(
|
||||
compareBy<ActiveTrackView>(
|
||||
{ it.artistSortKey },
|
||||
{ it.albumSortKey },
|
||||
{ it.discSort },
|
||||
{ it.trackSort },
|
||||
{ it.titleSortKey },
|
||||
{ it.path },
|
||||
),
|
||||
if (sort == "artist") {
|
||||
dao.getArtistSectionAnchorCandidates()
|
||||
.groupBy { candidate -> SortKeys.sectionLabel(candidate.artist) }
|
||||
.map { (label, section) ->
|
||||
label to TrackPageCursor(
|
||||
revision,
|
||||
"tracks:artist",
|
||||
text1 = section.minOf(ArtistSectionAnchorCandidate::sortKey),
|
||||
)
|
||||
} else {
|
||||
section.minWith(compareBy<ActiveTrackView>({ it.titleSortKey }, { it.path }))
|
||||
}
|
||||
label to if (sort == "artist") {
|
||||
TrackPageCursor(revision, "tracks:artist", text1 = first.artistSortKey)
|
||||
} else {
|
||||
TrackPageCursor(revision, "tracks:title", text1 = first.titleSortKey)
|
||||
}
|
||||
} else {
|
||||
dao.getTitleSectionAnchors().map { row ->
|
||||
row.sectionLabel to TrackPageCursor(
|
||||
revision,
|
||||
"tracks:title",
|
||||
text1 = row.sortKey,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
anchors.sortedWith(compareBy<Pair<String, TrackPageCursor>> { it.second.text1 }.thenBy { it.first })
|
||||
|
||||
+57
-3
@@ -22,6 +22,17 @@ data class SectionAnchorRow(
|
||||
@androidx.room.ColumnInfo(name = "sort_key") val sortKey: String,
|
||||
)
|
||||
|
||||
data class ArtistSectionAnchorCandidate(
|
||||
val artist: String,
|
||||
@androidx.room.ColumnInfo(name = "sort_key") val sortKey: String,
|
||||
)
|
||||
|
||||
data class TrackSectionLabelCandidate(
|
||||
val id: Long,
|
||||
val title: String,
|
||||
@androidx.room.ColumnInfo(name = "section_label") val sectionLabel: String,
|
||||
)
|
||||
|
||||
data class LibraryLoudnessStatsRow(
|
||||
val lufsCount: Long,
|
||||
val medianLufs: Double?,
|
||||
@@ -50,6 +61,16 @@ interface CatalogDao {
|
||||
@Query("SELECT revision FROM catalog_meta WHERE id = 1")
|
||||
suspend fun getRevision(): Long
|
||||
|
||||
@Query(
|
||||
"""
|
||||
UPDATE catalog_meta
|
||||
SET collation_version = :version,
|
||||
updated_at = :updatedAt
|
||||
WHERE id = 1
|
||||
""",
|
||||
)
|
||||
suspend fun setCollationVersion(version: Int, updatedAt: Long)
|
||||
|
||||
@Query("SELECT * FROM catalog_sources WHERE source_key = :sourceKey")
|
||||
suspend fun getSource(sourceKey: String): CatalogSourceEntity?
|
||||
|
||||
@@ -471,13 +492,30 @@ interface CatalogDao {
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT section_label, MIN(artist_sort_key) AS sort_key
|
||||
SELECT artist, MIN(artist_sort_key) AS sort_key
|
||||
FROM active_tracks
|
||||
GROUP BY section_label
|
||||
GROUP BY artist
|
||||
ORDER BY sort_key
|
||||
""",
|
||||
)
|
||||
suspend fun getArtistSectionAnchors(): List<SectionAnchorRow>
|
||||
suspend fun getArtistSectionAnchorCandidates(): List<ArtistSectionAnchorCandidate>
|
||||
|
||||
@Query(
|
||||
"""
|
||||
SELECT id, title, section_label
|
||||
FROM tracks
|
||||
WHERE id > :afterId
|
||||
ORDER BY id
|
||||
LIMIT :limit
|
||||
""",
|
||||
)
|
||||
suspend fun getTrackSectionLabelCandidates(
|
||||
afterId: Long,
|
||||
limit: Int,
|
||||
): List<TrackSectionLabelCandidate>
|
||||
|
||||
@Query("UPDATE tracks SET section_label = :sectionLabel WHERE id = :trackId")
|
||||
suspend fun updateTrackSectionLabel(trackId: Long, sectionLabel: String)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun putAlbumSummaries(rows: List<AlbumSummaryEntity>)
|
||||
@@ -1027,6 +1065,22 @@ interface CatalogDao {
|
||||
deleteAbandonedGenerationRecords()
|
||||
}
|
||||
|
||||
@Transaction
|
||||
suspend fun migrateSectionLabels(version: Int, updatedAt: Long) {
|
||||
var afterId = 0L
|
||||
do {
|
||||
val rows = getTrackSectionLabelCandidates(afterId, 1_000)
|
||||
for (row in rows) {
|
||||
val corrected = SortKeys.sectionLabel(row.title)
|
||||
if (corrected != row.sectionLabel) {
|
||||
updateTrackSectionLabel(row.id, corrected)
|
||||
}
|
||||
}
|
||||
afterId = rows.lastOrNull()?.id ?: afterId
|
||||
} while (rows.size == 1_000)
|
||||
setCollationVersion(version, updatedAt)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
suspend fun publishGeneration(
|
||||
sourceKey: String,
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ import java.util.Locale
|
||||
import org.json.JSONObject
|
||||
import org.json.JSONArray
|
||||
|
||||
const val COLLATION_VERSION = 1
|
||||
const val COLLATION_VERSION = 2
|
||||
const val DEFAULT_PAGE_SIZE = 100
|
||||
const val MAX_PAGE_SIZE = 200
|
||||
|
||||
@@ -59,9 +59,9 @@ object SortKeys {
|
||||
|
||||
fun sectionLabel(value: String): String {
|
||||
val normalized = Normalizer.normalize(value.trim(), Normalizer.Form.NFD)
|
||||
val first = normalized.firstOrNull { Character.isLetterOrDigit(it) } ?: return "#"
|
||||
val first = normalized.firstOrNull() ?: return "#"
|
||||
val upper = first.uppercaseChar()
|
||||
return if (upper in 'A'..'Z' || upper in '0'..'9') upper.toString() else "#"
|
||||
return if (upper in 'A'..'Z') upper.toString() else "#"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user