fix empty playlists thumbnail

This commit is contained in:
Bnyro 2022-08-06 19:06:10 +02:00
parent 35fc7ddef4
commit 5446d3257f

View File

@ -44,11 +44,13 @@ class PlaylistsAdapter(
override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) { override fun onBindViewHolder(holder: PlaylistsViewHolder, position: Int) {
val playlist = playlists[position] val playlist = playlists[position]
holder.binding.apply { holder.binding.apply {
ConnectionHelper.loadImage(playlist.thumbnail, playlistThumbnail)
// set imageview drawable as empty playlist if imageview empty // set imageview drawable as empty playlist if imageview empty
if (playlistThumbnail.drawable == null) { Log.e(TAG, playlist.thumbnail.toString())
if (playlist.thumbnail!!.split("/").size <= 4) {
playlistThumbnail.setImageResource(R.drawable.ic_empty_playlist) playlistThumbnail.setImageResource(R.drawable.ic_empty_playlist)
playlistThumbnail.setBackgroundColor(R.attr.colorSurface) playlistThumbnail.setBackgroundColor(R.attr.colorSurface)
} else {
ConnectionHelper.loadImage(playlist.thumbnail, playlistThumbnail)
} }
playlistTitle.text = playlist.name playlistTitle.text = playlist.name
deletePlaylist.setOnClickListener { deletePlaylist.setOnClickListener {
@ -56,8 +58,8 @@ class PlaylistsAdapter(
builder.setTitle(R.string.deletePlaylist) builder.setTitle(R.string.deletePlaylist)
builder.setMessage(R.string.areYouSure) builder.setMessage(R.string.areYouSure)
builder.setPositiveButton(R.string.yes) { _, _ -> builder.setPositiveButton(R.string.yes) { _, _ ->
val token = PreferenceHelper.getToken() PreferenceHelper.getToken()
deletePlaylist(playlist.id!!, token, position) deletePlaylist(playlist.id!!, position)
} }
builder.setNegativeButton(R.string.cancel, null) builder.setNegativeButton(R.string.cancel, null)
builder.show() builder.show()
@ -68,11 +70,14 @@ class PlaylistsAdapter(
} }
} }
private fun deletePlaylist(id: String, token: String, position: Int) { private fun deletePlaylist(id: String, position: Int) {
fun run() { fun run() {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
val response = try { val response = try {
RetrofitInstance.authApi.deletePlaylist(token, PlaylistId(id)) RetrofitInstance.authApi.deletePlaylist(
PreferenceHelper.getToken(),
PlaylistId(id)
)
} catch (e: IOException) { } catch (e: IOException) {
println(e) println(e)
Log.e(TAG, "IOException, you might not have internet connection") Log.e(TAG, "IOException, you might not have internet connection")
@ -83,9 +88,7 @@ class PlaylistsAdapter(
} }
try { try {
if (response.message == "ok") { if (response.message == "ok") {
Log.d(TAG, "deleted!")
playlists.removeAt(position) playlists.removeAt(position)
// FIXME: This needs to run on UI thread?
activity.runOnUiThread { notifyDataSetChanged() } activity.runOnUiThread { notifyDataSetChanged() }
} }
} catch (e: Exception) { } catch (e: Exception) {