Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DownSample Upload image to be shown in UploadMediaDetailFragment to handle OOM, Bitmap Too large exception #3830

Merged
merged 9 commits into from
Jun 24, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ZoomableDraweeView extends DraweeView<GenericDraweeHierarchy>

private boolean mIsDialtoneEnabled = false;
private boolean mZoomingEnabled = true;
private TransformationListener transformationListener;

private final ControllerListener mControllerListener =
new BaseControllerListener<Object>() {
Expand All @@ -73,9 +74,18 @@ public void onTransformChanged(Matrix transform) {
}

@Override
public void onTransformEnd(Matrix transform) {}
public void onTransformEnd(Matrix transform) {
if (null != transformationListener) {
transformationListener.onTransformationEnd();
}
}
};

public void setTransformationListener(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this too long to fit on 1 line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yes :P

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, sorry, do you mean trying the if, without the braces?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I meant this line. you could shorten the parameter name but it is not necessary

TransformationListener transformationListener) {
this.transformationListener = transformationListener;
}

private final GestureListenerWrapper mTapListenerWrapper = new GestureListenerWrapper();

public ZoomableDraweeView(Context context, GenericDraweeHierarchy hierarchy) {
Expand Down Expand Up @@ -397,4 +407,11 @@ protected Class<?> getLogTag() {
protected ZoomableController createZoomableController() {
return AnimatedZoomableController.newInstance();
}

/**
* Use this, If someone is willing to listen to scale change
*/
public interface TransformationListener{
void onTransformationEnd();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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 @@ -23,13 +24,19 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.github.chrisbanes.photoview.PhotoView;
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.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 @@ -44,6 +51,7 @@
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 @@ -69,7 +77,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
@BindView(R.id.rv_descriptions)
RecyclerView rvDescriptions;
@BindView(R.id.backgroundImage)
PhotoView photoViewBackgroundImage;
ZoomableDraweeView photoViewBackgroundImage;
@BindView(R.id.btn_next)
AppCompatButton btnNext;
@BindView(R.id.btn_previous)
Expand Down Expand Up @@ -164,11 +172,26 @@ private void init() {
btnCopyPreviousTitleDesc.setVisibility(View.VISIBLE);
}

attachImageViewScaleChangeListener();

addEtTitleTouchListener();
}

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(
() -> expandCollapseLlMediaDetail(false));
photoViewBackgroundImage.setController(controller);
}
}

/**
* Handles the drawable click listener for Edit Text
*/
Expand Down Expand Up @@ -198,17 +221,6 @@ 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 @@ -284,7 +296,7 @@ public void onImageProcessed(UploadItem uploadItem, Place place) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.github.chrisbanes.photoview.PhotoView
macgills marked this conversation as resolved.
Show resolved Hide resolved
<fr.free.nrw.commons.media.zoomControllers.zoomable.ZoomableDraweeView
android:id="@+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:actualImageScaleType="fitXY" />
android:scaleType="fitXY"
/>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
Expand Down