Use custom logging wrapper
Create a custom logging wrapper so that debug messages dont show up in release builds, fix bugs with anonymous objects and to just remove the boilerplate for normal log functions.
This commit is contained in:
parent
c7549d6bfa
commit
384d0f1a27
22 changed files with 148 additions and 130 deletions
30
app/src/main/java/org/oxycblt/auxio/Logger.kt
Normal file
30
app/src/main/java/org/oxycblt/auxio/Logger.kt
Normal file
|
@ -0,0 +1,30 @@
|
|||
package org.oxycblt.auxio
|
||||
|
||||
import android.util.Log
|
||||
|
||||
// Shortcut functions for logging.
|
||||
// Yes, I know timber exists but it does too much.
|
||||
|
||||
/**
|
||||
* Shortcut method for logging a debug statement, handles debug builds and anonymous objects
|
||||
* @param msg The message to log
|
||||
*/
|
||||
fun Any.logD(msg: String) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.d(getName(), msg)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut method for logging an error. Handles anonymous objects
|
||||
* @param msg The message to log
|
||||
*/
|
||||
fun Any.logE(msg: String) {
|
||||
Log.e(getName(), msg)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a non-nullable name, used so that logs will always show up in the console.
|
||||
* @return The name of the object, otherwise "Anonymous Object"
|
||||
*/
|
||||
private fun Any.getName(): String = this::class.simpleName ?: "Anonymous Object"
|
|
@ -4,7 +4,6 @@ import android.content.Intent
|
|||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -63,7 +62,7 @@ class MainActivity : AppCompatActivity() {
|
|||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// Do modern edge to edge [Which is really a shot in the dark tbh]
|
||||
Log.d(this::class.simpleName, "Doing R+ edge-to-edge.")
|
||||
this@MainActivity.logD("Doing R+ edge-to-edge.")
|
||||
|
||||
setDecorFitsSystemWindows(false)
|
||||
|
||||
|
@ -77,7 +76,7 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
} else {
|
||||
// Do old edge-to-edge otherwise
|
||||
Log.d(this::class.simpleName, "Doing legacy edge-to-edge.")
|
||||
this@MainActivity.logD("Doing legacy edge-to-edge.")
|
||||
|
||||
binding.root.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
|
|
|
@ -104,7 +104,7 @@ class MainFragment : Fragment() {
|
|||
|
||||
playbackModel.restorePlaybackIfNeeded(requireContext())
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment Created.")
|
||||
logD("Fragment Created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
@ -154,10 +154,7 @@ class MainFragment : Fragment() {
|
|||
|
||||
private fun handleCompactPlaybackVisibility(binding: FragmentMainBinding, song: Song?) {
|
||||
if (song == null) {
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"Hiding CompactPlaybackFragment since no song is being played."
|
||||
)
|
||||
logD("Hiding CompactPlaybackFragment since no song is being played.")
|
||||
|
||||
binding.compactPlayback.visibility = View.GONE
|
||||
playbackModel.disableAnimation()
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.content.Context
|
|||
import android.database.Cursor
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import android.util.Log
|
||||
import org.oxycblt.auxio.logD
|
||||
|
||||
/**
|
||||
* A SQLite database for managing the persistent playback state and queue.
|
||||
|
@ -82,7 +82,7 @@ class PlaybackStateDatabase(context: Context) :
|
|||
} finally {
|
||||
database.endTransaction()
|
||||
|
||||
Log.d(this::class.simpleName, "Successfully wiped previous state.")
|
||||
logD("Successfully wiped previous state.")
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -106,7 +106,7 @@ class PlaybackStateDatabase(context: Context) :
|
|||
} finally {
|
||||
database.endTransaction()
|
||||
|
||||
Log.d(this::class.simpleName, "Wrote state to database.")
|
||||
logD("Wrote state to database.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,10 +180,10 @@ class PlaybackStateDatabase(context: Context) :
|
|||
} finally {
|
||||
database.endTransaction()
|
||||
|
||||
Log.d(this::class.simpleName, "Successfully wiped queue.")
|
||||
logD("Successfully wiped queue.")
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Writing to queue.")
|
||||
logD("Writing to queue.")
|
||||
|
||||
var position = 0
|
||||
|
||||
|
@ -215,7 +215,7 @@ class PlaybackStateDatabase(context: Context) :
|
|||
// the next iteration should skip it.
|
||||
position = i
|
||||
|
||||
Log.d(this::class.simpleName, "Wrote batch of $position songs.")
|
||||
logD("Wrote batch of $position songs.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.oxycblt.auxio.detail
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -12,6 +11,7 @@ import androidx.navigation.fragment.navArgs
|
|||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentAlbumDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.AlbumSongAdapter
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.music.Song
|
||||
|
@ -121,7 +121,7 @@ class AlbumDetailFragment : DetailFragment() {
|
|||
// -- VIEWMODEL SETUP ---
|
||||
|
||||
detailModel.albumSortMode.observe(viewLifecycleOwner) { mode ->
|
||||
Log.d(this::class.simpleName, "Updating sort mode to $mode")
|
||||
logD("Updating sort mode to $mode")
|
||||
|
||||
// Update the current sort icon
|
||||
binding.albumSortButton.setImageResource(mode.iconRes)
|
||||
|
@ -186,7 +186,7 @@ class AlbumDetailFragment : DetailFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
logD("Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.oxycblt.auxio.detail
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -12,6 +11,7 @@ import androidx.navigation.fragment.navArgs
|
|||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentArtistDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.ArtistAlbumAdapter
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
|
@ -110,7 +110,7 @@ class ArtistDetailFragment : DetailFragment() {
|
|||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
detailModel.artistSortMode.observe(viewLifecycleOwner) { mode ->
|
||||
Log.d(this::class.simpleName, "Updating sort mode to $mode")
|
||||
logD("Updating sort mode to $mode")
|
||||
|
||||
// Update the current sort icon
|
||||
binding.artistSortButton.setImageResource(mode.iconRes)
|
||||
|
@ -127,7 +127,7 @@ class ArtistDetailFragment : DetailFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
logD("Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.navigation.fragment.navArgs
|
|||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentGenreDetailBinding
|
||||
import org.oxycblt.auxio.detail.adapters.GenreArtistAdapter
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.ui.disable
|
||||
|
@ -109,7 +110,7 @@ class GenreDetailFragment : DetailFragment() {
|
|||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
detailModel.genreSortMode.observe(viewLifecycleOwner) { mode ->
|
||||
Log.d(this::class.simpleName, "Updating sort mode to $mode")
|
||||
logD("Updating sort mode to $mode")
|
||||
|
||||
// Update the current sort icon
|
||||
binding.genreSortButton.setImageResource(mode.iconRes)
|
||||
|
@ -120,7 +121,7 @@ class GenreDetailFragment : DetailFragment() {
|
|||
)
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
logD("Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.oxycblt.auxio.R
|
|||
import org.oxycblt.auxio.databinding.FragmentLibraryBinding
|
||||
import org.oxycblt.auxio.library.adapters.LibraryAdapter
|
||||
import org.oxycblt.auxio.library.adapters.SearchAdapter
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
|
@ -136,7 +137,7 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
|||
}
|
||||
|
||||
libraryModel.sortMode.observe(viewLifecycleOwner) { mode ->
|
||||
Log.d(this::class.simpleName, "Updating sort mode to $mode")
|
||||
logD("Updating sort mode to $mode")
|
||||
|
||||
// Then update the menu item in the toolbar to reflect the new mode
|
||||
binding.libraryToolbar.menu.forEach {
|
||||
|
@ -160,7 +161,7 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
|||
}
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
logD("Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
@ -206,7 +207,7 @@ class LibraryFragment : Fragment(), SearchView.OnQueryTextListener {
|
|||
if (!libraryModel.isNavigating) {
|
||||
libraryModel.updateNavigationStatus(true)
|
||||
|
||||
Log.d(this::class.simpleName, "Navigating to the detail fragment for ${baseModel.name}")
|
||||
logD("Navigating to the detail fragment for ${baseModel.name}")
|
||||
|
||||
findNavController().navigate(
|
||||
when (baseModel) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import androidx.fragment.app.activityViewModels
|
|||
import androidx.navigation.fragment.findNavController
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentLoadingBinding
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
|
||||
|
||||
|
@ -107,7 +108,7 @@ class LoadingFragment : Fragment(R.layout.fragment_loading) {
|
|||
loadingModel.go()
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
logD("Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.util.Log
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.processing.MusicLoader
|
||||
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
|
||||
import org.oxycblt.auxio.music.processing.MusicSorter
|
||||
|
@ -45,7 +46,7 @@ class MusicStore private constructor() {
|
|||
*/
|
||||
suspend fun load(app: Application): MusicLoaderResponse {
|
||||
return withContext(Dispatchers.IO) {
|
||||
Log.i(this::class.simpleName, "Starting initial music load...")
|
||||
logD("Starting initial music load...")
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
|
||||
|
@ -83,10 +84,7 @@ class MusicStore private constructor() {
|
|||
|
||||
val elapsed = System.currentTimeMillis() - start
|
||||
|
||||
Log.i(
|
||||
this::class.simpleName,
|
||||
"Music load completed successfully in ${elapsed}ms."
|
||||
)
|
||||
logD("Music load completed successfully in ${elapsed}ms.")
|
||||
|
||||
loaded = true
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import android.provider.MediaStore.Audio.Artists
|
|||
import android.provider.MediaStore.Audio.Genres
|
||||
import android.provider.MediaStore.Audio.Media
|
||||
import android.util.Log
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.logE
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
|
@ -47,7 +49,7 @@ class MusicLoader(
|
|||
loadAlbums()
|
||||
loadSongs()
|
||||
} catch (error: Exception) {
|
||||
Log.e(this::class.simpleName, "Something went horribly wrong.")
|
||||
logE("Something went horribly wrong.")
|
||||
error.printStackTrace()
|
||||
|
||||
return MusicLoaderResponse.FAILURE
|
||||
|
@ -61,7 +63,7 @@ class MusicLoader(
|
|||
}
|
||||
|
||||
private fun loadGenres() {
|
||||
Log.d(this::class.simpleName, "Starting genre search...")
|
||||
logD("Starting genre search...")
|
||||
|
||||
// First, get a cursor for every genre in the android system
|
||||
val genreCursor = resolver.query(
|
||||
|
@ -99,14 +101,11 @@ class MusicLoader(
|
|||
cursor.close()
|
||||
}
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"Genre search finished with ${genres.size} genres found."
|
||||
)
|
||||
logD("Genre search finished with ${genres.size} genres found.")
|
||||
}
|
||||
|
||||
private fun loadArtists() {
|
||||
Log.d(this::class.simpleName, "Starting artist search...")
|
||||
logD("Starting artist search...")
|
||||
|
||||
// Load all the artists
|
||||
val artistCursor = resolver.query(
|
||||
|
@ -170,15 +169,12 @@ class MusicLoader(
|
|||
artistGenreCursor?.close()
|
||||
}
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"Artist search finished with ${artists.size} artists found."
|
||||
)
|
||||
logD("Artist search finished with ${artists.size} artists found.")
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
private fun loadAlbums() {
|
||||
Log.d(this::class.simpleName, "Starting album search...")
|
||||
logD("Starting album search...")
|
||||
|
||||
val albumCursor = resolver.query(
|
||||
Albums.EXTERNAL_CONTENT_URI,
|
||||
|
@ -222,15 +218,12 @@ class MusicLoader(
|
|||
it.name to it.artistId to it.year
|
||||
}.toMutableList()
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"Album search finished with ${albums.size} albums found"
|
||||
)
|
||||
logD("Album search finished with ${albums.size} albums found")
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
private fun loadSongs() {
|
||||
Log.d(this::class.simpleName, "Starting song search...")
|
||||
logD("Starting song search...")
|
||||
|
||||
val songCursor = resolver.query(
|
||||
Media.EXTERNAL_CONTENT_URI,
|
||||
|
@ -276,9 +269,6 @@ class MusicLoader(
|
|||
it.name to it.albumId to it.track to it.duration
|
||||
}.toMutableList()
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"Song search finished with ${songs.size} found"
|
||||
)
|
||||
logD("Song search finished with ${songs.size} found")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.oxycblt.auxio.music.processing
|
||||
|
||||
import android.util.Log
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.Genre
|
||||
|
@ -24,7 +25,7 @@ class MusicSorter(
|
|||
}
|
||||
|
||||
private fun sortSongsIntoAlbums() {
|
||||
Log.d(this::class.simpleName, "Sorting songs into albums...")
|
||||
logD("Sorting songs into albums...")
|
||||
|
||||
val unknownSongs = songs.toMutableList()
|
||||
|
||||
|
@ -56,15 +57,12 @@ class MusicSorter(
|
|||
|
||||
albums.add(unknownAlbum)
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"${unknownSongs.size} songs were placed into an unknown album."
|
||||
)
|
||||
logD("${unknownSongs.size} songs were placed into an unknown album.")
|
||||
}
|
||||
}
|
||||
|
||||
private fun sortAlbumsIntoArtists() {
|
||||
Log.d(this::class.simpleName, "Sorting albums into artists...")
|
||||
logD("Sorting albums into artists...")
|
||||
|
||||
val unknownAlbums = albums.toMutableList()
|
||||
|
||||
|
@ -109,15 +107,12 @@ class MusicSorter(
|
|||
|
||||
artists.add(unknownArtist)
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"${unknownAlbums.size} albums were placed into an unknown artist."
|
||||
)
|
||||
logD("${unknownAlbums.size} albums were placed into an unknown artist.")
|
||||
}
|
||||
}
|
||||
|
||||
private fun sortArtistsIntoGenres() {
|
||||
Log.d(this::class.simpleName, "Sorting artists into genres...")
|
||||
logD("Sorting artists into genres...")
|
||||
|
||||
val unknownArtists = artists.toMutableList()
|
||||
|
||||
|
@ -147,10 +142,7 @@ class MusicSorter(
|
|||
}
|
||||
genres.add(unknownGenre)
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"${unknownArtists.size} artists were placed into an unknown genre."
|
||||
)
|
||||
logD("${unknownArtists.size} artists were placed into an unknown genre.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.oxycblt.auxio.BuildConfig
|
|||
import org.oxycblt.auxio.MainFragmentDirections
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentCompactPlaybackBinding
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.ui.createToast
|
||||
|
||||
|
@ -69,7 +70,7 @@ class CompactPlaybackFragment : Fragment() {
|
|||
|
||||
playbackModel.song.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
Log.d(this::class.simpleName, "Updating song display to ${it.name}")
|
||||
logD("Updating song display to ${it.name}")
|
||||
|
||||
binding.song = it
|
||||
binding.playbackProgress.max = it.seconds.toInt()
|
||||
|
@ -80,7 +81,7 @@ class CompactPlaybackFragment : Fragment() {
|
|||
binding.playbackProgress.progress = it
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment Created")
|
||||
logD("Fragment Created")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.support.v4.media.session.MediaSessionCompat
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.media.app.NotificationCompat.MediaStyle
|
||||
import org.oxycblt.auxio.MainActivity
|
||||
|
@ -81,12 +82,18 @@ fun NotificationManager.createMediaNotification(
|
|||
|
||||
/**
|
||||
* Set the current metadata of a media notification.
|
||||
* @param song The [Song] that the notification should reflect
|
||||
* @param context The [Context] needed to load the cover bitmap
|
||||
* @param song The [Song] that the notification should reflect
|
||||
* @param colorize Whether to load the album art and colorize the notification based off it
|
||||
* @param onDone A callback for when the process is finished
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
fun NotificationCompat.Builder.setMetadata(song: Song, context: Context, onDone: () -> Unit) {
|
||||
fun NotificationCompat.Builder.setMetadata(
|
||||
context: Context,
|
||||
song: Song,
|
||||
colorize: Boolean,
|
||||
onDone: () -> Unit
|
||||
) {
|
||||
setContentTitle(song.name)
|
||||
setContentText(
|
||||
song.album.artist.name,
|
||||
|
@ -98,8 +105,7 @@ fun NotificationCompat.Builder.setMetadata(song: Song, context: Context, onDone:
|
|||
setSubText(song.album.name)
|
||||
}
|
||||
|
||||
// Also set the cover art [If reasonable]
|
||||
if (SettingsManager.getInstance().colorizeNotif) {
|
||||
if (colorize) {
|
||||
// getBitmap() is concurrent, so only call back to the object calling this function when
|
||||
// the loading is over.
|
||||
getBitmap(song, context) {
|
||||
|
@ -124,12 +130,12 @@ fun NotificationCompat.Builder.updatePlaying(context: Context) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Update the loop/shuffle button on the media notification
|
||||
* Update the extra action on the media notification [E.G the Loop/Shuffle button]
|
||||
* @param context The context required to refresh the action
|
||||
*/
|
||||
@SuppressLint("RestrictedApi")
|
||||
fun NotificationCompat.Builder.updateExtraAction(context: Context) {
|
||||
mActions[0] = if (SettingsManager.getInstance().useAltNotifAction) {
|
||||
fun NotificationCompat.Builder.updateExtraAction(context: Context, useAltAction: Boolean) {
|
||||
mActions[0] = if (useAltAction) {
|
||||
newAction(NotificationUtils.ACTION_SHUFFLE, context)
|
||||
} else {
|
||||
newAction(NotificationUtils.ACTION_LOOP, context)
|
||||
|
@ -201,4 +207,4 @@ private fun newAction(action: String, context: Context): NotificationCompat.Acti
|
|||
Intent(action), PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
).build()
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import androidx.fragment.app.activityViewModels
|
|||
import androidx.navigation.fragment.findNavController
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentPlaybackBinding
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.playback.state.LoopMode
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
|
@ -92,12 +93,12 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
|
||||
playbackModel.song.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
Log.d(this::class.simpleName, "Updating song display to ${it.name}.")
|
||||
logD("Updating song display to ${it.name}.")
|
||||
|
||||
binding.song = it
|
||||
binding.playbackSeekBar.max = it.seconds.toInt()
|
||||
} else {
|
||||
Log.d(this::class.simpleName, "No song is being played, leaving.")
|
||||
logD("No song is being played, leaving.")
|
||||
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
@ -194,7 +195,7 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment Created.")
|
||||
logD("Fragment Created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import kotlinx.coroutines.flow.conflate
|
|||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
import kotlinx.coroutines.launch
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.Song
|
||||
import org.oxycblt.auxio.music.coil.getBitmap
|
||||
import org.oxycblt.auxio.music.toURI
|
||||
|
@ -82,7 +83,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
// --- SERVICE OVERRIDES ---
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
Log.d(this::class.simpleName, "Service is active.")
|
||||
logD("Service is active.")
|
||||
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
@ -177,7 +178,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
serviceJob.cancel()
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Service destroyed.")
|
||||
logD("Service destroyed.")
|
||||
}
|
||||
|
||||
// --- PLAYER EVENT LISTENER OVERRIDES ---
|
||||
|
@ -237,7 +238,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
|
||||
uploadMetadataToSession(it)
|
||||
|
||||
notification.setMetadata(playbackManager.song!!, this) {
|
||||
notification.setMetadata(this, playbackManager.song!!, settingsManager.colorizeNotif) {
|
||||
startForegroundOrNotify("Song")
|
||||
}
|
||||
|
||||
|
@ -283,13 +284,13 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
}
|
||||
}
|
||||
|
||||
notification.updateExtraAction(this)
|
||||
notification.updateExtraAction(this, settingsManager.useAltNotifAction)
|
||||
startForegroundOrNotify("Loop")
|
||||
}
|
||||
|
||||
override fun onShuffleUpdate(isShuffling: Boolean) {
|
||||
if (settingsManager.useAltNotifAction) {
|
||||
notification.updateExtraAction(this)
|
||||
notification.updateExtraAction(this, settingsManager.useAltNotifAction)
|
||||
|
||||
startForegroundOrNotify("Shuffle update")
|
||||
}
|
||||
|
@ -302,7 +303,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
}
|
||||
|
||||
override fun onRestoreFinish() {
|
||||
Log.d(this::class.simpleName, "Restore done")
|
||||
logD("Restore done")
|
||||
|
||||
restorePlayer()
|
||||
}
|
||||
|
@ -311,14 +312,14 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
|
||||
override fun onColorizeNotifUpdate(doColorize: Boolean) {
|
||||
playbackManager.song?.let {
|
||||
notification.setMetadata(it, this) {
|
||||
notification.setMetadata(this, it, settingsManager.colorizeNotif) {
|
||||
startForegroundOrNotify("Colorize update")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNotifActionUpdate(useAltAction: Boolean) {
|
||||
notification.updateExtraAction(this)
|
||||
notification.updateExtraAction(this, useAltAction)
|
||||
|
||||
startForegroundOrNotify("Notif action update")
|
||||
}
|
||||
|
@ -351,12 +352,12 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
}
|
||||
|
||||
private fun restoreNotification() {
|
||||
notification.updateExtraAction(this)
|
||||
notification.updateExtraAction(this, settingsManager.useAltNotifAction)
|
||||
notification.updateMode(this)
|
||||
notification.updatePlaying(this)
|
||||
|
||||
playbackManager.song?.let {
|
||||
notification.setMetadata(it, this) {
|
||||
notification.setMetadata(this, it, settingsManager.colorizeNotif) {
|
||||
if (playbackManager.isPlaying) {
|
||||
startForegroundOrNotify("Restore")
|
||||
} else {
|
||||
|
@ -402,7 +403,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
// Don't start the foreground if the playback hasn't started yet AND if the playback hasn't
|
||||
// been restored
|
||||
if (playbackManager.hasPlayed && playbackManager.isRestored) {
|
||||
Log.d(this::class.simpleName, "Starting foreground/notifying because of $reason")
|
||||
logD("Starting foreground/notifying because of $reason")
|
||||
|
||||
if (!isForeground) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
|
@ -510,7 +511,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
|
||||
private fun resume() {
|
||||
if (playbackManager.song != null && settingsManager.doPlugMgt) {
|
||||
Log.d(this::class.simpleName, "Device connected, resuming...")
|
||||
logD("Device connected, resuming...")
|
||||
|
||||
playbackManager.setPlayingStatus(true)
|
||||
}
|
||||
|
@ -518,7 +519,7 @@ class PlaybackService : Service(), Player.EventListener, PlaybackStateManager.Ca
|
|||
|
||||
private fun pause() {
|
||||
if (playbackManager.song != null && settingsManager.doPlugMgt) {
|
||||
Log.d(this::class.simpleName, "Device disconnected, pausing...")
|
||||
logD("Device disconnected, pausing...")
|
||||
|
||||
playbackManager.setPlayingStatus(false)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import androidx.lifecycle.Transformations
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.logE
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
|
@ -109,7 +111,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
// Play an album
|
||||
fun playAlbum(album: Album, shuffled: Boolean) {
|
||||
if (album.songs.isEmpty()) {
|
||||
Log.e(this::class.simpleName, "Album is empty, Not playing.")
|
||||
logE("Album is empty, Not playing.")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -120,7 +122,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
// Play an artist
|
||||
fun playArtist(artist: Artist, shuffled: Boolean) {
|
||||
if (artist.songs.isEmpty()) {
|
||||
Log.e(this::class.simpleName, "Artist is empty, Not playing.")
|
||||
logE("Artist is empty, Not playing.")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -131,7 +133,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
// Play a genre
|
||||
fun playGenre(genre: Genre, shuffled: Boolean) {
|
||||
if (genre.songs.isEmpty()) {
|
||||
Log.e(this::class.simpleName, "Genre is empty, Not playing.")
|
||||
logE("Genre is empty, Not playing.")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -349,7 +351,7 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
}
|
||||
|
||||
private fun restorePlaybackState() {
|
||||
Log.d(this::class.simpleName, "Attempting to restore playback state.")
|
||||
logD("Attempting to restore playback state.")
|
||||
|
||||
mSong.value = playbackManager.song
|
||||
mPosition.value = playbackManager.position / 1000
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.ItemActionHeaderBinding
|
||||
import org.oxycblt.auxio.databinding.ItemQueueSongBinding
|
||||
import org.oxycblt.auxio.logE
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.music.Song
|
||||
|
@ -72,7 +73,7 @@ class QueueAdapter(
|
|||
}
|
||||
|
||||
else -> {
|
||||
Log.e(this::class.simpleName, "Bad data fed to QueueAdapter.")
|
||||
logE("Bad data fed to QueueAdapter.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import kotlinx.coroutines.withContext
|
|||
import org.oxycblt.auxio.database.PlaybackState
|
||||
import org.oxycblt.auxio.database.PlaybackStateDatabase
|
||||
import org.oxycblt.auxio.database.QueueItem
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.logE
|
||||
import org.oxycblt.auxio.music.Album
|
||||
import org.oxycblt.auxio.music.Artist
|
||||
import org.oxycblt.auxio.music.BaseModel
|
||||
|
@ -121,12 +123,12 @@ class PlaybackStateManager private constructor() {
|
|||
// Auxio doesn't support playing songs while swapping the mode to GENRE, as its impossible
|
||||
// to determine what genre a song has.
|
||||
if (mode == PlaybackMode.IN_GENRE) {
|
||||
Log.e(this::class.simpleName, "Auxio cant play songs with the mode of IN_GENRE.")
|
||||
logE("Auxio cant play songs with the mode of IN_GENRE.")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Updating song to ${song.name} and mode to $mode")
|
||||
logD("Updating song to ${song.name} and mode to $mode")
|
||||
|
||||
val musicStore = MusicStore.getInstance()
|
||||
|
||||
|
@ -171,15 +173,12 @@ class PlaybackStateManager private constructor() {
|
|||
fun playParentModel(baseModel: BaseModel, shuffled: Boolean) {
|
||||
// This should never occur.
|
||||
if (baseModel is Song || baseModel is Header) {
|
||||
Log.e(
|
||||
this::class.simpleName,
|
||||
"playParentModel does not support ${baseModel::class.simpleName}."
|
||||
)
|
||||
logE("playParentModel does not support ${baseModel::class.simpleName}.")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Playing ${baseModel.name}")
|
||||
logD("Playing ${baseModel.name}")
|
||||
|
||||
mParent = baseModel
|
||||
mIndex = 0
|
||||
|
@ -328,10 +327,10 @@ class PlaybackStateManager private constructor() {
|
|||
// --- QUEUE EDITING FUNCTIONS ---
|
||||
|
||||
fun removeQueueItem(index: Int): Boolean {
|
||||
Log.d(this::class.simpleName, "Removing item ${mQueue[index].name}.")
|
||||
logD("Removing item ${mQueue[index].name}.")
|
||||
|
||||
if (index > mQueue.size || index < 0) {
|
||||
Log.e(this::class.simpleName, "Index is out of bounds, did not remove queue item.")
|
||||
logE("Index is out of bounds, did not remove queue item.")
|
||||
|
||||
return false
|
||||
}
|
||||
|
@ -348,7 +347,7 @@ class PlaybackStateManager private constructor() {
|
|||
val item = mQueue.removeAt(from)
|
||||
mQueue.add(to, item)
|
||||
} catch (exception: IndexOutOfBoundsException) {
|
||||
Log.e(this::class.simpleName, "Indices were out of bounds, did not move queue item")
|
||||
logE("Indices were out of bounds, did not move queue item")
|
||||
|
||||
return false
|
||||
}
|
||||
|
@ -371,10 +370,10 @@ class PlaybackStateManager private constructor() {
|
|||
}
|
||||
|
||||
fun removeUserQueueItem(index: Int) {
|
||||
Log.d(this::class.simpleName, "Removing item ${mUserQueue[index].name}.")
|
||||
logD("Removing item ${mUserQueue[index].name}.")
|
||||
|
||||
if (index > mUserQueue.size || index < 0) {
|
||||
Log.e(this::class.simpleName, "Index is out of bounds, did not remove queue item.")
|
||||
logE("Index is out of bounds, did not remove queue item.")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -389,7 +388,7 @@ class PlaybackStateManager private constructor() {
|
|||
val item = mUserQueue.removeAt(from)
|
||||
mUserQueue.add(to, item)
|
||||
} catch (exception: IndexOutOfBoundsException) {
|
||||
Log.e(this::class.simpleName, "Indices were out of bounds, did not move queue item")
|
||||
logE("Indices were out of bounds, did not move queue item")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -430,7 +429,7 @@ class PlaybackStateManager private constructor() {
|
|||
private fun genShuffle(keepSong: Boolean) {
|
||||
val newSeed = Random.Default.nextLong()
|
||||
|
||||
Log.d(this::class.simpleName, "Shuffling queue with seed $newSeed")
|
||||
logD("Shuffling queue with seed $newSeed")
|
||||
|
||||
mShuffleSeed = newSeed
|
||||
|
||||
|
@ -501,7 +500,7 @@ class PlaybackStateManager private constructor() {
|
|||
// --- PERSISTENCE FUNCTIONS ---
|
||||
|
||||
suspend fun saveStateToDatabase(context: Context) {
|
||||
Log.d(this::class.simpleName, "Saving state to DB.")
|
||||
logD("Saving state to DB.")
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
|
||||
|
@ -516,11 +515,11 @@ class PlaybackStateManager private constructor() {
|
|||
|
||||
val time = System.currentTimeMillis() - start
|
||||
|
||||
Log.d(this::class.simpleName, "Save finished in ${time}ms")
|
||||
logD("Save finished in ${time}ms")
|
||||
}
|
||||
|
||||
suspend fun getStateFromDatabase(context: Context) {
|
||||
Log.d(this::class.simpleName, "Getting state from DB.")
|
||||
logD("Getting state from DB.")
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
|
||||
|
@ -535,11 +534,11 @@ class PlaybackStateManager private constructor() {
|
|||
|
||||
val loadTime = System.currentTimeMillis() - start
|
||||
|
||||
Log.d(this::class.simpleName, "Load finished in ${loadTime}ms")
|
||||
logD("Load finished in ${loadTime}ms")
|
||||
|
||||
state?.let {
|
||||
Log.d(this::class.simpleName, "Valid playback state $it")
|
||||
Log.d(this::class.simpleName, "Valid queue size ${queueItems.size}")
|
||||
logD("Valid playback state $it")
|
||||
logD("Valid queue size ${queueItems.size}")
|
||||
|
||||
unpackFromPlaybackState(it)
|
||||
unpackQueue(queueItems)
|
||||
|
@ -548,7 +547,7 @@ class PlaybackStateManager private constructor() {
|
|||
|
||||
val time = System.currentTimeMillis() - start
|
||||
|
||||
Log.d(this::class.simpleName, "Restore finished in ${time}ms")
|
||||
logD("Restore finished in ${time}ms")
|
||||
|
||||
mIsRestored = true
|
||||
}
|
||||
|
@ -642,7 +641,7 @@ class PlaybackStateManager private constructor() {
|
|||
private fun doParentSanityCheck() {
|
||||
// Check if the parent was lost while in the DB.
|
||||
if (mSong != null && mParent == null && mMode != PlaybackMode.ALL_SONGS) {
|
||||
Log.d(this::class.simpleName, "Parent lost, attempting restore.")
|
||||
logD("Parent lost, attempting restore.")
|
||||
|
||||
mParent = when (mMode) {
|
||||
PlaybackMode.IN_ALBUM -> mQueue.firstOrNull()?.album
|
||||
|
@ -683,7 +682,7 @@ class PlaybackStateManager private constructor() {
|
|||
genres = otherGenres.toMutableList()
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Found genre $genres")
|
||||
logD("Found genre $genres")
|
||||
|
||||
// There should not be more than one common genre, so return null if that's the case
|
||||
if (genres.size > 1) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.customview.customView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.recycler.DisplayMode
|
||||
import org.oxycblt.auxio.settings.adapters.AccentAdapter
|
||||
import org.oxycblt.auxio.ui.ACCENTS
|
||||
|
@ -24,13 +25,11 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// --- PREFERENCE ITEM SETUP ---
|
||||
|
||||
preferenceScreen.children.forEach {
|
||||
recursivelyHandleChildren(it)
|
||||
}
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
logD("Fragment created.")
|
||||
}
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.reddit.indicatorfastscroll.FastScrollItemIndicator
|
|||
import com.reddit.indicatorfastscroll.FastScrollerView
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentSongsBinding
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
|
@ -80,7 +81,7 @@ class SongsFragment : Fragment() {
|
|||
|
||||
setupFastScroller(binding)
|
||||
|
||||
Log.d(this::class.simpleName, "Fragment created.")
|
||||
logD("Fragment created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
@ -133,10 +134,7 @@ class SongsFragment : Fragment() {
|
|||
if (total > maxEntries.toInt()) {
|
||||
concatInterval = ceil(total / maxEntries).toInt()
|
||||
|
||||
Log.d(
|
||||
this::class.simpleName,
|
||||
"More entries than screen space, truncating by $concatInterval..."
|
||||
)
|
||||
logD("More entries than screen space, truncating by $concatInterval.")
|
||||
|
||||
check(concatInterval > 1) {
|
||||
"ConcatInterval was one despite truncation being needed"
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.text.toSpanned
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logE
|
||||
import java.util.Locale
|
||||
|
||||
// Functions for managing colors/accents.
|
||||
|
@ -89,7 +90,7 @@ fun Int.toColor(context: Context): Int {
|
|||
return try {
|
||||
ContextCompat.getColor(context, this)
|
||||
} catch (e: Resources.NotFoundException) {
|
||||
Log.e(this::class.simpleName, "Attempted color load failed.")
|
||||
logE("Attempted color load failed.")
|
||||
|
||||
// Default to the emergency color [Black] if the loading fails.
|
||||
ContextCompat.getColor(context, android.R.color.black)
|
||||
|
|
Loading…
Reference in a new issue