Skip to content

Commit

Permalink
Handled null CompoundDrawable[2] in etTitle-> UploadMediaDetailsFragm…
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishkumar468 committed Oct 10, 2020
1 parent 09623a4 commit 9083eae
Showing 1 changed file with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
Expand All @@ -24,19 +23,13 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.drawable.ScalingUtils.ScaleType;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.interfaces.DraweeController;
import com.github.chrisbanes.photoview.PhotoView;
import com.jakewharton.rxbinding2.widget.RxTextView;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.filepicker.UploadableFile;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.media.zoomControllers.zoomable.DoubleTapGestureListener;
import fr.free.nrw.commons.media.zoomControllers.zoomable.ZoomableDraweeView;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.upload.Description;
Expand All @@ -51,7 +44,6 @@
import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.disposables.Disposable;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -77,7 +69,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
@BindView(R.id.rv_descriptions)
RecyclerView rvDescriptions;
@BindView(R.id.backgroundImage)
ZoomableDraweeView photoViewBackgroundImage;
PhotoView photoViewBackgroundImage;
@BindView(R.id.btn_next)
AppCompatButton btnNext;
@BindView(R.id.btn_previous)
Expand Down Expand Up @@ -172,24 +164,9 @@ private void init() {
btnCopyPreviousTitleDesc.setVisibility(View.VISIBLE);
}

addEtTitleTouchListener();
}
attachImageViewScaleChangeListener();

private void showImageWithLocalUri(Uri imageUri) {
if (imageUri != null) {
GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources())
.setActualImageScaleType(ScaleType.FIT_XY)
.build();
photoViewBackgroundImage.setHierarchy(hierarchy);
photoViewBackgroundImage
.setTapListener(new DoubleTapGestureListener(photoViewBackgroundImage));
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(Uri.fromFile(new File(imageUri.getPath())))
.build();
photoViewBackgroundImage.setTransformationListener(
() -> expandCollapseMediaDetail(false));
photoViewBackgroundImage.setController(controller);
}
addEtTitleTouchListener();
}

/**
Expand Down Expand Up @@ -223,6 +200,17 @@ private float convertDpToPixel(float dp, Context context) {
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}

/**
* Attaches the scale change listener to the image view
*/
private void attachImageViewScaleChangeListener() {
photoViewBackgroundImage.setOnScaleChangeListener(
(scaleFactor, focusX, focusY) -> {
//Whenever the uses plays with the image, lets collapse the media detail container
expandCollapseLlMediaDetail(false);
});
}

/**
* attach the presenter with the view
*/
Expand Down Expand Up @@ -298,7 +286,7 @@ public void onImageProcessed(UploadItem uploadItem, Place place) {
}

descriptions = uploadItem.getDescriptions();
showImageWithLocalUri(uploadItem.getMediaUri());
photoViewBackgroundImage.setImageURI(uploadItem.getMediaUri());
setDescriptionsInAdapter(descriptions);
}

Expand Down Expand Up @@ -407,17 +395,14 @@ public void onDestroyView() {

@OnClick(R.id.rl_container_title)
public void onRlContainerTitleClicked() {
expandCollapseMediaDetail(!isExpanded);
expandCollapseLlMediaDetail(!isExpanded);
}

/**
* show hide media detail based on
* @param shouldExpand
*/
private void expandCollapseMediaDetail(boolean shouldExpand){
if (isExpanded == shouldExpand) {
return;
}
private void expandCollapseLlMediaDetail(boolean shouldExpand){
llContainerMediaDetail.setVisibility(shouldExpand ? View.VISIBLE : View.GONE);
isExpanded = !isExpanded;
ibExpandCollapse.setRotation(ibExpandCollapse.getRotation() + 180);
Expand Down

0 comments on commit 9083eae

Please sign in to comment.