From affe5c482ba506fef05853e640cb76818c431883 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Fri, 30 Dec 2022 11:06:15 -0700 Subject: [PATCH] all: reformat code --- CHANGELOG.md | 2 +- app/build.gradle | 4 ++++ .../java/org/oxycblt/auxio/MainFragment.kt | 1 - .../org/oxycblt/auxio/home/HomeFragment.kt | 2 +- .../oxycblt/auxio/image/extractor/Covers.kt | 4 +++- .../auxio/music/extractor/CacheExtractor.kt | 3 +-- .../auxio/music/extractor/ParsingUtil.kt | 21 +++++++++--------- .../auxio/music/extractor/SeparatorsDialog.kt | 19 ++++++++-------- .../auxio/music/picker/GenreChoiceAdapter.kt | 17 ++++++++++++++ .../music/picker/GenrePlaybackPickerDialog.kt | 22 +++++++++++++++++-- .../auxio/music/picker/PickerViewModel.kt | 4 ++-- .../oxycblt/auxio/music/storage/Storage.kt | 2 -- .../auxio/playback/PlaybackViewModel.kt | 8 +++---- .../org/oxycblt/auxio/settings/Settings.kt | 4 +--- .../oxycblt/auxio/ui/NavigationViewModel.kt | 8 +++---- .../org/oxycblt/auxio/widgets/WidgetUtil.kt | 4 ++-- prebuild.py | 2 +- 17 files changed, 82 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a94d5e349..d4d5ba5f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - Added setting to hide "collaborator" artists - Upgraded music ID management: - Added support for MusicBrainz IDs (MBIDs) - - Use the more unique MD5 hash of metadata when MBIDs can't be used + - Use a more unique hash of metadata when MBIDs can't be used - Genres now display a list of artists - Added toggle to load non-music (Such as podcasts) - Music loader now caches parsed metadata for faster load times diff --git a/app/build.gradle b/app/build.gradle index ef8f54ab5..ddeeaeb23 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -121,3 +121,7 @@ spotless { licenseHeaderFile("NOTICE") } } + +afterEvaluate { + preDebugBuild.dependsOn spotlessApply +} diff --git a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt index e66ef86cc..b692ae477 100644 --- a/app/src/main/java/org/oxycblt/auxio/MainFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/MainFragment.kt @@ -37,7 +37,6 @@ import kotlin.math.max import kotlin.math.min import org.oxycblt.auxio.databinding.FragmentMainBinding import org.oxycblt.auxio.list.selection.SelectionViewModel -import org.oxycblt.auxio.music.Artist import org.oxycblt.auxio.music.Music import org.oxycblt.auxio.music.Song import org.oxycblt.auxio.playback.PlaybackBottomSheetBehavior diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt index 3e6795c5a..7c9ace57b 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt @@ -292,7 +292,7 @@ class HomeFragment : // Check the ascending option and corresponding sort option to align with // the current sort of the tab. if (option.itemId == toHighlight.mode.itemId || - (option.itemId == R.id.option_sort_asc && toHighlight.isAscending)) { + (option.itemId == R.id.option_sort_asc && toHighlight.isAscending)) { option.isChecked = true } diff --git a/app/src/main/java/org/oxycblt/auxio/image/extractor/Covers.kt b/app/src/main/java/org/oxycblt/auxio/image/extractor/Covers.kt index 6b703e37f..31a4bda55 100644 --- a/app/src/main/java/org/oxycblt/auxio/image/extractor/Covers.kt +++ b/app/src/main/java/org/oxycblt/auxio/image/extractor/Covers.kt @@ -177,6 +177,8 @@ object Covers { @Suppress("BlockingMethodInNonBlockingContext") private suspend fun fetchMediaStoreCovers(context: Context, album: Album): InputStream? { // Eliminate any chance that this blocking call might mess up the loading process - return withContext(Dispatchers.IO) { context.contentResolver.openInputStream(album.coverUri) } + return withContext(Dispatchers.IO) { + context.contentResolver.openInputStream(album.coverUri) + } } } diff --git a/app/src/main/java/org/oxycblt/auxio/music/extractor/CacheExtractor.kt b/app/src/main/java/org/oxycblt/auxio/music/extractor/CacheExtractor.kt index d5e11713a..e9b391594 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/extractor/CacheExtractor.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/extractor/CacheExtractor.kt @@ -387,8 +387,7 @@ private class CacheDatabase(context: Context) : * @return A list of strings corresponding to the delimited values present within the original * string. Escaped delimiters are converted back into their normal forms. */ - private fun String.parseSQLMultiValue() = - splitEscaped { it == ';' }.correctWhitespace() + private fun String.parseSQLMultiValue() = splitEscaped { it == ';' }.correctWhitespace() /** Defines the columns used in this database. */ private object Columns { diff --git a/app/src/main/java/org/oxycblt/auxio/music/extractor/ParsingUtil.kt b/app/src/main/java/org/oxycblt/auxio/music/extractor/ParsingUtil.kt index 92cbeee1d..29b0ba624 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/extractor/ParsingUtil.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/extractor/ParsingUtil.kt @@ -17,11 +17,9 @@ package org.oxycblt.auxio.music.extractor -import androidx.core.text.isDigitsOnly import java.util.UUID import org.oxycblt.auxio.music.Date import org.oxycblt.auxio.settings.Settings -import org.oxycblt.auxio.util.logD import org.oxycblt.auxio.util.nonZeroOrNull /** @@ -117,8 +115,8 @@ inline fun String.splitEscaped(selector: (Char) -> Boolean): List { /** * Fix trailing whitespace or blank contents in a [String]. - * @return A string with trailing whitespace remove,d or null if the [String] was all whitespace - * or empty. + * @return A string with trailing whitespace remove,d or null if the [String] was all whitespace or + * empty. */ fun String.correctWhitespace() = trim().ifBlank { null } @@ -197,12 +195,15 @@ private fun String.parseId3v1Genre(): String? { // ID3v1 genres are a plain integer value without formatting, so in that case // try to index the genre table with such. If this fails, then try to compare it // to some other hard-coded values. - val numeric = toIntOrNull() ?: return when (this) { - // CR and RX are not technically ID3v1, but are formatted similarly to a plain number. - "CR" -> "Cover" - "RX" -> "Remix" - else -> null - } + val numeric = + toIntOrNull() + ?: return when (this) { + // CR and RX are not technically ID3v1, but are formatted similarly to a plain + // number. + "CR" -> "Cover" + "RX" -> "Remix" + else -> null + } return GENRE_TABLE.getOrNull(numeric) } diff --git a/app/src/main/java/org/oxycblt/auxio/music/extractor/SeparatorsDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/extractor/SeparatorsDialog.kt index c7e2ed55f..12d8eae5d 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/extractor/SeparatorsDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/extractor/SeparatorsDialog.kt @@ -61,16 +61,17 @@ class SeparatorsDialog : ViewBindingDialogFragment() { // More efficient to do one iteration through the separator list and initialize // the corresponding CheckBox for each character instead of doing an iteration // through the separator list for each CheckBox. - (savedInstanceState?.getString(KEY_PENDING_SEPARATORS) ?: settings.musicSeparators)?.forEach { - when (it) { - SEPARATOR_COMMA -> binding.separatorComma.isChecked = true - SEPARATOR_SEMICOLON -> binding.separatorSemicolon.isChecked = true - SEPARATOR_SLASH -> binding.separatorSlash.isChecked = true - SEPARATOR_PLUS -> binding.separatorPlus.isChecked = true - SEPARATOR_AND -> binding.separatorAnd.isChecked = true - else -> error("Unexpected separator in settings data") + (savedInstanceState?.getString(KEY_PENDING_SEPARATORS) ?: settings.musicSeparators) + ?.forEach { + when (it) { + SEPARATOR_COMMA -> binding.separatorComma.isChecked = true + SEPARATOR_SEMICOLON -> binding.separatorSemicolon.isChecked = true + SEPARATOR_SLASH -> binding.separatorSlash.isChecked = true + SEPARATOR_PLUS -> binding.separatorPlus.isChecked = true + SEPARATOR_AND -> binding.separatorAnd.isChecked = true + else -> error("Unexpected separator in settings data") + } } - } } override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/java/org/oxycblt/auxio/music/picker/GenreChoiceAdapter.kt b/app/src/main/java/org/oxycblt/auxio/music/picker/GenreChoiceAdapter.kt index 57f8322ce..0d6fceae1 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/picker/GenreChoiceAdapter.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/picker/GenreChoiceAdapter.kt @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2022 Auxio Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.oxycblt.auxio.music.picker import android.view.View diff --git a/app/src/main/java/org/oxycblt/auxio/music/picker/GenrePlaybackPickerDialog.kt b/app/src/main/java/org/oxycblt/auxio/music/picker/GenrePlaybackPickerDialog.kt index a5bba8d48..9ba9368fe 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/picker/GenrePlaybackPickerDialog.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/picker/GenrePlaybackPickerDialog.kt @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2022 Auxio Project + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package org.oxycblt.auxio.music.picker import android.os.Bundle @@ -21,7 +38,8 @@ import org.oxycblt.auxio.util.collectImmediately * A picker [ViewBindingDialogFragment] intended for when [Genre] playback is ambiguous. * @author Alexander Capehart (OxygenCobalt) */ -class GenrePlaybackPickerDialog : ViewBindingDialogFragment(), ClickableListListener { +class GenrePlaybackPickerDialog : + ViewBindingDialogFragment(), ClickableListListener { private val pickerModel: PickerViewModel by viewModels() private val playbackModel: PlaybackViewModel by androidActivityViewModels() // Information about what Song to show choices for is initially within the navigation arguments @@ -63,4 +81,4 @@ class GenrePlaybackPickerDialog : ViewBindingDialogFragment(null) /** The current item whose artists should be shown in the picker. Null if there is no item. */ - val currentItem: StateFlow get() = _currentItem + val currentItem: StateFlow + get() = _currentItem private val _artistChoices = MutableStateFlow>(listOf()) /** The current [Artist] choices. Empty if no item is shown in the picker. */ @@ -75,5 +76,4 @@ class PickerViewModel : ViewModel(), MusicStore.Callback { else -> {} } } - } diff --git a/app/src/main/java/org/oxycblt/auxio/music/storage/Storage.kt b/app/src/main/java/org/oxycblt/auxio/music/storage/Storage.kt index ebe8a0ae2..00a22deaf 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/storage/Storage.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/storage/Storage.kt @@ -18,12 +18,10 @@ package org.oxycblt.auxio.music.storage import android.content.Context -import android.media.MediaExtractor import android.media.MediaFormat import android.os.storage.StorageManager import android.os.storage.StorageVolume import android.webkit.MimeTypeMap -import com.google.android.exoplayer2.util.MimeTypes import java.io.File import org.oxycblt.auxio.R diff --git a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackViewModel.kt b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackViewModel.kt index d2e5e4181..42a37159b 100644 --- a/app/src/main/java/org/oxycblt/auxio/playback/PlaybackViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/playback/PlaybackViewModel.kt @@ -70,8 +70,8 @@ class PlaybackViewModel(application: Application) : private val _artistPlaybackPickerSong = MutableStateFlow(null) /** - * Flag signaling to open a picker dialog in order to resolve an ambiguous choice when - * playing a [Song] from one of it's [Artist]s. + * Flag signaling to open a picker dialog in order to resolve an ambiguous choice when playing a + * [Song] from one of it's [Artist]s. * @see playFromArtist */ val artistPickerSong: StateFlow @@ -79,8 +79,8 @@ class PlaybackViewModel(application: Application) : private val _genrePlaybackPickerSong = MutableStateFlow(null) /** - * Flag signaling to open a picker dialog in order to resolve an ambiguous choice when playing - * a [Song] from one of it's [Genre]s. + * Flag signaling to open a picker dialog in order to resolve an ambiguous choice when playing a + * [Song] from one of it's [Genre]s. */ val genrePickerSong: StateFlow get() = _genrePlaybackPickerSong diff --git a/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt b/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt index f5711e221..50887fede 100644 --- a/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt +++ b/app/src/main/java/org/oxycblt/auxio/settings/Settings.kt @@ -165,9 +165,7 @@ class Settings(private val context: Context, private val callback: Callback? = n unlikelyToBeNull(callback).onSettingChanged(key) } - /** - * Simplified callback for settings changes. - */ + /** Simplified callback for settings changes. */ interface Callback { // TODO: Refactor this lifecycle /** diff --git a/app/src/main/java/org/oxycblt/auxio/ui/NavigationViewModel.kt b/app/src/main/java/org/oxycblt/auxio/ui/NavigationViewModel.kt index 905862d7d..2ea31a0c4 100644 --- a/app/src/main/java/org/oxycblt/auxio/ui/NavigationViewModel.kt +++ b/app/src/main/java/org/oxycblt/auxio/ui/NavigationViewModel.kt @@ -92,8 +92,8 @@ class NavigationViewModel : ViewModel() { /** * Navigate to one of the parent [Artist]'s of the given [Song]. - * @param song The [Song] to navigate with. If there are multiple parent [Artist]s, - * a picker dialog will be shown. + * @param song The [Song] to navigate with. If there are multiple parent [Artist]s, a picker + * dialog will be shown. */ fun exploreNavigateToParentArtist(song: Song) { exploreNavigateToParentArtistImpl(song, song.artists) @@ -101,8 +101,8 @@ class NavigationViewModel : ViewModel() { /** * Navigate to one of the parent [Artist]'s of the given [Album]. - * @param album The [Album] to navigate with. If there are multiple parent [Artist]s, - * a picker dialog will be shown. + * @param album The [Album] to navigate with. If there are multiple parent [Artist]s, a picker + * dialog will be shown. */ fun exploreNavigateToParentArtist(album: Album) { exploreNavigateToParentArtistImpl(album, album.artists) diff --git a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetUtil.kt b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetUtil.kt index 2085db573..58f75b0a0 100644 --- a/app/src/main/java/org/oxycblt/auxio/widgets/WidgetUtil.kt +++ b/app/src/main/java/org/oxycblt/auxio/widgets/WidgetUtil.kt @@ -80,8 +80,8 @@ fun RemoteViews.setLayoutDirection(@IdRes viewId: Int, layoutDirection: Int) { } /** - * Update the app widget layouts corresponding to the given [WidgetProvider] [ComponentName] with - * an adaptive layout, in a version-compatible manner. + * Update the app widget layouts corresponding to the given [WidgetProvider] [ComponentName] with an + * adaptive layout, in a version-compatible manner. * @param context [Context] required to backport adaptive layout behavior. * @param component [ComponentName] of the app widget layout to update. * @param views Mapping between different size classes and [RemoteViews] instances. diff --git a/prebuild.py b/prebuild.py index 7aeb9eb11..59ea9552b 100755 --- a/prebuild.py +++ b/prebuild.py @@ -60,7 +60,7 @@ if os.getenv("ANDROID_HOME") is None and os.getenv("ANDROID_SDK_ROOT") is None: "ANDROID_HOME/ANDROID_SDK_ROOT before continuing.") sys.exit(1) -ndk_path = os.getenv("NDK_PATH") +ndk_path = os.getenv("ANDROID_NDK_HOME") if ndk_path is None or not os.path.isfile(os.path.join(ndk_path, "ndk-build")): # We don't have a proper path. Do some digging on the Android SDK directory # to see if we can find it.