24
24
import org .thoughtcrime .securesms .R ;
25
25
import org .thoughtcrime .securesms .color .MaterialColor ;
26
26
import org .thoughtcrime .securesms .giph .model .GiphyImage ;
27
+ import org .thoughtcrime .securesms .giph .model .GiphyPaddedUrl ;
27
28
import org .thoughtcrime .securesms .mms .GlideApp ;
28
29
import org .thoughtcrime .securesms .mms .GlideRequests ;
29
30
import org .thoughtcrime .securesms .util .Util ;
30
31
import org .thoughtcrime .securesms .util .ViewUtil ;
31
32
33
+ import java .io .ByteArrayOutputStream ;
32
34
import java .io .File ;
35
+ import java .io .PrintWriter ;
33
36
import java .util .List ;
34
37
import java .util .concurrent .ExecutionException ;
35
38
@@ -69,7 +72,7 @@ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Dra
69
72
Log .w (TAG , e );
70
73
71
74
synchronized (this ) {
72
- if (image .getGifUrl ().equals (model )) {
75
+ if (new GiphyPaddedUrl ( image .getGifUrl (), image . getGifSize () ).equals (model )) {
73
76
this .modelReady = true ;
74
77
notifyAll ();
75
78
}
@@ -81,7 +84,7 @@ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Dra
81
84
@ Override
82
85
public boolean onResourceReady (Drawable resource , Object model , Target <Drawable > target , DataSource dataSource , boolean isFirstResource ) {
83
86
synchronized (this ) {
84
- if (image .getGifUrl ().equals (model )) {
87
+ if (new GiphyPaddedUrl ( image .getGifUrl (), image . getGifSize () ).equals (model )) {
85
88
this .modelReady = true ;
86
89
notifyAll ();
87
90
}
@@ -99,7 +102,8 @@ public File getFile(boolean forMms) throws ExecutionException, InterruptedExcept
99
102
}
100
103
101
104
return Glide .with (context )
102
- .load (forMms ? image .getGifMmsUrl () : image .getGifUrl ())
105
+ .load (forMms ? new GiphyPaddedUrl (image .getGifMmsUrl (), image .getMmsGifSize ()) :
106
+ new GiphyPaddedUrl (image .getGifUrl (), image .getGifSize ()))
103
107
.downloadOnly (Target .SIZE_ORIGINAL , Target .SIZE_ORIGINAL )
104
108
.get ();
105
109
}
@@ -144,18 +148,19 @@ public void onBindViewHolder(GiphyViewHolder holder, int position) {
144
148
holder .gifProgress .setVisibility (View .GONE );
145
149
146
150
RequestBuilder <Drawable > thumbnailRequest = GlideApp .with (context )
147
- .load (image .getStillUrl ())
151
+ .load (new GiphyPaddedUrl ( image .getStillUrl (), image . getStillSize () ))
148
152
.diskCacheStrategy (DiskCacheStrategy .ALL );
149
153
150
154
if (Util .isLowMemory (context )) {
151
- glideRequests .load (image .getStillUrl ())
155
+ glideRequests .load (new GiphyPaddedUrl ( image .getStillUrl (), image . getStillSize () ))
152
156
.placeholder (new ColorDrawable (Util .getRandomElement (MaterialColor .values ()).toConversationColor (context )))
153
157
.diskCacheStrategy (DiskCacheStrategy .ALL )
158
+ .listener (holder )
154
159
.into (holder .thumbnail );
155
160
156
161
holder .setModelReady ();
157
162
} else {
158
- glideRequests .load (image .getGifUrl ())
163
+ glideRequests .load (new GiphyPaddedUrl ( image .getGifUrl (), image . getGifSize () ))
159
164
.thumbnail (thumbnailRequest )
160
165
.placeholder (new ColorDrawable (Util .getRandomElement (MaterialColor .values ()).toConversationColor (context )))
161
166
.diskCacheStrategy (DiskCacheStrategy .ALL )
0 commit comments