music: remove redundant null checks

Remove more redundant null checks in MediaStoreBackend.

Again, no need to check if there is no issue where they might be null.
This commit is contained in:
OxygenCobalt 2022-06-22 09:05:22 -06:00
parent 316a0e719c
commit 86010e896e
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 9 additions and 19 deletions

View file

@ -276,7 +276,7 @@ abstract class MediaStoreBackend : Indexer.Backend {
// to null if they are not present. If this field is <unknown>, null it so that
// it's easier to handle later.
audio.artist =
cursor.getStringOrNull(artistIndex)?.run {
cursor.getString(artistIndex).run {
if (this != MediaStore.UNKNOWN_STRING) {
this
} else {
@ -505,20 +505,15 @@ open class VolumeAwareMediaStoreBackend : MediaStoreBackend() {
cursor.getColumnIndexOrThrow(MediaStore.Audio.AudioColumns.RELATIVE_PATH)
}
val volumeName = cursor.getStringOrNull(volumeIndex)
val relativePath = cursor.getStringOrNull(relativePathIndex)
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.
// TODO: Remove redundant null checks for fields you are pretty sure are not null.
if (volumeName != null && relativePath != null) {
// Iterating through the volume list is cheaper than creating a map,
// interestingly enough.
val volume = volumes.find { it.mediaStoreVolumeNameCompat == volumeName }
if (volume != null) {
audio.dir = Directory(volume, relativePath.removeSuffix(File.separator))
}
val volume = volumes.find { it.mediaStoreVolumeNameCompat == volumeName }
if (volume != null) {
audio.dir = Directory(volume, relativePath.removeSuffix(File.separator))
}
return audio

View file

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight"
android:radius="20dp" />

View file

@ -25,7 +25,7 @@
android:layout_gravity="bottom|start"
android:layout_marginStart="@dimen/spacing_medium"
android:layout_marginBottom="@dimen/spacing_tiny"
android:textAppearance="@style/TextAppearance.Auxio.BodyMedium"
android:textAppearance="@style/TextAppearance.Auxio.LabelMedium"
android:textColor="@color/sel_accented_secondary"
tools:text="11:38" />
@ -36,7 +36,7 @@
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/spacing_medium"
android:layout_marginBottom="@dimen/spacing_tiny"
android:textAppearance="@style/TextAppearance.Auxio.BodyMedium"
android:textAppearance="@style/TextAppearance.Auxio.LabelMedium"
android:textColor="?android:attr/textColorSecondary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/playback_seek_bar"

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Auxio.Button.AppWidget.V31" parent="Widget.AppCompat.Button.Borderless">
<item name="android:background">@drawable/ui_large_unbounded_ripple</item>
<item name="android:background">@drawable/ui_remote_ripple</item>
</style>
</resources>