1
1
package fr .free .nrw .commons .media ;
2
2
3
3
import android .annotation .SuppressLint ;
4
+ import android .graphics .drawable .Animatable ;
4
5
import android .app .AlertDialog ;
5
6
import android .content .Intent ;
7
+ import android .content .Context ;
6
8
import android .net .Uri ;
7
9
import android .os .Bundle ;
8
10
import android .text .Editable ;
23
25
24
26
import com .facebook .drawee .backends .pipeline .Fresco ;
25
27
import com .facebook .drawee .interfaces .DraweeController ;
28
+ import com .facebook .drawee .controller .BaseControllerListener ;
29
+ import com .facebook .drawee .controller .ControllerListener ;
26
30
import com .facebook .drawee .view .SimpleDraweeView ;
31
+ import com .facebook .imagepipeline .image .ImageInfo ;
27
32
import com .facebook .imagepipeline .request .ImageRequest ;
28
33
29
34
import org .apache .commons .lang3 .StringUtils ;
39
44
import butterknife .BindView ;
40
45
import butterknife .ButterKnife ;
41
46
import butterknife .OnClick ;
47
+ import androidx .annotation .Nullable ;
42
48
import fr .free .nrw .commons .Media ;
43
49
import fr .free .nrw .commons .MediaDataExtractor ;
44
50
import fr .free .nrw .commons .R ;
@@ -97,10 +103,8 @@ public static MediaDetailFragment forMedia(int index, boolean editable, boolean
97
103
98
104
private int initialListTop = 0 ;
99
105
100
- @ BindView (R .id .mediaDetailImage )
106
+ @ BindView (R .id .mediaDetailImageView )
101
107
SimpleDraweeView image ;
102
- @ BindView (R .id .mediaDetailSpacer )
103
- MediaDetailSpacer spacer ;
104
108
@ BindView (R .id .mediaDetailTitle )
105
109
TextView title ;
106
110
@ BindView (R .id .mediaDetailDesc )
@@ -197,36 +201,18 @@ && getParentFragment() instanceof MediaDetailPagerFragment) {
197
201
// Progressively darken the image in the background when we scroll detail pane up
198
202
scrollListener = this ::updateTheDarkness ;
199
203
view .getViewTreeObserver ().addOnScrollChangedListener (scrollListener );
200
-
201
- // Layout layoutListener to size the spacer item relative to the available space.
202
- // There may be a .... better way to do this.
203
- layoutListener = new ViewTreeObserver .OnGlobalLayoutListener () {
204
- private int currentHeight = -1 ;
205
-
206
- @ Override
207
- public void onGlobalLayout () {
208
- int viewHeight = view .getHeight ();
209
- //int textHeight = title.getLineHeight();
210
- int paddingDp = 112 ;
211
- float paddingPx = TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , paddingDp , getResources ().getDisplayMetrics ());
212
- int newHeight = viewHeight - Math .round (paddingPx );
213
-
214
- if (newHeight != currentHeight ) {
215
- currentHeight = newHeight ;
216
- ViewGroup .LayoutParams params = spacer .getLayoutParams ();
217
- params .height = newHeight ;
218
- spacer .setLayoutParams (params );
219
-
220
- scrollView .scrollTo (0 , initialListTop );
221
- }
222
- }
223
- };
224
- view .getViewTreeObserver ().addOnGlobalLayoutListener (layoutListener );
225
204
locale = getResources ().getConfiguration ().locale ;
226
-
227
205
return view ;
228
206
}
229
207
208
+ @ OnClick (R .id .mediaDetailImageView )
209
+ public void launchZoomActivity (View view ) {
210
+ Context ctx = view .getContext ();
211
+ ctx .startActivity (
212
+ new Intent (ctx ,ZoomableActivity .class ).setData (Uri .parse (media .getImageUrl ()))
213
+ );
214
+ }
215
+
230
216
@ Override
231
217
public void onResume () {
232
218
super .onResume ();
@@ -255,6 +241,26 @@ private void displayMediaDetails() {
255
241
compositeDisposable .add (disposable );
256
242
}
257
243
244
+ private void updateAspectRatio (ImageInfo imageInfo ) {
245
+ if (imageInfo != null ) {
246
+ int finalHeight = (scrollView .getWidth ()*imageInfo .getHeight ()) / imageInfo .getWidth ();
247
+ ViewGroup .LayoutParams params = image .getLayoutParams ();
248
+ params .height = finalHeight ;
249
+ image .setLayoutParams (params );
250
+ }
251
+ }
252
+
253
+ private final ControllerListener aspectRatioListener = new BaseControllerListener <ImageInfo >() {
254
+ @ Override
255
+ public void onIntermediateImageSet (String id , @ Nullable ImageInfo imageInfo ) {
256
+ updateAspectRatio (imageInfo );
257
+ }
258
+ @ Override
259
+ public void onFinalImageSet (String id , @ Nullable ImageInfo imageInfo , @ Nullable Animatable animatable ) {
260
+ updateAspectRatio (imageInfo );
261
+ }
262
+ };
263
+
258
264
/**
259
265
* Uses two image sources.
260
266
* - low resolution thumbnail is shown initially
@@ -264,6 +270,7 @@ private void setupImageView() {
264
270
DraweeController controller = Fresco .newDraweeControllerBuilder ()
265
271
.setLowResImageRequest (ImageRequest .fromUri (media .getThumbUrl ()))
266
272
.setImageRequest (ImageRequest .fromUri (media .getImageUrl ()))
273
+ .setControllerListener (aspectRatioListener )
267
274
.setOldController (image .getController ())
268
275
.build ();
269
276
image .setController (controller );
0 commit comments