mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
DownSample Upload image to be shown in UploadMediaDetailFragment to handle OOM, Bitmap Too large exception (#3830)
* Fixes #3829 * DownSample Upload image to be shown in UploadMediaDetailFragment to handle OOM, Bitmap Too large exception * removed unused imports, handled possible exceptions * Let Fresco handle the downsampling of image * invalidate in onTransformEnd * Expose an interface TransformationListener in ZoomableDraweeView to listen to transformation change end * removed photoView dependency * removed unused imports in ZoomableActivity * Bugfix, expand/collapse * changed functio name
This commit is contained in:
parent
78d519f83e
commit
e471226405
5 changed files with 54 additions and 29 deletions
|
|
@ -37,7 +37,6 @@ dependencies {
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
|
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
|
||||||
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
|
|
||||||
implementation 'com.github.pedrovgs:renderers:3.3.3'
|
implementation 'com.github.pedrovgs:renderers:3.3.3'
|
||||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.2'
|
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.2'
|
||||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v8:0.11.0'
|
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v8:0.11.0'
|
||||||
|
|
|
||||||
|
|
@ -23,18 +23,11 @@ import com.facebook.drawee.drawable.ScalingUtils;
|
||||||
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
import com.facebook.drawee.generic.GenericDraweeHierarchy;
|
||||||
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||||
import com.facebook.drawee.interfaces.DraweeController;
|
import com.facebook.drawee.interfaces.DraweeController;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import com.facebook.drawee.view.SimpleDraweeView;
|
|
||||||
import com.facebook.imagepipeline.image.ImageInfo;
|
import com.facebook.imagepipeline.image.ImageInfo;
|
||||||
import com.github.chrisbanes.photoview.PhotoView;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class ZoomableActivity extends AppCompatActivity {
|
public class ZoomableActivity extends AppCompatActivity {
|
||||||
private Uri imageUri;
|
private Uri imageUri;
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ public class ZoomableDraweeView extends DraweeView<GenericDraweeHierarchy>
|
||||||
|
|
||||||
private boolean mIsDialtoneEnabled = false;
|
private boolean mIsDialtoneEnabled = false;
|
||||||
private boolean mZoomingEnabled = true;
|
private boolean mZoomingEnabled = true;
|
||||||
|
private TransformationListener transformationListener;
|
||||||
|
|
||||||
private final ControllerListener mControllerListener =
|
private final ControllerListener mControllerListener =
|
||||||
new BaseControllerListener<Object>() {
|
new BaseControllerListener<Object>() {
|
||||||
|
|
@ -73,9 +74,18 @@ public class ZoomableDraweeView extends DraweeView<GenericDraweeHierarchy>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTransformEnd(Matrix transform) {}
|
public void onTransformEnd(Matrix transform) {
|
||||||
|
if (null != transformationListener) {
|
||||||
|
transformationListener.onTransformationEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public void setTransformationListener(
|
||||||
|
TransformationListener transformationListener) {
|
||||||
|
this.transformationListener = transformationListener;
|
||||||
|
}
|
||||||
|
|
||||||
private final GestureListenerWrapper mTapListenerWrapper = new GestureListenerWrapper();
|
private final GestureListenerWrapper mTapListenerWrapper = new GestureListenerWrapper();
|
||||||
|
|
||||||
public ZoomableDraweeView(Context context, GenericDraweeHierarchy hierarchy) {
|
public ZoomableDraweeView(Context context, GenericDraweeHierarchy hierarchy) {
|
||||||
|
|
@ -397,4 +407,11 @@ public class ZoomableDraweeView extends DraweeView<GenericDraweeHierarchy>
|
||||||
protected ZoomableController createZoomableController() {
|
protected ZoomableController createZoomableController() {
|
||||||
return AnimatedZoomableController.newInstance();
|
return AnimatedZoomableController.newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this, If someone is willing to listen to scale change
|
||||||
|
*/
|
||||||
|
public interface TransformationListener{
|
||||||
|
void onTransformationEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import static fr.free.nrw.commons.utils.ImageUtils.getErrorMessageForResult;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
|
|
@ -23,13 +24,19 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.OnClick;
|
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 com.jakewharton.rxbinding2.widget.RxTextView;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.Utils;
|
import fr.free.nrw.commons.Utils;
|
||||||
import fr.free.nrw.commons.filepicker.UploadableFile;
|
import fr.free.nrw.commons.filepicker.UploadableFile;
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
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.nearby.Place;
|
||||||
import fr.free.nrw.commons.settings.Prefs;
|
import fr.free.nrw.commons.settings.Prefs;
|
||||||
import fr.free.nrw.commons.upload.Description;
|
import fr.free.nrw.commons.upload.Description;
|
||||||
|
|
@ -44,6 +51,7 @@ import fr.free.nrw.commons.utils.DialogUtil;
|
||||||
import fr.free.nrw.commons.utils.ImageUtils;
|
import fr.free.nrw.commons.utils.ImageUtils;
|
||||||
import fr.free.nrw.commons.utils.ViewUtil;
|
import fr.free.nrw.commons.utils.ViewUtil;
|
||||||
import io.reactivex.disposables.Disposable;
|
import io.reactivex.disposables.Disposable;
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -69,7 +77,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
@BindView(R.id.rv_descriptions)
|
@BindView(R.id.rv_descriptions)
|
||||||
RecyclerView rvDescriptions;
|
RecyclerView rvDescriptions;
|
||||||
@BindView(R.id.backgroundImage)
|
@BindView(R.id.backgroundImage)
|
||||||
PhotoView photoViewBackgroundImage;
|
ZoomableDraweeView photoViewBackgroundImage;
|
||||||
@BindView(R.id.btn_next)
|
@BindView(R.id.btn_next)
|
||||||
AppCompatButton btnNext;
|
AppCompatButton btnNext;
|
||||||
@BindView(R.id.btn_previous)
|
@BindView(R.id.btn_previous)
|
||||||
|
|
@ -164,11 +172,26 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
btnCopyPreviousTitleDesc.setVisibility(View.VISIBLE);
|
btnCopyPreviousTitleDesc.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
attachImageViewScaleChangeListener();
|
|
||||||
|
|
||||||
addEtTitleTouchListener();
|
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(
|
||||||
|
() -> expandCollapseMediaDetail(false));
|
||||||
|
photoViewBackgroundImage.setController(controller);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the drawable click listener for Edit Text
|
* Handles the drawable click listener for Edit Text
|
||||||
*/
|
*/
|
||||||
|
|
@ -200,17 +223,6 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
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
|
* attach the presenter with the view
|
||||||
*/
|
*/
|
||||||
|
|
@ -286,7 +298,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptions = uploadItem.getDescriptions();
|
descriptions = uploadItem.getDescriptions();
|
||||||
photoViewBackgroundImage.setImageURI(uploadItem.getMediaUri());
|
showImageWithLocalUri(uploadItem.getMediaUri());
|
||||||
setDescriptionsInAdapter(descriptions);
|
setDescriptionsInAdapter(descriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,14 +407,17 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
||||||
|
|
||||||
@OnClick(R.id.rl_container_title)
|
@OnClick(R.id.rl_container_title)
|
||||||
public void onRlContainerTitleClicked() {
|
public void onRlContainerTitleClicked() {
|
||||||
expandCollapseLlMediaDetail(!isExpanded);
|
expandCollapseMediaDetail(!isExpanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show hide media detail based on
|
* show hide media detail based on
|
||||||
* @param shouldExpand
|
* @param shouldExpand
|
||||||
*/
|
*/
|
||||||
private void expandCollapseLlMediaDetail(boolean shouldExpand){
|
private void expandCollapseMediaDetail(boolean shouldExpand){
|
||||||
|
if (isExpanded == shouldExpand) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
llContainerMediaDetail.setVisibility(shouldExpand ? View.VISIBLE : View.GONE);
|
llContainerMediaDetail.setVisibility(shouldExpand ? View.VISIBLE : View.GONE);
|
||||||
isExpanded = !isExpanded;
|
isExpanded = !isExpanded;
|
||||||
ibExpandCollapse.setRotation(ibExpandCollapse.getRotation() + 180);
|
ibExpandCollapse.setRotation(ibExpandCollapse.getRotation() + 180);
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,12 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.github.chrisbanes.photoview.PhotoView
|
<fr.free.nrw.commons.media.zoomControllers.zoomable.ZoomableDraweeView
|
||||||
android:id="@+id/backgroundImage"
|
android:id="@+id/backgroundImage"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:actualImageScaleType="fitXY" />
|
android:scaleType="fitXY"
|
||||||
|
/>
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
<androidx.cardview.widget.CardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue