Add proper placeholders
Add placeholders for album art, artist name, and album name if there arent any from the file itself.
This commit is contained in:
@@ -3,6 +3,7 @@ package org.oxycblt.auxio
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@@ -10,7 +11,7 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
|
||||
Log.d(this::class.simpleName, "Activity Created.")
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@ import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentLibraryBinding
|
||||
import org.oxycblt.auxio.recycler.adapters.AlbumAdapter
|
||||
@@ -23,11 +19,6 @@ class LibraryFragment : Fragment() {
|
||||
ViewModelProvider(this).get(LibraryViewModel::class.java)
|
||||
}
|
||||
|
||||
private val inflateJob = Job()
|
||||
private val mainScope = CoroutineScope(
|
||||
inflateJob + Dispatchers.Main
|
||||
)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -37,14 +28,7 @@ class LibraryFragment : Fragment() {
|
||||
inflater, R.layout.fragment_library, container, false
|
||||
)
|
||||
|
||||
// Offload the initial layout creation to a coroutine so that it doesn't hold up
|
||||
// the UI thread. Hacky but it results in a smoother experience.
|
||||
mainScope.launch {
|
||||
binding.libraryRecycler.adapter = AlbumAdapter(libraryModel.albums.value!!)
|
||||
binding.libraryRecycler.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
// binding.libraryRecycler.adapter = adapter
|
||||
binding.libraryRecycler.adapter = AlbumAdapter(libraryModel.albums.value!!)
|
||||
binding.libraryRecycler.applyDivider()
|
||||
binding.libraryRecycler.setHasFixedSize(true)
|
||||
|
||||
@@ -52,10 +36,4 @@ class LibraryFragment : Fragment() {
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
|
||||
inflateJob.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class MusicRepository {
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
|
||||
val loader = MusicLoader(app)
|
||||
val loader = MusicLoader(app.contentResolver)
|
||||
|
||||
if (loader.response == MusicLoaderResponse.DONE) {
|
||||
// If the loading succeeds, then process the songs and set them.
|
||||
|
||||
@@ -79,7 +79,7 @@ fun ImageView.getCoverArt(any: Any) {
|
||||
load(uri) {
|
||||
crossfade(true)
|
||||
placeholder(android.R.color.transparent)
|
||||
error(android.R.color.transparent)
|
||||
error(R.drawable.music_icon)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,3 +92,19 @@ fun TextView.getAlbumSongs(album: Album) {
|
||||
context.getString(R.string.format_multi_song_count, album.numSongs.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@BindingAdapter("songInfo")
|
||||
fun TextView.getSongInfo(song: Song) {
|
||||
var artist = song.album.artist.name
|
||||
var album = song.album.title
|
||||
|
||||
if (artist == "") {
|
||||
artist = context.getString(R.string.label_unknown_artist)
|
||||
}
|
||||
|
||||
if (album == "") {
|
||||
album = context.getString(R.string.label_unknown_album)
|
||||
}
|
||||
|
||||
text = context.getString(R.string.format_song_info, artist, album)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.oxycblt.auxio.music.processing
|
||||
|
||||
import android.app.Application
|
||||
import android.content.ContentResolver
|
||||
import android.database.Cursor
|
||||
import android.provider.MediaStore.Audio.Albums
|
||||
@@ -21,7 +20,7 @@ enum class MusicLoaderResponse {
|
||||
|
||||
// Class that loads music from the FileSystem.
|
||||
// FIXME: This thing probably has some memory leaks *somewhere*
|
||||
class MusicLoader(app: Application) {
|
||||
class MusicLoader(private val resolver: ContentResolver) {
|
||||
|
||||
var genres = mutableListOf<Genre>()
|
||||
var artists = mutableListOf<Artist>()
|
||||
@@ -34,7 +33,6 @@ class MusicLoader(app: Application) {
|
||||
private var songCursor: Cursor? = null
|
||||
|
||||
val response: MusicLoaderResponse
|
||||
private val resolver: ContentResolver = app.contentResolver
|
||||
|
||||
init {
|
||||
response = findMusic()
|
||||
|
||||
@@ -8,9 +8,6 @@ import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentSongsBinding
|
||||
import org.oxycblt.auxio.recycler.adapters.SongAdapter
|
||||
@@ -18,11 +15,6 @@ import org.oxycblt.auxio.recycler.applyDivider
|
||||
|
||||
class SongsFragment : Fragment() {
|
||||
|
||||
private val inflateJob = Job()
|
||||
private val mainScope = CoroutineScope(
|
||||
inflateJob + Dispatchers.Main
|
||||
)
|
||||
|
||||
private val songsModel: SongsViewModel by lazy {
|
||||
ViewModelProvider(this).get(SongsViewModel::class.java)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user