4
4
5
5
import android .annotation .SuppressLint ;
6
6
import android .content .Context ;
7
+ import android .net .Uri ;
7
8
import android .os .Bundle ;
8
9
import android .text .TextUtils ;
9
10
import android .util .DisplayMetrics ;
23
24
import butterknife .BindView ;
24
25
import butterknife .ButterKnife ;
25
26
import butterknife .OnClick ;
26
- import com .github .chrisbanes .photoview .PhotoView ;
27
+ import com .facebook .drawee .backends .pipeline .Fresco ;
28
+ import com .facebook .drawee .drawable .ScalingUtils .ScaleType ;
29
+ import com .facebook .drawee .generic .GenericDraweeHierarchy ;
30
+ import com .facebook .drawee .generic .GenericDraweeHierarchyBuilder ;
31
+ import com .facebook .drawee .interfaces .DraweeController ;
27
32
import com .jakewharton .rxbinding2 .widget .RxTextView ;
28
33
import fr .free .nrw .commons .R ;
29
34
import fr .free .nrw .commons .Utils ;
30
35
import fr .free .nrw .commons .filepicker .UploadableFile ;
31
36
import fr .free .nrw .commons .kvstore .JsonKvStore ;
32
37
import fr .free .nrw .commons .location .LatLng ;
38
+ import fr .free .nrw .commons .media .zoomControllers .zoomable .DoubleTapGestureListener ;
39
+ import fr .free .nrw .commons .media .zoomControllers .zoomable .ZoomableDraweeView ;
33
40
import fr .free .nrw .commons .nearby .Place ;
34
41
import fr .free .nrw .commons .settings .Prefs ;
35
42
import fr .free .nrw .commons .upload .Description ;
44
51
import fr .free .nrw .commons .utils .ImageUtils ;
45
52
import fr .free .nrw .commons .utils .ViewUtil ;
46
53
import io .reactivex .disposables .Disposable ;
54
+ import java .io .File ;
47
55
import java .util .ArrayList ;
48
56
import java .util .Arrays ;
49
57
import java .util .List ;
@@ -69,7 +77,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
69
77
@ BindView (R .id .rv_descriptions )
70
78
RecyclerView rvDescriptions ;
71
79
@ BindView (R .id .backgroundImage )
72
- PhotoView photoViewBackgroundImage ;
80
+ ZoomableDraweeView photoViewBackgroundImage ;
73
81
@ BindView (R .id .btn_next )
74
82
AppCompatButton btnNext ;
75
83
@ BindView (R .id .btn_previous )
@@ -164,11 +172,26 @@ private void init() {
164
172
btnCopyPreviousTitleDesc .setVisibility (View .VISIBLE );
165
173
}
166
174
167
- attachImageViewScaleChangeListener ();
168
-
169
175
addEtTitleTouchListener ();
170
176
}
171
177
178
+ private void showImageWithLocalUri (Uri imageUri ) {
179
+ if (imageUri != null ) {
180
+ GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder .newInstance (getResources ())
181
+ .setActualImageScaleType (ScaleType .FIT_XY )
182
+ .build ();
183
+ photoViewBackgroundImage .setHierarchy (hierarchy );
184
+ photoViewBackgroundImage
185
+ .setTapListener (new DoubleTapGestureListener (photoViewBackgroundImage ));
186
+ DraweeController controller = Fresco .newDraweeControllerBuilder ()
187
+ .setUri (Uri .fromFile (new File (imageUri .getPath ())))
188
+ .build ();
189
+ photoViewBackgroundImage .setTransformationListener (
190
+ () -> expandCollapseMediaDetail (false ));
191
+ photoViewBackgroundImage .setController (controller );
192
+ }
193
+ }
194
+
172
195
/**
173
196
* Handles the drawable click listener for Edit Text
174
197
*/
@@ -200,17 +223,6 @@ private float convertDpToPixel(float dp, Context context) {
200
223
return dp * ((float ) context .getResources ().getDisplayMetrics ().densityDpi / DisplayMetrics .DENSITY_DEFAULT );
201
224
}
202
225
203
- /**
204
- * Attaches the scale change listener to the image view
205
- */
206
- private void attachImageViewScaleChangeListener () {
207
- photoViewBackgroundImage .setOnScaleChangeListener (
208
- (scaleFactor , focusX , focusY ) -> {
209
- //Whenever the uses plays with the image, lets collapse the media detail container
210
- expandCollapseLlMediaDetail (false );
211
- });
212
- }
213
-
214
226
/**
215
227
* attach the presenter with the view
216
228
*/
@@ -286,7 +298,7 @@ public void onImageProcessed(UploadItem uploadItem, Place place) {
286
298
}
287
299
288
300
descriptions = uploadItem .getDescriptions ();
289
- photoViewBackgroundImage . setImageURI (uploadItem .getMediaUri ());
301
+ showImageWithLocalUri (uploadItem .getMediaUri ());
290
302
setDescriptionsInAdapter (descriptions );
291
303
}
292
304
@@ -395,14 +407,17 @@ public void onDestroyView() {
395
407
396
408
@ OnClick (R .id .rl_container_title )
397
409
public void onRlContainerTitleClicked () {
398
- expandCollapseLlMediaDetail (!isExpanded );
410
+ expandCollapseMediaDetail (!isExpanded );
399
411
}
400
412
401
413
/**
402
414
* show hide media detail based on
403
415
* @param shouldExpand
404
416
*/
405
- private void expandCollapseLlMediaDetail (boolean shouldExpand ){
417
+ private void expandCollapseMediaDetail (boolean shouldExpand ){
418
+ if (isExpanded == shouldExpand ) {
419
+ return ;
420
+ }
406
421
llContainerMediaDetail .setVisibility (shouldExpand ? View .VISIBLE : View .GONE );
407
422
isExpanded = !isExpanded ;
408
423
ibExpandCollapse .setRotation (ibExpandCollapse .getRotation () + 180 );
0 commit comments