util: remove logEOrThrow
Remove logEOrThrow from the logging framework. Better to error than silently not doing anything.
This commit is contained in:
parent
9d58076a0a
commit
5f6cdad507
13 changed files with 36 additions and 53 deletions
|
@ -48,7 +48,6 @@ import org.oxycblt.auxio.util.collect
|
|||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -134,10 +133,11 @@ class AlbumDetailFragment :
|
|||
}
|
||||
|
||||
override fun onOpenMenu(item: Item, anchor: View) {
|
||||
when (item) {
|
||||
is Song -> musicMenu(anchor, R.menu.menu_album_song_actions, item)
|
||||
else -> logEOrThrow("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
if (item is Song) {
|
||||
musicMenu(anchor, R.menu.menu_album_song_actions, item)
|
||||
}
|
||||
|
||||
error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
}
|
||||
|
||||
override fun onPlayParent() {
|
||||
|
@ -220,7 +220,7 @@ class AlbumDetailFragment :
|
|||
.navigate(AlbumDetailFragmentDirections.actionShowArtist(item.id))
|
||||
}
|
||||
null -> {}
|
||||
else -> logEOrThrow("Unexpected navigation item ${item::class.java}")
|
||||
else -> error("Unexpected navigation item ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.oxycblt.auxio.util.collect
|
|||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -130,7 +129,7 @@ class ArtistDetailFragment :
|
|||
when (item) {
|
||||
is Song -> musicMenu(anchor, R.menu.menu_artist_song_actions, item)
|
||||
is Album -> musicMenu(anchor, R.menu.menu_artist_album_actions, item)
|
||||
else -> logEOrThrow("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
else -> error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +196,7 @@ class ArtistDetailFragment :
|
|||
}
|
||||
}
|
||||
null -> {}
|
||||
else -> logEOrThrow("Unexpected navigation item ${item::class.java}")
|
||||
else -> error("Unexpected navigation item ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ import org.oxycblt.auxio.util.collect
|
|||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
|
||||
|
@ -132,7 +131,7 @@ class GenreDetailFragment :
|
|||
override fun onOpenMenu(item: Item, anchor: View) {
|
||||
when (item) {
|
||||
is Song -> musicMenu(anchor, R.menu.menu_song_actions, item)
|
||||
else -> logEOrThrow("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
else -> error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.oxycblt.auxio.ui.recycler.MenuItemListener
|
|||
import org.oxycblt.auxio.ui.recycler.SyncListDiffer
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.formatDurationMs
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.secsToMs
|
||||
|
||||
/**
|
||||
|
@ -104,7 +103,7 @@ class AlbumListFragment : HomeListFragment<Album>() {
|
|||
override fun onOpenMenu(item: Item, anchor: View) {
|
||||
when (item) {
|
||||
is Album -> musicMenu(anchor, R.menu.menu_album_actions, item)
|
||||
else -> logEOrThrow("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
else -> error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.oxycblt.auxio.ui.recycler.MenuItemListener
|
|||
import org.oxycblt.auxio.ui.recycler.SyncListDiffer
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.formatDurationMs
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
|
||||
/**
|
||||
* A [HomeListFragment] for showing a list of [Artist]s.
|
||||
|
@ -80,7 +79,7 @@ class ArtistListFragment : HomeListFragment<Artist>() {
|
|||
override fun onOpenMenu(item: Item, anchor: View) {
|
||||
when (item) {
|
||||
is Artist -> musicMenu(anchor, R.menu.menu_genre_artist_actions, item)
|
||||
else -> logEOrThrow("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
else -> error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.oxycblt.auxio.ui.recycler.MenuItemListener
|
|||
import org.oxycblt.auxio.ui.recycler.SyncListDiffer
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.formatDurationMs
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
|
||||
/**
|
||||
* A [HomeListFragment] for showing a list of [Genre]s.
|
||||
|
@ -80,7 +79,7 @@ class GenreListFragment : HomeListFragment<Genre>() {
|
|||
override fun onOpenMenu(item: Item, anchor: View) {
|
||||
when (item) {
|
||||
is Genre -> musicMenu(anchor, R.menu.menu_genre_artist_actions, item)
|
||||
else -> logEOrThrow("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
else -> error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.oxycblt.auxio.ui.recycler.SyncListDiffer
|
|||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.context
|
||||
import org.oxycblt.auxio.util.formatDurationMs
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.secsToMs
|
||||
|
||||
/**
|
||||
|
@ -108,7 +107,7 @@ class SongListFragment : HomeListFragment<Song>() {
|
|||
override fun onOpenMenu(item: Item, anchor: View) {
|
||||
when (item) {
|
||||
is Song -> musicMenu(anchor, R.menu.menu_song_actions, item)
|
||||
else -> logEOrThrow("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
else -> error("Unexpected datatype when opening menu: ${item::class.java}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.io.File
|
|||
import java.lang.reflect.Method
|
||||
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)
|
||||
|
@ -39,14 +38,7 @@ 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) ||
|
||||
relativePath.endsWith(File.separatorChar)) {
|
||||
logEOrThrow("Path was formatted with trailing separators")
|
||||
}
|
||||
}
|
||||
|
||||
class Directory private constructor(val volume: StorageVolume, val relativePath: String) {
|
||||
fun resolveName(context: Context) =
|
||||
context.getString(R.string.fmt_path, volume.getDescriptionCompat(context), relativePath)
|
||||
|
||||
|
@ -60,9 +52,22 @@ data class Directory(val volume: StorageVolume, val relativePath: String) {
|
|||
volume.uuidCompat?.let { uuid -> "${uuid}:${relativePath}" }
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = volume.hashCode()
|
||||
result = 31 * result + relativePath.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
other is Directory && other.volume == volume && other.relativePath == relativePath
|
||||
|
||||
companion object {
|
||||
private const val DOCUMENT_URI_PRIMARY_NAME = "primary"
|
||||
|
||||
fun from(volume: StorageVolume, relativePath: String) =
|
||||
Directory(
|
||||
volume, relativePath.removePrefix(File.separator).removeSuffix(File.separator))
|
||||
|
||||
/**
|
||||
* Converts an opaque document uri in the form of VOLUME:PATH into a [Directory]. This is a
|
||||
* flagrant violation of the API convention, but since we never really write to the URI I
|
||||
|
@ -79,7 +84,7 @@ data class Directory(val volume: StorageVolume, val relativePath: String) {
|
|||
|
||||
val relativePath = split.getOrNull(1)
|
||||
|
||||
return Directory(volume ?: return null, relativePath ?: return null)
|
||||
return from(volume ?: return null, relativePath ?: return null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -441,7 +441,7 @@ class Api21MediaStoreBackend : MediaStoreBackend() {
|
|||
val volumePath = volume.directoryCompat ?: continue
|
||||
val strippedPath = rawPath.removePrefix(volumePath)
|
||||
if (strippedPath != rawPath) {
|
||||
audio.dir = Directory(volume, strippedPath.removePrefix(File.separator))
|
||||
audio.dir = Directory.from(volume, strippedPath)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ open class BaseApi29MediaStoreBackend : MediaStoreBackend() {
|
|||
// This is what we use for the Directory's volume.
|
||||
val volume = volumes.find { it.mediaStoreVolumeNameCompat == volumeName }
|
||||
if (volume != null) {
|
||||
audio.dir = Directory(volume, relativePath.removeSuffix(File.separator))
|
||||
audio.dir = Directory.from(volume, relativePath)
|
||||
}
|
||||
|
||||
return audio
|
||||
|
|
|
@ -42,7 +42,6 @@ import org.oxycblt.auxio.ui.accent.AccentCustomizeDialog
|
|||
import org.oxycblt.auxio.util.androidActivityViewModels
|
||||
import org.oxycblt.auxio.util.isNight
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
|
@ -108,7 +107,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
|||
.show(childFragmentManager, PreAmpCustomizeDialog.TAG)
|
||||
context.getString(R.string.set_key_music_dirs) ->
|
||||
MusicDirsDialog().show(childFragmentManager, MusicDirsDialog.TAG)
|
||||
else -> logEOrThrow("Unexpected dialog key ${preference.key}")
|
||||
else -> error("Unexpected dialog key ${preference.key}")
|
||||
}
|
||||
}
|
||||
else -> super.onDisplayPreferenceDialog(preference)
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.oxycblt.auxio.ui.accent
|
|||
|
||||
import android.os.Build
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.logW
|
||||
|
||||
private val ACCENT_NAMES =
|
||||
intArrayOf(
|
||||
|
@ -131,7 +131,7 @@ class Accent private constructor(val index: Int) {
|
|||
companion object {
|
||||
fun from(index: Int): Accent {
|
||||
if (index > (MAX - 1)) {
|
||||
logEOrThrow("Account outside of bounds [idx: $index, max: $MAX]")
|
||||
logW("Account outside of bounds [idx: $index, max: $MAX]")
|
||||
return Accent(5)
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.oxycblt.auxio.ui.MainNavigationAction
|
|||
import org.oxycblt.auxio.ui.NavigationViewModel
|
||||
import org.oxycblt.auxio.util.androidActivityViewModels
|
||||
import org.oxycblt.auxio.util.logD
|
||||
import org.oxycblt.auxio.util.logEOrThrow
|
||||
import org.oxycblt.auxio.util.showToast
|
||||
|
||||
/**
|
||||
|
@ -74,7 +73,7 @@ abstract class MenuFragment<T : ViewBinding> : ViewBindingFragment<T>() {
|
|||
navModel.mainNavigateTo(MainNavigationAction.SongDetails(song))
|
||||
}
|
||||
else -> {
|
||||
logEOrThrow("Unexpected menu item selected")
|
||||
error("Unexpected menu item selected")
|
||||
return@musicMenuImpl false
|
||||
}
|
||||
}
|
||||
|
@ -110,8 +109,7 @@ abstract class MenuFragment<T : ViewBinding> : ViewBindingFragment<T>() {
|
|||
navModel.exploreNavigateTo(album.artist)
|
||||
}
|
||||
else -> {
|
||||
logEOrThrow("Unexpected menu item selected")
|
||||
return@musicMenuImpl false
|
||||
error("Unexpected menu item selected")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,7 +141,7 @@ abstract class MenuFragment<T : ViewBinding> : ViewBindingFragment<T>() {
|
|||
requireContext().showToast(R.string.lng_queue_added)
|
||||
}
|
||||
else -> {
|
||||
logEOrThrow("Unexpected menu item selected")
|
||||
error("Unexpected menu item selected")
|
||||
return@musicMenuImpl false
|
||||
}
|
||||
}
|
||||
|
@ -176,8 +174,7 @@ abstract class MenuFragment<T : ViewBinding> : ViewBindingFragment<T>() {
|
|||
requireContext().showToast(R.string.lng_queue_added)
|
||||
}
|
||||
else -> {
|
||||
logEOrThrow("Unexpected menu item selected")
|
||||
return@musicMenuImpl false
|
||||
error("Unexpected menu item selected")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,18 +45,6 @@ fun Any.logW(msg: String) = Log.w(autoTag, msg)
|
|||
/** Shortcut method for logging [msg] as an error to the console. Handles anonymous objects */
|
||||
fun Any.logE(msg: String) = Log.e(autoTag, msg)
|
||||
|
||||
/**
|
||||
* Logs an error on release, but throws an exception in debug. This is useful for non-showstopper
|
||||
* bugs that I would still prefer to be caught in debug mode.
|
||||
*/
|
||||
fun Any.logEOrThrow(msg: String) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
error(msg)
|
||||
} else {
|
||||
logE(msg)
|
||||
}
|
||||
}
|
||||
|
||||
/** Automatically creates a tag that identifies the object currently logging. */
|
||||
private val Any.autoTag: String
|
||||
get() = "Auxio.${this::class.simpleName ?: "Anonymous Object"}"
|
||||
|
|
Loading…
Reference in a new issue