music: fix crash when adding music dirs

Fix a crash that would occur when trying to add music dirs without a
file manager to handle it.

Some users apparently disable the built-in file manager under the
assumption that the same intents will work with other file managers.
They do not, and so we need to handle that case and let the user know.
This commit is contained in:
Alexander Capehart
2023-01-04 08:17:34 -07:00
parent 3e33510139
commit d5941aa705
5 changed files with 21 additions and 10 deletions
@@ -173,8 +173,8 @@ class DetailViewModel(application: Application) :
}
/**
* Set a new [currentSong] from it's [Music.UID]. If the [Music.UID] differs, [currentSong]
* and [songProperties] will be updated to align with the new [Song].
* Set a new [currentSong] from it's [Music.UID]. If the [Music.UID] differs, [currentSong] and
* [songProperties] will be updated to align with the new [Song].
* @param uid The UID of the [Song] to load. Must be valid.
*/
fun setSongUid(uid: Music.UID) {
@@ -140,8 +140,7 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
min.resolveDate(context)
}
override fun equals(other: Any?) =
other is Range && min == other.min && max == other.max
override fun equals(other: Any?) = other is Range && min == other.min && max == other.max
override fun hashCode() = 31 * max.hashCode() + min.hashCode()
@@ -17,6 +17,7 @@
package org.oxycblt.auxio.music.filesystem
import android.content.ActivityNotFoundException
import android.net.Uri
import android.os.Bundle
import android.os.storage.StorageManager
@@ -84,10 +85,16 @@ class MusicDirsDialog :
val dialog = it as AlertDialog
dialog.getButton(AlertDialog.BUTTON_NEUTRAL)?.setOnClickListener {
logD("Opening launcher")
requireNotNull(openDocumentTreeLauncher) {
"Document tree launcher was not available"
}
.launch(null)
val launcher = requireNotNull(openDocumentTreeLauncher) {
"Document tree launcher was not available"
}
try {
launcher.launch(null)
} catch (e: ActivityNotFoundException) {
// User doesn't have a capable file manager.
requireContext().showToast(R.string.err_no_app)
}
}
}
@@ -97,7 +104,6 @@ class MusicDirsDialog :
}
var dirs = Settings(context).getMusicDirs(storageManager)
if (savedInstanceState != null) {
val pendingDirs = savedInstanceState.getStringArrayList(KEY_PENDING_DIRS)
if (pendingDirs != null) {
@@ -191,7 +191,7 @@ class ReplayGainAudioProcessor(private val context: Context) :
// Opus has it's own "r128_*_gain" ReplayGain specification, which requires dividing the
// adjustment by 256 to get the gain. This is used alongside the base adjustment
// intrinsic to the format to create the normalized adjustment. That base adjustment
// is already handled by the media framework, so we just need to apply the more
// is already handled by the media framework, so we just need to apply the more
// specific adjustments.
tags.vorbis[TAG_R128_TRACK_GAIN]
?.run { first().parseReplayGainAdjustment() }