Skip to content

Commit

Permalink
Bugfix?
Browse files Browse the repository at this point in the history
Now catching Glide exceptions and loading a default bitmap because
.error() didn't work quite as expected
  • Loading branch information
Carlos Perez committed Jul 9, 2022
1 parent d9d2f9d commit b029c03
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 16 deletions.
158 changes: 158 additions & 0 deletions albumplaceholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SubsonicClient(var initialAccount: Account) {
} catch (e: Exception) {
val placeholder = Glide.with(App.context)
.asBitmap()
.load(R.drawable.ic_album_art_fallback)
.load(R.drawable.ic_album_art_placeholder)
.submit()
placeholder.get()
}
Expand Down Expand Up @@ -503,11 +503,20 @@ class SubsonicClient(var initialAccount: Account) {
if (!File(getLocalCoverArtUri(id)).exists()) {
Log.i("Image saver", "Fetching image $id")
saveImage(
Glide.with(App.context)
.asBitmap()
.load(uriBuilder.toString()) // sample image
.submit()
.get(),
try {

Glide.with(App.context)
.asBitmap()
.load(uriBuilder.toString())
.submit()
.get()
} catch (e: Exception) {
Glide.with(App.context)
.asBitmap()
.load(R.drawable.ic_album_art_placeholder)
.submit()
.get()
},
getCoverArtsDirectory(),
getLocalCoverArtUri(id)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import tech.logica10.soniclair.R
import tech.logica10.soniclair.TvActivity
import tech.logica10.soniclair.extensions.loadUrl
import tech.logica10.soniclair.models.Album
import tech.logica10.soniclair.models.ICardViewModel
import tech.logica10.soniclair.models.Playlist
Expand Down Expand Up @@ -51,9 +52,6 @@ class SoniclairCardAdapter(

// Replace the contents of a view (invoked by the layout manager)
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
fun ImageView.loadUrl(url: String) {
Glide.with(context).load(url).into(this)
}
// Get element from your dataset at this position and replace the
// contents of the view with that element
viewHolder.firstLine.text = dataSet[position].firstLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import tech.logica10.soniclair.R
import tech.logica10.soniclair.extensions.loadUrl
import tech.logica10.soniclair.models.ICardViewModel


Expand Down Expand Up @@ -56,9 +57,7 @@ class SoniclairPlaylistItemAdapter(

// Replace the contents of a view (invoked by the layout manager)
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
fun ImageView.loadUrl(url: String) {
Glide.with(context).load(url).into(this)
}

// Get element from your dataset at this position and replace the
// contents of the view with that element
viewHolder.firstLine.text = dataSet[position].firstLine()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tech.logica10.soniclair.extensions

import android.widget.ImageView
import com.bumptech.glide.Glide
import tech.logica10.soniclair.R

fun ImageView.loadUrl(url: String) {
try {
Glide.with(context).load(url).into(this)
} catch (e: Exception) {
Glide.with(context).load(R.drawable.ic_album_art_placeholder).into(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.bumptech.glide.Glide
import com.getcapacitor.JSObject
import tech.logica10.soniclair.*
import tech.logica10.soniclair.adapters.SoniclairPlaylistItemAdapter
import tech.logica10.soniclair.extensions.loadUrl
import tech.logica10.soniclair.models.ICardViewModel
import kotlin.math.floor

Expand Down Expand Up @@ -44,10 +45,6 @@ class NowPlayingFragment(val bind: TvActivity.TvActivityBind, val client: Subson
Globals.UnregisterObserver(observer)
}

private fun ImageView.loadUrl(url: String) {
Glide.with(context).load(url).into(this)
}

inner class NowPlayingObserver : IBroadcastObserver {
override fun update(action: String?, value: String?) {
when (action) {
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit b029c03

@vercel
Copy link

@vercel vercel bot commented on b029c03 Jul 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

soniclair – ./

soniclair.vercel.app
soniclair-thelinkin3000.vercel.app
soniclair-git-main-thelinkin3000.vercel.app

Please sign in to comment.