@@ -101,7 +101,7 @@ dependencies {
compile 'com.github.inorichi:subsampling-scale-image-view:44aa442'
// Android support library
- final support_library_version = '25.1.0'
+ final support_library_version = '25.1.1'
compile "com.android.support:support-v4:$support_library_version"
compile "com.android.support:appcompat-v7:$support_library_version"
compile "com.android.support:cardview-v7:$support_library_version"
@@ -486,14 +486,10 @@ open class CatalogueFragment : BaseRxFragment<CataloguePresenter>(),
* @return the holder of the manga or null if it's not bound.
*/
private fun getHolder(manga: Manga): CatalogueHolder? {
- val layoutManager = recycler.layoutManager as LinearLayoutManager
- val firstVisiblePos = layoutManager.findFirstVisibleItemPosition()
- val lastVisiblePos = layoutManager.findLastVisibleItemPosition()
-
- (firstVisiblePos..lastVisiblePos-1).forEach { i ->
- val item = adapter.getItem(i) as? CatalogueItem
+ adapter.allBoundViewHolders.forEach { holder ->
+ val item = adapter.getItem(holder.adapterPosition) as? CatalogueItem
if (item != null && item.manga.id!! == manga.id!!) {
- return recycler.findViewHolderForLayoutPosition(i) as? CatalogueHolder
+ return holder as CatalogueHolder
}
@@ -4,7 +4,9 @@ import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.davidea.flexibleadapter.FlexibleAdapter
+import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
+import eu.kanade.tachiyomi.widget.StateImageViewTarget
import kotlinx.android.synthetic.main.item_catalogue_grid.view.*
/**
@@ -42,8 +44,9 @@ class CatalogueGridHolder(private val view: View, private val adapter: FlexibleA
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.centerCrop()
.skipMemoryCache(true)
+ .error(R.drawable.ic_broken_image_grey_24dp)
.placeholder(android.R.color.transparent)
- .into(view.thumbnail)
+ .into(StateImageViewTarget(view.thumbnail, view.progress))
@@ -1,3 +1,5 @@
+@file:Suppress("NOTHING_TO_INLINE")
+
package eu.kanade.tachiyomi.util
import android.graphics.Color
@@ -28,4 +30,16 @@ inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Sn
snack.f()
snack.show()
return snack
-}
+}
+inline fun View.visible() {
+ visibility = View.VISIBLE
+inline fun View.invisible() {
+ visibility = View.INVISIBLE
+inline fun View.gone() {
+ visibility = View.GONE
@@ -0,0 +1,49 @@
+package eu.kanade.tachiyomi.widget
+import android.graphics.drawable.Drawable
+import android.widget.ImageView
+import android.widget.ImageView.ScaleType
+import android.widget.ProgressBar
+import com.bumptech.glide.load.resource.drawable.GlideDrawable
+import com.bumptech.glide.request.animation.GlideAnimation
+import com.bumptech.glide.request.target.GlideDrawableImageViewTarget
+import eu.kanade.tachiyomi.util.gone
+import eu.kanade.tachiyomi.util.visible
+/**
+ * A glide target to display an image with an optional progress bar and a configurable scale type
+ * for the error drawable.
+ *
+ * @param view the view where the image will be loaded
+ * @param progress an optional progress bar to show when the image is loading.
+ * @param errorScaleType the scale type for the error drawable, [ScaleType.CENTER] by default.
+ */
+class StateImageViewTarget(view: ImageView,
+ val progress: ProgressBar? = null,
+ val errorScaleType: ScaleType = ScaleType.CENTER) :
+ GlideDrawableImageViewTarget(view) {
+ private val imageScaleType = view.scaleType
+ override fun onLoadStarted(placeholder: Drawable?) {
+ progress?.visible()
+ super.onLoadStarted(placeholder)
+ }
+ override fun onLoadFailed(e: Exception?, errorDrawable: Drawable?) {
+ progress?.gone()
+ view.scaleType = errorScaleType
+ super.onLoadFailed(e, errorDrawable)
+ override fun onLoadCleared(placeholder: Drawable?) {
+ super.onLoadCleared(placeholder)
+ override fun onResourceReady(resource: GlideDrawable?, animation: GlideAnimation<in GlideDrawable>?) {
+ view.scaleType = imageScaleType
+ super.onResourceReady(resource, animation)
@@ -0,0 +1,10 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:alpha=".38"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M21,5v6.59l-3,-3.01 -4,4.01 -4,-4 -4,4 -3,-3.01L3,5c0,-1.1 0.9,-2 2,-2h14c1.1,0 2,0.9 2,2zM18,11.42l3,3.01L21,19c0,1.1 -0.9,2 -2,2L5,21c-1.1,0 -2,-0.9 -2,-2v-6.58l3,2.99 4,-4 4,4 4,-3.99z"/>
+</vector>
@@ -58,6 +58,14 @@
android:shadowRadius="4"
tools:text="Sample name"/>
+ <ProgressBar
+ android:id="@+id/progress"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ style="?android:attr/progressBarStyleSmall"
+ android:visibility="gone"
+ android:layout_gravity="center"/>
</FrameLayout>