@@ -8,12 +8,16 @@ import android.view.View
8
8
import android.view.ViewGroup
9
9
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
10
10
import android.widget.ImageView
11
- import com.bumptech.glide.load.DecodeFormat
12
11
import com.bumptech.glide.request.target.SimpleTarget
13
12
import com.bumptech.glide.request.transition.Transition
14
13
import com.davemorrissey.labs.subscaleview.ImageSource
15
14
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
15
+ import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder
16
+ import com.davemorrissey.labs.subscaleview.decoder.SkiaPooledImageRegionDecoder
16
17
import com.mikepenz.community_material_typeface_library.CommunityMaterial
18
+ import io.reactivex.Single
19
+ import io.reactivex.android.schedulers.AndroidSchedulers
20
+ import io.reactivex.schedulers.Schedulers
17
21
import io.reactivex.subjects.PublishSubject
18
22
import kotterknife.bindView
19
23
import me.proxer.app.GlideRequests
@@ -23,6 +27,7 @@ import me.proxer.app.manga.MangaAdapter.ViewHolder
23
27
import me.proxer.app.util.DeviceUtils
24
28
import me.proxer.app.util.extension.decodedName
25
29
import me.proxer.app.util.extension.setIconicsImage
30
+ import me.proxer.app.util.extension.subscribeAndLogErrors
26
31
import me.proxer.library.entity.manga.Page
27
32
import me.proxer.library.util.ProxerUrls
28
33
import java.io.File
@@ -69,8 +74,6 @@ class MangaAdapter(private val isVertical: Boolean) : BaseAdapter<Page, ViewHold
69
74
70
75
init {
71
76
image.setDoubleTapZoomDuration(shortAnimationTime)
72
- image.setBitmapDecoderClass(RapidImageDecoder ::class .java)
73
- image.setRegionDecoderClass(RapidImageRegionDecoder ::class .java)
74
77
75
78
errorIndicator.setIconicsImage(CommunityMaterial .Icon .cmd_refresh, 64 )
76
79
@@ -103,36 +106,46 @@ class MangaAdapter(private val isVertical: Boolean) : BaseAdapter<Page, ViewHold
103
106
image.maxScale = scale
104
107
}
105
108
109
+ if (item.name.endsWith(" png" )) {
110
+ image.setBitmapDecoderClass(RapidImageDecoder ::class .java)
111
+ image.setRegionDecoderClass(RapidImageRegionDecoder ::class .java)
112
+ } else {
113
+ image.setBitmapDecoderClass(SkiaImageDecoder ::class .java)
114
+ image.setRegionDecoderClass(SkiaPooledImageRegionDecoder ::class .java)
115
+ }
116
+
106
117
errorIndicator.visibility = View .GONE
107
118
image.visibility = View .VISIBLE
108
119
109
120
glide?.clear(glideTarget)
110
121
glideTarget = GlideFileTarget ()
111
122
112
123
glideTarget?.let { target ->
113
- glide?.download(ProxerUrls .mangaPageImage(server, entryId, id, item.decodedName).toString())
114
- ?.format(when (DeviceUtils .shouldShowHighQualityImages(image.context)) {
115
- true -> DecodeFormat .PREFER_ARGB_8888
116
- false -> DecodeFormat .PREFER_RGB_565
117
- })
124
+ glide
125
+ ?.download(ProxerUrls .mangaPageImage(server, entryId, id, item.decodedName).toString())
118
126
?.into(target)
119
127
}
120
128
}
121
129
122
130
internal inner class GlideFileTarget : SimpleTarget <File >() {
123
131
124
132
override fun onResourceReady (resource : File , transition : Transition <in File >? ) {
125
- image.setImage(ImageSource .uri(resource.path))
126
- image.setScaleAndCenter(0.2f , PointF (0f , 0f ))
127
-
128
- // Fade animations do not look good with the horizontal reader.
129
- if (isVertical) {
130
- image.apply { alpha = 0.2f }
131
- .animate()
132
- .alpha(1.0f )
133
- .setDuration(mediumAnimationTime.toLong())
134
- .start()
135
- }
133
+ Single .fromCallable { ImageSource .uri(resource.path) }
134
+ .subscribeOn(Schedulers .io())
135
+ .observeOn(AndroidSchedulers .mainThread())
136
+ .subscribeAndLogErrors { source ->
137
+ image.setImage(source)
138
+ image.setScaleAndCenter(0.2f , PointF (0f , 0f ))
139
+
140
+ // Fade animations do not look good with the horizontal reader.
141
+ if (isVertical) {
142
+ image.apply { alpha = 0.2f }
143
+ .animate()
144
+ .alpha(1.0f )
145
+ .setDuration(mediumAnimationTime.toLong())
146
+ .start()
147
+ }
148
+ }
136
149
}
137
150
138
151
override fun onLoadFailed (errorDrawable : Drawable ? ) {
0 commit comments