Cleanup code

Cleanup a bunch of redundant, unused, and bad code.
This commit is contained in:
OxygenCobalt 2020-11-21 16:43:32 -07:00
parent 13b80585d2
commit d8a40fe219
32 changed files with 66 additions and 109 deletions

View file

@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.oxycblt.auxio">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- TODO: Backup -->
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Base">
android:theme="@style/Theme.Base"
tools:ignore="AllowBackup">
<activity
android:name=".MainActivity"
android:launchMode="singleInstance"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

View file

@ -59,9 +59,9 @@ class MainFragment : Fragment() {
)
val navController = (
childFragmentManager.findFragmentById(R.id.explore_nav_host)
as NavHostFragment?
)?.findNavController()
childFragmentManager.findFragmentById(R.id.explore_nav_host)
as NavHostFragment?
)?.findNavController()
// --- UI SETUP ---

View file

@ -90,7 +90,7 @@ class AlbumDetailFragment : DetailFragment() {
}
// Don't enable the sort button if there's only one song [or less]
if (detailModel.currentAlbum.value!!.numSongs < 2) {
if (detailModel.currentAlbum.value!!.songs.size < 2) {
binding.albumSortButton.disable(requireContext())
}

View file

@ -86,7 +86,7 @@ class ArtistDetailFragment : DetailFragment() {
}
// Disable the sort button if there is only one album [Or less]
if (detailModel.currentArtist.value!!.numAlbums < 2) {
if (detailModel.currentArtist.value!!.albums.size < 2) {
binding.artistSortButton.disable(requireContext())
}

View file

@ -86,7 +86,7 @@ class GenreDetailFragment : DetailFragment() {
}
// Disable the sort button if there is only one artist [Or less]
if (detailModel.currentGenre.value!!.numArtists < 2) {
if (detailModel.currentGenre.value!!.artists.size < 2) {
binding.genreSortButton.disable(requireContext())
}

View file

@ -22,7 +22,7 @@ class LibraryViewModel : ViewModel() {
val searchHasFocus: Boolean get() = mSearchHasFocus
// TODO: Move these to prefs when they're added
private val mShowMode = MutableLiveData(ShowMode.SHOW_GENRES)
private val mShowMode = MutableLiveData(ShowMode.SHOW_ARTISTS)
val showMode: LiveData<ShowMode> get() = mShowMode
private val mSortMode = MutableLiveData(SortMode.ALPHA_DOWN)

View file

@ -45,7 +45,6 @@ data class Song(
* @property year The year this album was released. 0 if there is none in the metadata.
* @property artist The Album's parent [Artist]. use this instead of [artistId]
* @property songs The Album's child [Song]s.
* @property numSongs The amount of songs in an Album.
* @property totalDuration The combined duration of all of the album's child songs, formatted.
* @author OxygenCobalt
*/
@ -59,7 +58,6 @@ data class Album(
lateinit var artist: Artist
val songs = mutableListOf<Song>()
val numSongs: Int get() = songs.size
val totalDuration: String by lazy {
var seconds: Long = 0
songs.forEach {
@ -80,15 +78,7 @@ data class Artist(
val albums = mutableListOf<Album>()
val genres = mutableListOf<Genre>()
val numAlbums: Int get() = albums.size
val numSongs: Int by lazy {
var num = 0
albums.forEach {
num += it.numSongs
}
num
}
val songs: MutableList<Song> by lazy {
val songs: List<Song> by lazy {
val songs = mutableListOf<Song>()
albums.forEach {
songs.addAll(it.songs)
@ -109,22 +99,14 @@ data class Genre(
) : BaseModel() {
val artists = mutableListOf<Artist>()
val numArtists: Int get() = artists.size
val numAlbums: Int by lazy {
var num = 0
val albums: List<Album> by lazy {
val albums = mutableListOf<Album>()
artists.forEach {
num += it.numAlbums
albums.addAll(it.albums)
}
num
albums
}
val numSongs: Int by lazy {
var num = 0
artists.forEach {
num += it.numSongs
}
num
}
val songs: MutableList<Song> by lazy {
val songs: List<Song> by lazy {
val songs = mutableListOf<Song>()
artists.forEach {
songs.addAll(it.songs)

View file

@ -92,10 +92,10 @@ fun Int.toYear(context: Context): String {
@BindingAdapter("genreCounts")
fun TextView.bindGenreCounts(genre: Genre) {
val artists = context.resources.getQuantityString(
R.plurals.format_artist_count, genre.numArtists, genre.numArtists
R.plurals.format_artist_count, genre.artists.size, genre.artists.size
)
val albums = context.resources.getQuantityString(
R.plurals.format_album_count, genre.numAlbums, genre.numAlbums
R.plurals.format_album_count, genre.albums.size, genre.albums.size
)
text = context.getString(R.string.format_double_counts, artists, albums)
@ -116,10 +116,10 @@ fun TextView.bindArtistGenre(artist: Artist) {
@BindingAdapter("artistCounts")
fun TextView.bindArtistCounts(artist: Artist) {
val albums = context.resources.getQuantityString(
R.plurals.format_album_count, artist.numAlbums, artist.numAlbums
R.plurals.format_album_count, artist.albums.size, artist.albums.size
)
val songs = context.resources.getQuantityString(
R.plurals.format_song_count, artist.numSongs, artist.numSongs
R.plurals.format_song_count, artist.songs.size, artist.songs.size
)
text = context.getString(R.string.format_double_counts, albums, songs)
@ -133,7 +133,7 @@ fun TextView.bindAllAlbumDetails(album: Album) {
album.year.toYear(context),
context.resources.getQuantityString(
R.plurals.format_song_count,
album.numSongs, album.numSongs
album.songs.size, album.songs.size
),
album.totalDuration
)
@ -147,7 +147,7 @@ fun TextView.bindAlbumInfo(album: Album) {
album.artist.name,
context.resources.getQuantityString(
R.plurals.format_song_count,
album.numSongs, album.numSongs
album.songs.size, album.songs.size
)
)
}

View file

@ -3,7 +3,6 @@ package org.oxycblt.auxio.music.coil
import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import android.util.Log
import android.widget.ImageView
import androidx.core.graphics.drawable.toBitmap
import androidx.databinding.BindingAdapter
@ -16,7 +15,7 @@ import org.oxycblt.auxio.music.Genre
import org.oxycblt.auxio.music.Song
// Get a bitmap for a song, onDone will be called when the bitmap is loaded.
// Don't use this on UI elements, thats what the BindingAdapters are for.
// Don't use this on UI elements, that's what the BindingAdapters are for.
fun getBitmap(song: Song, context: Context, onDone: (Bitmap) -> Unit) {
Coil.enqueue(
ImageRequest.Builder(context)
@ -57,7 +56,7 @@ fun ImageView.bindArtistImage(artist: Artist) {
val request: ImageRequest
// If there is more than one album, then create a mosaic of them.
if (artist.numAlbums >= 4) {
if (artist.albums.size >= 4) {
val uris = mutableListOf<Uri>()
for (i in 0..3) {
@ -93,11 +92,9 @@ fun ImageView.bindArtistImage(artist: Artist) {
fun ImageView.bindGenreImage(genre: Genre) {
val request: ImageRequest
if (genre.numArtists >= 4) {
if (genre.artists.size >= 4) {
val uris = mutableListOf<Uri>()
Log.d(this::class.simpleName, genre.numAlbums.toString())
// Get the Nth cover from each artist, if possible.
for (i in 0..3) {
val artist = genre.artists[i]

View file

@ -21,7 +21,7 @@ enum class MusicLoaderResponse {
// Class that loads music from the FileSystem.
// TODO: Add custom artist images from the filesystem
// TODO: Move genre loading of songs [Loads would take longer though]
// TODO: Move genre loading to songs [Loads would take longer though]
class MusicLoader(
private val resolver: ContentResolver,
@ -219,7 +219,7 @@ class MusicLoader(
}
albums = albums.distinctBy {
it.name to it.artistId to it.year to it.numSongs
it.name to it.artistId to it.year
}.toMutableList()
Log.d(

View file

@ -57,8 +57,6 @@ fun NotificationManager.createMediaNotification(
PendingIntent.FLAG_UPDATE_CURRENT
)
// TODO: Things that probably aren't possible but would be nice
// - Playing intent takes you to PlaybackFragment instead of MainFragment
return NotificationCompat.Builder(context, NotificationUtils.CHANNEL_ID)
.setSmallIcon(R.drawable.ic_song)
.setStyle(
@ -124,7 +122,7 @@ fun NotificationCompat.Builder.updateMode(context: Context) {
// If playing from all songs, set the subtext as that, otherwise the currently played parent.
if (playbackManager.mode == PlaybackMode.ALL_SONGS) {
setSubText(context.getString(R.string.title_all_songs))
setSubText(context.getString(R.string.label_all_songs))
} else {
setSubText(playbackManager.parent!!.name)
}

View file

@ -158,7 +158,7 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
}
}
// Updates for the current duration TextView/Seekbar
// Updates for the current duration TextView/SeekBar
playbackModel.formattedPosition.observe(viewLifecycleOwner) {
binding.playbackDurationCurrent.text = it
}

View file

@ -80,20 +80,21 @@ class QueueAdapter(
fun removeItem(adapterIndex: Int) {
data.removeAt(adapterIndex)
notifyItemRemoved(adapterIndex)
// Check for two things:
// If the data from the next queue is now entirely empty [Signified by a header at the end]
// Or if the data from the last queue is now entirely empty [Signified by there being 2 headers with no items in between]
if (data[data.lastIndex] is Header) {
val lastIndex = data.lastIndex
// TODO: Do notifyItemRangeRemoved instead of notifyItemRemoved
data.removeAt(lastIndex)
notifyItemRemoved(lastIndex)
notifyItemRangeRemoved(lastIndex, 2)
} else if (data.lastIndex >= 1 && data[0] is Header && data[1] is Header) {
data.removeAt(0)
notifyItemRemoved(0)
notifyItemRangeRemoved(0, 2)
} else {
notifyItemRemoved(adapterIndex)
}
}

View file

@ -85,7 +85,7 @@ class QueueFragment : Fragment() {
name = getString(
R.string.format_next_from,
if (playbackModel.mode.value == PlaybackMode.ALL_SONGS)
getString(R.string.title_all_songs)
getString(R.string.label_all_songs)
else
playbackModel.parent.value!!.name
)

View file

@ -133,7 +133,7 @@ class PlaybackStateManager private constructor() {
PlaybackMode.IN_ARTIST -> {
mParent = song.album.artist
mQueue = song.album.artist.songs
mQueue = song.album.artist.songs.toMutableList()
}
PlaybackMode.IN_ALBUM -> {
@ -425,7 +425,7 @@ class PlaybackStateManager private constructor() {
}
// --- PERSISTENCE FUNCTIONS ---
// TODO: Implement a fast queue save function that can be enabled in settings
// TODO: Implement a fast queue save function
suspend fun saveStateToDatabase(context: Context) {
Log.d(this::class.simpleName, "Saving state to DB.")
@ -557,15 +557,15 @@ class PlaybackStateManager private constructor() {
// Traverse albums and then album songs instead of just the songs, as its faster.
musicStore.albums.find { it.id == item.albumId }
?.songs?.find { it.id == item.songId }?.let {
mQueue.add(it)
}
mQueue.add(it)
}
}
userQueueItems.forEach { item ->
musicStore.albums.find { it.id == item.albumId }
?.songs?.find { it.id == item.songId }?.let {
mUserQueue.add(it)
}
mUserQueue.add(it)
}
}
forceQueueUpdate()

View file

@ -6,7 +6,7 @@ import org.oxycblt.auxio.music.BaseModel
// Base Diff callback
class DiffCallback<T : BaseModel> : DiffUtil.ItemCallback<T>() {
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean {
return oldItem == newItem
return oldItem.hashCode() == newItem.hashCode()
}
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean {

View file

@ -43,7 +43,7 @@ fun ImageButton.disable(context: Context) {
}
fun String.createToast(context: Context) {
Toast.makeText(context, this, Toast.LENGTH_SHORT).show()
Toast.makeText(context.applicationContext, this, Toast.LENGTH_SHORT).show()
}
// Apply a custom vertical divider

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:gravity="center"
android:left="16dp"
android:right="16dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />
<corners android:radius="4dp" />
<size android:height="3dp" />
</shape>
</item>
</layer-list>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.fragment.app.FragmentContainerView android:id="@+id/main_nav_host"
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="androidx.navigation.fragment.NavHostFragment"

View file

@ -34,7 +34,7 @@
app:menu="@menu/menu_album_actions"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Header"
app:navigationIcon="@drawable/ic_back"
app:title="@string/title_library_fragment" />
app:title="@string/label_library" />
<androidx.core.widget.NestedScrollView
android:id="@+id/nested_scroll"

View file

@ -34,7 +34,7 @@
app:menu="@menu/menu_detail"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Header"
app:navigationIcon="@drawable/ic_back"
app:title="@string/title_library_fragment" />
app:title="@string/label_library" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"

View file

@ -34,7 +34,7 @@
app:menu="@menu/menu_detail"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Header"
app:navigationIcon="@drawable/ic_back"
app:title="@string/title_library_fragment" />
app:title="@string/label_library" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
@ -96,7 +96,7 @@
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="?android:attr/textColorSecondary"
android:layout_marginStart="@dimen/margin_medium"
android:text="@{@plurals/format_song_count(genre.numSongs, genre.numSongs)}"
android:text="@{@plurals/format_song_count(genre.songs.size, genre.songs.size)}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/genre_counts"
tools:text="80 Songs" />

View file

@ -20,7 +20,7 @@
app:popupTheme="@style/AppThemeOverlay.Popup"
app:menu="@menu/menu_library"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Header"
app:title="@string/title_library_fragment" />
app:title="@string/label_library" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/library_recycler"

View file

@ -35,7 +35,7 @@
app:navigationIcon="@drawable/ic_down"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="@string/title_playback"
app:title="@string/label_playback"
app:menu="@menu/menu_playback"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Header" />

View file

@ -18,7 +18,7 @@
android:elevation="@dimen/elevation_normal"
app:menu="@menu/menu_songs"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Header"
app:title="@string/title_all_songs" />
app:title="@string/label_all_songs" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/song_recycler"

View file

@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/library_fragment"
android:title="@string/title_library_fragment"
android:title="@string/label_library"
android:icon="@drawable/ic_library" />
<item
android:id="@+id/songs_fragment"

View file

@ -2,7 +2,6 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_explore"
app:startDestination="@id/library_fragment">
<fragment

View file

@ -2,7 +2,6 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_main"
app:startDestination="@id/loading_fragment">
<fragment
android:id="@+id/loading_fragment"

View file

@ -4,21 +4,14 @@
<dimen name="padding_tiny">4dp</dimen>
<dimen name="padding_small">8dp</dimen>
<dimen name="padding_medium">16dp</dimen>
<dimen name="padding_mid_large">24dp</dimen>
<dimen name="padding_large">32dp</dimen>
<dimen name="padding_huge">64dp</dimen>
<!-- Margin namespace | Dimens for margin attributes -->
<dimen name="margin_tiny">4dp</dimen>
<dimen name="margin_small">8dp</dimen>
<dimen name="margin_mid_small">10dp</dimen>
<dimen name="margin_medium">16dp</dimen>
<dimen name="margin_mid_large">24dp</dimen>
<dimen name="margin_large">32dp</dimen>
<dimen name="margin_huge">64dp</dimen>
<!-- Height Namespace | Height for UI elements -->
<dimen name="height_tab_menu">40dp</dimen>
<dimen name="height_compact_progress">2dp</dimen>
<!-- Width Namespace | Width for UI elements -->

View file

@ -2,18 +2,11 @@
<resources>
<string name="app_name">Auxio</string>
<!-- Title Namespace | Toolbar titles -->
<string name="title_library_fragment">Library</string>
<string name="title_all_songs">All Songs</string>
<string name="title_playback">Now Playing</string>
<!-- Error Namespace | Error Labels -->
<string name="error_no_music">No music found.</string>
<string name="error_music_load_failed">Music loading failed.</string>
<string name="error_no_perms">Permissions to read storage are needed.</string>
<!-- Label Namespace | Static Labels -->
<string name="label_retry">Retry</string>
<string name="label_library">Library</string>
<string name="label_all_songs">All Songs</string>
<string name="label_playback">Now Playing</string>
<string name="label_grant">Grant</string>
<string name="label_genres">Genres</string>
<string name="label_artists">Artists</string>
@ -28,7 +21,6 @@
<string name="label_play_artist">Play from artist</string>
<string name="label_play_album">Play from album</string>
<string name="label_go_artist">Go to artist</string>
<string name="label_go_album">Go to album</string>
<string name="label_queue">Queue</string>
<string name="label_queue_add">Add to queue</string>
<string name="label_queue_added">Added to queue</string>
@ -36,6 +28,11 @@
<string name="label_channel">Music Playback</string>
<string name="label_service_playback">The music playback service for Auxio.</string>
<!-- Error Namespace | Error Labels -->
<string name="error_no_music">No music found.</string>
<string name="error_music_load_failed">Music loading failed.</string>
<string name="error_no_perms">Permissions to read storage are needed.</string>
<!-- Hint Namespace | EditText Hints -->
<string name="hint_search_library">Search Library…</string>

View file

@ -48,12 +48,13 @@
</style>
<!--
Fix to get QueueFragment to not overlap the Status Bar or Navigation Bar
Fix to get QueueFragment to not overlap the Status Bar or Navigation Bar [Currently unused but still here]
https://stackoverflow.com/a/57790787/14143986
-->
<style name="Theme.BottomSheetFix" parent="@style/Theme.Design.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:navigationBarColor">@color/background</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
-->
</resources>