44
55import android .annotation .SuppressLint ;
66import android .content .Context ;
7- import android .net .Uri ;
87import android .os .Bundle ;
98import android .text .TextUtils ;
109import android .util .DisplayMetrics ;
2423import butterknife .BindView ;
2524import butterknife .ButterKnife ;
2625import butterknife .OnClick ;
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 ;
26+ import com .github .chrisbanes .photoview .PhotoView ;
3227import com .jakewharton .rxbinding2 .widget .RxTextView ;
3328import fr .free .nrw .commons .R ;
3429import fr .free .nrw .commons .Utils ;
3530import fr .free .nrw .commons .filepicker .UploadableFile ;
3631import fr .free .nrw .commons .kvstore .JsonKvStore ;
3732import 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 ;
4033import fr .free .nrw .commons .nearby .Place ;
4134import fr .free .nrw .commons .settings .Prefs ;
4235import fr .free .nrw .commons .upload .Description ;
5144import fr .free .nrw .commons .utils .ImageUtils ;
5245import fr .free .nrw .commons .utils .ViewUtil ;
5346import io .reactivex .disposables .Disposable ;
54- import java .io .File ;
5547import java .util .ArrayList ;
5648import java .util .Arrays ;
5749import java .util .List ;
@@ -77,7 +69,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
7769 @ BindView (R .id .rv_descriptions )
7870 RecyclerView rvDescriptions ;
7971 @ BindView (R .id .backgroundImage )
80- ZoomableDraweeView photoViewBackgroundImage ;
72+ PhotoView photoViewBackgroundImage ;
8173 @ BindView (R .id .btn_next )
8274 AppCompatButton btnNext ;
8375 @ BindView (R .id .btn_previous )
@@ -172,24 +164,9 @@ private void init() {
172164 btnCopyPreviousTitleDesc .setVisibility (View .VISIBLE );
173165 }
174166
175- addEtTitleTouchListener ();
176- }
167+ attachImageViewScaleChangeListener ();
177168
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- }
169+ addEtTitleTouchListener ();
193170 }
194171
195172 /**
@@ -223,6 +200,17 @@ private float convertDpToPixel(float dp, Context context) {
223200 return dp * ((float ) context .getResources ().getDisplayMetrics ().densityDpi / DisplayMetrics .DENSITY_DEFAULT );
224201 }
225202
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+
226214 /**
227215 * attach the presenter with the view
228216 */
@@ -298,7 +286,7 @@ public void onImageProcessed(UploadItem uploadItem, Place place) {
298286 }
299287
300288 descriptions = uploadItem .getDescriptions ();
301- showImageWithLocalUri (uploadItem .getMediaUri ());
289+ photoViewBackgroundImage . setImageURI (uploadItem .getMediaUri ());
302290 setDescriptionsInAdapter (descriptions );
303291 }
304292
@@ -407,17 +395,14 @@ public void onDestroyView() {
407395
408396 @ OnClick (R .id .rl_container_title )
409397 public void onRlContainerTitleClicked () {
410- expandCollapseMediaDetail (!isExpanded );
398+ expandCollapseLlMediaDetail (!isExpanded );
411399 }
412400
413401 /**
414402 * show hide media detail based on
415403 * @param shouldExpand
416404 */
417- private void expandCollapseMediaDetail (boolean shouldExpand ){
418- if (isExpanded == shouldExpand ) {
419- return ;
420- }
405+ private void expandCollapseLlMediaDetail (boolean shouldExpand ){
421406 llContainerMediaDetail .setVisibility (shouldExpand ? View .VISIBLE : View .GONE );
422407 isExpanded = !isExpanded ;
423408 ibExpandCollapse .setRotation (ibExpandCollapse .getRotation () + 180 );
0 commit comments