all: general cleanup

A bunch of changes that accumulated that I'm too lazy to split into
good commits.
This commit is contained in:
OxygenCobalt 2022-06-22 18:38:57 -06:00
parent 630950ea5d
commit 3fcd7e1a63
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
21 changed files with 90 additions and 80 deletions

View file

@ -56,7 +56,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3"
// --- SUPPORT ---

View file

@ -55,11 +55,19 @@ val Long.audioUri: Uri
val Long.albumCoverUri: Uri
get() = ContentUris.withAppendedId(EXTERNAL_ALBUM_ART_URI, this)
/**
* Parse out the number field from a field assumed to be NN, where NN is a track number. This is
* most commonly found on vorbis comments. Values of zero will be ignored under the assumption that
* they are invalid.
*/
val String.trackNo: Int?
get() = toIntOrNull()?.let { if (it > 0) it else null }
/**
* Parse out the number field from an NN/TT string that is typically found in DISC_NUMBER and
* CD_TRACK_NUMBER. Values of zero will be ignored under the assumption that they are invalid.
*/
val String.no: Int?
val String.trackDiscNo: Int?
get() = split('/', limit = 2)[0].toIntOrNull()?.let { if (it > 0) it else null }
/**

View file

@ -32,8 +32,13 @@ import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.lazyReflectedMethod
import org.oxycblt.auxio.util.logEOrThrow
/** A path to a file. [name] is the stripped file name, [parent] is the parent path. */
data class Path(val name: String, val parent: Directory)
/**
* A path to a directory. [volume] is the volume the directory resides in, and [relativePath] is the
* path from the volume's root to the directory itself.
*/
data class Directory(val volume: StorageVolume, val relativePath: String) {
init {
if (relativePath.startsWith(File.separatorChar) ||

View file

@ -29,7 +29,8 @@ import org.oxycblt.auxio.music.Song
import org.oxycblt.auxio.music.audioUri
import org.oxycblt.auxio.music.id3GenreName
import org.oxycblt.auxio.music.iso8601year
import org.oxycblt.auxio.music.no
import org.oxycblt.auxio.music.trackDiscNo
import org.oxycblt.auxio.music.trackNo
import org.oxycblt.auxio.music.year
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.logW
@ -153,7 +154,9 @@ class Task(context: Context, private val audio: MediaStoreBackend.Audio) {
return audio.toSong()
}
// Populate the format mime type if we have one.
format.sampleMimeType?.let { audio.formatMimeType = it }
val metadata = format.metadata
if (metadata != null) {
completeAudio(metadata)
@ -209,13 +212,13 @@ class Task(context: Context, private val audio: MediaStoreBackend.Audio) {
tags["TIT2"]?.let { audio.title = it }
// Track, as NN/TT
tags["TRCK"]?.no?.let { audio.track = it }
tags["TRCK"]?.trackDiscNo?.let { audio.track = it }
// Disc, as NN/TT
tags["TPOS"]?.no?.let { audio.disc = it }
tags["TPOS"]?.trackDiscNo?.let { audio.disc = it }
// Dates are somewhat complicated, as not only did their semantics change from a flat year
// value in ID3v2.3 to a full ISO-8601 date in ID3v2.4, but there are also a variety of
// value in ID3v2.3 to a full ISO-8601 date in ID3v2.4, but there are also a variety of
// date types.
// Our hierarchy for dates is as such:
// 1. ID3v2.4 Original Date, as it resolves the "Released in X, Remastered in Y" issue
@ -223,11 +226,9 @@ class Task(context: Context, private val audio: MediaStoreBackend.Audio) {
// 3. ID3v2.4 Release Date, as it is the second most common date type
// 4. ID3v2.3 Original Date, as it is like #1
// 5. ID3v2.3 Release Year, as it is the most common date type
tags["TYER"]?.year?.let { audio.year = it }
tags["TORY"]?.year?.let { audio.year = it }
tags["TDRL"]?.iso8601year?.let { audio.year = it }
tags["TDRC"]?.iso8601year?.let { audio.year = it }
tags["TDOR"]?.iso8601year?.let { audio.year = it }
audio.year
?: tags["TDOR"]?.iso8601year ?: tags["TDRC"]?.iso8601year ?: tags["TDRL"]?.iso8601year
?: tags["TORY"]?.year ?: tags["TYER"]?.year
// Album
tags["TALB"]?.let { audio.album = it }
@ -246,11 +247,11 @@ class Task(context: Context, private val audio: MediaStoreBackend.Audio) {
// Title
tags["TITLE"]?.let { audio.title = it }
// Track, might be NN/TT, most often though TOTALTRACKS handles T.
tags["TRACKNUMBER"]?.no?.let { audio.track = it }
// Track. Probably not NN/TT, as TOTALTRACKS handles totals.
tags["TRACKNUMBER"]?.trackNo?.let { audio.track = it }
// Disc, might be NN/TT, most often though TOTALDISCS handles T.
tags["DISCNUMBER"]?.no?.let { audio.disc = it }
// Disc. Probably not NN/TT, as TOTALDISCS handles totals.
tags["DISCNUMBER"]?.trackNo?.let { audio.disc = it }
// Vorbis dates are less complicated, but there are still several types
// Our hierarchy for dates is as such:
@ -258,9 +259,8 @@ class Task(context: Context, private val audio: MediaStoreBackend.Audio) {
// 2. Date, as it is the most common date type
// 3. Year, as old vorbis tags tended to use this (I know this because it's the only
// tag that android supports, so it must be 15 years old or more!)
tags["YEAR"]?.year?.let { audio.year = it }
tags["DATE"]?.iso8601year?.let { audio.year = it }
tags["ORIGINALDATE"]?.iso8601year?.let { audio.year = it }
audio.year =
tags["ORIGINALDATE"]?.iso8601year ?: tags["DATE"]?.iso8601year ?: tags["YEAR"]?.year
// Album
tags["ALBUM"]?.let { audio.album = it }
@ -271,8 +271,7 @@ class Task(context: Context, private val audio: MediaStoreBackend.Audio) {
// Album artist. This actually comes into two flavors:
// 1. ALBUMARTIST, which is the most common
// 2. ALBUM ARTIST, which is present on older vorbis tags
tags["ALBUM ARTIST"]?.let { audio.albumArtist = it }
tags["ALBUMARTIST"]?.let { audio.albumArtist = it }
audio.albumArtist = tags["ALBUMARTIST"] ?: tags["ALBUM ARTIST"]
// Genre, no ID3 rules here
tags["GENRE"]?.let { audio.genre = it }

View file

@ -37,9 +37,9 @@ import org.oxycblt.auxio.music.audioUri
import org.oxycblt.auxio.music.directoryCompat
import org.oxycblt.auxio.music.id3GenreName
import org.oxycblt.auxio.music.mediaStoreVolumeNameCompat
import org.oxycblt.auxio.music.no
import org.oxycblt.auxio.music.queryCursor
import org.oxycblt.auxio.music.storageVolumesCompat
import org.oxycblt.auxio.music.trackDiscNo
import org.oxycblt.auxio.music.useQuery
import org.oxycblt.auxio.settings.Settings
import org.oxycblt.auxio.util.contentResolverSafe
@ -72,8 +72,8 @@ import org.oxycblt.auxio.util.logD
* the metadata parser has a brain aneurysm the moment it stumbles upon a dreaded TRDC or DATE tag.
* Once again, this is because internally android uses an ancient in-house metadata parser to get
* everything indexed, and so far they have not bothered to modernize this parser or even switch it
* to something more powerful like Taglib, not even in Android 12. ID3v2.4 has been around for *21
* years.* *It can drink now.* All of my what.
* to something that actually works, not even in Android 12. ID3v2.4 has been around for *21
* years.* *It can drink now.*
*
* Not to mention all the other infuriating quirks. Album artists can't be accessed from the albums
* table, so we have to go for the less efficient "make a big query on all the songs lol" method so
@ -489,8 +489,7 @@ open class VolumeAwareMediaStoreBackend : MediaStoreBackend() {
"AND ${MediaStore.Audio.AudioColumns.RELATIVE_PATH} LIKE ?)"
override fun addDirToSelectorArgs(dir: Directory, args: MutableList<String>): Boolean {
// Leverage the volume field when selecting our directories. It's a little too
// expensive to include this alongside the data checks, so we assume that
// Leverage new the volume field when selecting our directories.
args.add(dir.volume.mediaStoreVolumeNameCompat ?: return false)
args.add("${dir.relativePath}%")
return true
@ -508,9 +507,8 @@ open class VolumeAwareMediaStoreBackend : MediaStoreBackend() {
val volumeName = cursor.getString(volumeIndex)
val relativePath = cursor.getString(relativePathIndex)
// We now have access to the volume name, so we try to leverage it instead.
// I have no idea how well this works in practice, but I assume that the fields
// probably exist.
// Find the StorageVolume whose MediaStore name corresponds to this song.
// This is what we use for the Directory.
val volume = volumes.find { it.mediaStoreVolumeNameCompat == volumeName }
if (volume != null) {
audio.dir = Directory(volume, relativePath.removeSuffix(File.separator))
@ -581,8 +579,8 @@ class Api30MediaStoreBackend : VolumeAwareMediaStoreBackend() {
// N is the number and T is the total. Parse the number while leaving out the
// total, as we have no use for it.
cursor.getStringOrNull(trackIndex)?.no?.let { audio.track = it }
cursor.getStringOrNull(discIndex)?.no?.let { audio.disc = it }
cursor.getStringOrNull(trackIndex)?.trackDiscNo?.let { audio.track = it }
cursor.getStringOrNull(discIndex)?.trackDiscNo?.let { audio.disc = it }
return audio
}

View file

@ -30,6 +30,8 @@ import android.widget.FrameLayout
* always be LTR. In Auxio, this applies to most of the playback components. This layout in
* particular overrides the layout direction in a way that will not disrupt how other views are laid
* out.
*
* @author OxygenCobalt
*/
open class NoRtlFrameLayout
@JvmOverloads

View file

@ -37,7 +37,6 @@ class IntListPreferenceDialog : PreferenceDialogFragmentCompat() {
builder.setTitle(listPreference.title)
builder.setPositiveButton(null, null)
builder.setNegativeButton(R.string.lbl_cancel, null)
// TODO: Replace this with an in-house view
builder.setSingleChoiceItems(listPreference.entries, listPreference.getValueIndex()) {
_,
index ->

View file

@ -79,15 +79,15 @@ data class Sort(val mode: Mode, val isAscending: Boolean) {
songs.sortWith(mode.getSongComparator(isAscending))
}
fun albumsInPlace(albums: MutableList<Album>) {
private fun albumsInPlace(albums: MutableList<Album>) {
albums.sortWith(mode.getAlbumComparator(isAscending))
}
fun artistsInPlace(artists: MutableList<Artist>) {
private fun artistsInPlace(artists: MutableList<Artist>) {
artists.sortWith(mode.getArtistComparator(isAscending))
}
fun genresInPlace(genres: MutableList<Genre>) {
private fun genresInPlace(genres: MutableList<Genre>) {
genres.sortWith(mode.getGenreComparator(isAscending))
}

View file

@ -2,10 +2,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorPrimary"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9s9,-4.03 9,-9c0,-0.46 -0.04,-0.92 -0.1,-1.36c-0.98,1.37 -2.58,2.26 -4.4,2.26c-2.98,0 -5.4,-2.42 -5.4,-5.4c0,-1.81 0.89,-3.42 2.26,-4.4C12.92,3.04 12.46,3 12,3L12,3z" />
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M16.5,3c-1.74,0 -3.41,0.81 -4.5,2.09C10.91,3.81 9.24,3 7.5,3 4.42,3 2,5.42 2,8.5c0,3.78 3.4,6.86 8.55,11.54L12,21.35l1.45,-1.32C18.6,15.36 22,12.28 22,8.5 22,5.42 19.58,3 16.5,3zM12.1,18.55l-0.1,0.1 -0.1,-0.1C7.14,14.24 4,11.39 4,8.5 4,6.5 5.5,5 7.5,5c1.54,0 3.04,0.99 3.57,2.36h1.87C13.46,5.99 14.96,5 16.5,5c2,0 3.5,1.5 3.5,3.5 0,2.89 -3.14,5.74 -7.9,10.05z"/>
</vector>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ui_scroll_thumb" />
</selector>

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent" />
</selector>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -41,7 +41,7 @@
android:layout_marginEnd="@dimen/spacing_mid_large"
android:gravity="center"
android:minWidth="@dimen/size_pre_amp_ticker"
android:textAppearance="@style/TextAppearance.Auxio.BodyMedium"
android:textAppearance="@style/TextAppearance.Auxio.LabelMedium"
app:layout_constraintBottom_toBottomOf="@+id/with_tags_slider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/with_tags_slider"
@ -78,7 +78,7 @@
android:layout_marginEnd="@dimen/spacing_mid_large"
android:gravity="center"
android:minWidth="@dimen/size_pre_amp_ticker"
android:textAppearance="@style/TextAppearance.Auxio.BodyMedium"
android:textAppearance="@style/TextAppearance.Auxio.LabelMedium"
app:layout_constraintBottom_toBottomOf="@+id/without_tags_slider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/without_tags_slider"

View file

@ -29,7 +29,7 @@
<dimen name="size_icon_small">24dp</dimen>
<dimen name="size_icon_large">32dp</dimen>
<dimen name="size_pre_amp_ticker">64dp</dimen>
<dimen name="size_pre_amp_ticker">56dp</dimen>
<dimen name="text_size_ext_label_larger">16sp</dimen>
<dimen name="text_size_ext_title_mid_large">18sp</dimen>

View file

@ -106,7 +106,7 @@
<string name="set_replay_gain">ReplayGain</string>
<string name="set_replay_gain_track">Prefer track</string>
<string name="set_replay_gain_album">Prefer album</string>
<string name="set_replay_gain_dynamic">Dynamic</string>
<string name="set_replay_gain_dynamic">Prefer album if one is playing</string>
<string name="set_pre_amp">ReplayGain pre-amp</string>
<string name="set_pre_amp_desc">The pre-amp is applied to the existing adjustment during playback</string>
<string name="set_pre_amp_with">Adjustment with tags</string>
@ -114,8 +114,8 @@
<string name="set_pre_amp_warning">Warning: Changing the pre-amp to a high positive value may result in peaking on some audio tracks.</string>
<string name="set_behavior">Behavior</string>
<string name="set_library_song_playback_mode">Library playback mode</string>
<string name="set_detail_song_playback_mode">Detail playback mode</string>
<string name="set_library_song_playback_mode">When playing from the library</string>
<string name="set_detail_song_playback_mode">When playing from item details</string>
<string name="set_playback_mode_none">Play from shown item</string>
<string name="set_playback_mode_all">Play from all songs</string>
<string name="set_playback_mode_album">Play from album</string>

View file

@ -17,16 +17,16 @@
</style>
<style name="TextAppearance.Auxio.DisplayMedium" parent="TextAppearance.Material3.DisplayMedium">
<item name="fontFamily">@font/inter</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_semibold</item>
<item name="android:textStyle">normal</item>
<item name="android:textStyle">bold</item>
<item name="android:letterSpacing">-0.0192222222</item>
</style>
<style name="TextAppearance.Auxio.DisplaySmall" parent="TextAppearance.Material3.DisplaySmall">
<item name="fontFamily">@font/inter</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_semibold</item>
<item name="android:textStyle">normal</item>
<item name="android:textStyle">bold</item>
<item name="android:letterSpacing">-0.0189444444</item>
</style>
@ -43,14 +43,14 @@
<style name="TextAppearance.Auxio.HeadlineMedium" parent="TextAppearance.Material3.HeadlineMedium">
<item name="fontFamily">@font/inter_semibold</item>
<item name="android:fontFamily">@font/inter_semibold</item>
<item name="android:textStyle">normal</item>
<item name="android:textStyle">bold</item>
<item name="android:letterSpacing">-0.0180714286</item>
</style>
<style name="TextAppearance.Auxio.HeadlineSmall" parent="TextAppearance.Material3.HeadlineSmall">
<item name="fontFamily">@font/inter_semibold</item>
<item name="android:fontFamily">@font/inter_semibold</item>
<item name="android:textStyle">normal</item>
<item name="android:textStyle">bold</item>
<item name="android:letterSpacing">-0.0165833333</item>
</style>
@ -65,15 +65,15 @@
</style>
<style name="TextAppearance.Auxio.TitleMedium" parent="TextAppearance.Material3.TitleMedium">
<item name="fontFamily">@font/inter</item>
<item name="android:fontFamily">@font/inter</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_regular</item>
<item name="android:textStyle">normal</item>
<item name="android:letterSpacing">-0.01125</item>
</style>
<style name="TextAppearance.Auxio.TitleSmall" parent="TextAppearance.Material3.TitleSmall">
<item name="fontFamily">@font/inter</item>
<item name="android:fontFamily">@font/inter</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_regular</item>
<item name="android:textStyle">normal</item>
<item name="android:letterSpacing">0.01</item>
</style>
@ -87,16 +87,16 @@
</style>
<style name="TextAppearance.Auxio.LabelMedium" parent="TextAppearance.Material3.LabelMedium">
<item name="fontFamily">@font/inter</item>
<item name="android:fontFamily">@font/inter</item>
<item name="android:textStyle">bold</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_regular</item>
<item name="android:textStyle">normal</item>
<item name="android:letterSpacing">0.00</item>
</style>
<style name="TextAppearance.Auxio.LabelSmall" parent="TextAppearance.Material3.LabelSmall">
<item name="fontFamily">@font/inter</item>
<item name="android:fontFamily">@font/inter</item>
<item name="android:textStyle">bold</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_regular</item>
<item name="android:textStyle">normal</item>
<item name="android:letterSpacing">0.0045454545</item>
</style>
@ -104,22 +104,22 @@
The body typeface is used for secondary and/or singular UI elements.
-->
<style name="TextAppearance.Auxio.BodyLarge" parent="TextAppearance.Material3.BodyLarge">
<item name="fontFamily">@font/inter</item>
<item name="android:fontFamily">@font/inter</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_regular</item>
<item name="android:textStyle">normal</item>
<item name="android:letterSpacing">-0.01125</item>
</style>
<style name="TextAppearance.Auxio.BodyMedium" parent="TextAppearance.Material3.BodyMedium">
<item name="fontFamily">@font/inter</item>
<item name="android:fontFamily">@font/inter</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_regular</item>
<item name="android:textStyle">normal</item>
<item name="android:letterSpacing">-0.0064285714</item>
</style>
<style name="TextAppearance.Auxio.BodySmall" parent="TextAppearance.Material3.BodySmall">
<item name="fontFamily">@font/inter</item>
<item name="android:fontFamily">@font/inter</item>
<item name="fontFamily">@font/inter_regular</item>
<item name="android:fontFamily">@font/inter_regular</item>
<item name="android:textStyle">normal</item>
<item name="android:letterSpacing">0.0008333333</item>
</style>
@ -133,7 +133,7 @@
<style name="TextAppearance.Auxio.TitleMediumEmphasis" parent="TextAppearance.Material3.TitleMedium">
<item name="fontFamily">@font/inter_semibold</item>
<item name="android:fontFamily">@font/inter_semibold</item>
<item name="android:textStyle">normal</item>
<item name="android:textStyle">bold</item>
<item name="android:letterSpacing">-0.00825</item>
</style>

View file

@ -73,10 +73,6 @@ ExoPlayer, while powerful, does add some overhead when playing exceptionally hig
This results in choppy, distorted playback in some cases as audio data cannot be delivered in time. Sadly, there is
not much I can do about this right now.
#### What is dynamic ReplayGain?
Dynamic ReplayGain is a quirk setting based off the FooBar2000 plugin that dynamically switches from track gain to album
gain depending on if the current playback is from an album or not.
#### Why are accents lighter/less saturated in dark mode?
As per the [Material Design Guidelines](https://material.io/design/color/dark-theme.html), accents should be less
saturated on dark mode to reduce eye strain and to increase visual cohesion.