From d5941aa7058511fa8b4b461cc44a62eb5622c72e Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Wed, 4 Jan 2023 08:15:21 -0700 Subject: [PATCH] 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. --- CHANGELOG.md | 6 ++++++ .../org/oxycblt/auxio/detail/DetailViewModel.kt | 4 ++-- .../main/java/org/oxycblt/auxio/music/Date.kt | 3 +-- .../auxio/music/filesystem/MusicDirsDialog.kt | 16 +++++++++++----- .../replaygain/ReplayGainAudioProcessor.kt | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0d47c38f..f14fdece8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## dev + +#### What's Fixed +- Fixed crash that would occur in music folders dialog when user does not have a working +file manager + ## 3.0.1 #### What's New diff --git a/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt b/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt index 2f7a404e0..71ec1a6a8 100644 --- a/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/detail/DetailViewModel.kt @@ -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) { diff --git a/app/src/main/java/org/oxycblt/auxio/music/Date.kt b/app/src/main/java/org/oxycblt/auxio/music/Date.kt index f6f7b1221..2e05ef5a4 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/Date.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/Date.kt @@ -140,8 +140,7 @@ class Date private constructor(private val tokens: List) : Comparable 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() diff --git a/app/src/main/java/org/oxycblt/auxio/music/filesystem/MusicDirsDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/filesystem/MusicDirsDialog.kt index 441cb7cbe..e294b7915 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/filesystem/MusicDirsDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/filesystem/MusicDirsDialog.kt @@ -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) { diff --git a/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt index 98450a763..7346ac7eb 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/replaygain/ReplayGainAudioProcessor.kt @@ -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() }