Implemented butterknife in ShareActivity [issue #1491]

This commit is contained in:
Ashish 2018-05-10 13:31:51 +05:30
parent 2d1f166ac7
commit 8f76dd0b61

View file

@ -8,7 +8,6 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -32,16 +31,16 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.BitmapCompat; import android.support.v4.graphics.BitmapCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
import android.view.inputmethod.InputMethodManager; import android.widget.FrameLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import butterknife.BindView;
import butterknife.OnClick;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder; import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView; import com.facebook.drawee.view.SimpleDraweeView;
import com.github.chrisbanes.photoview.PhotoView; import com.github.chrisbanes.photoview.PhotoView;
@ -69,22 +68,18 @@ import fr.free.nrw.commons.caching.CacheController;
import fr.free.nrw.commons.category.CategorizationFragment; import fr.free.nrw.commons.category.CategorizationFragment;
import fr.free.nrw.commons.category.OnCategoriesSaveHandler; import fr.free.nrw.commons.category.OnCategoriesSaveHandler;
import fr.free.nrw.commons.contributions.Contribution; import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.contributions.ContributionsActivity;
import fr.free.nrw.commons.modifications.CategoryModifier; import fr.free.nrw.commons.modifications.CategoryModifier;
import fr.free.nrw.commons.modifications.ModificationsContentProvider; import fr.free.nrw.commons.modifications.ModificationsContentProvider;
import fr.free.nrw.commons.modifications.ModifierSequence; import fr.free.nrw.commons.modifications.ModifierSequence;
import fr.free.nrw.commons.modifications.ModifierSequenceDao; import fr.free.nrw.commons.modifications.ModifierSequenceDao;
import fr.free.nrw.commons.modifications.TemplateRemoveModifier; import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
import fr.free.nrw.commons.utils.ImageUtils;
import fr.free.nrw.commons.mwapi.MediaWikiApi; import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.utils.ViewUtil; import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber; import timber.log.Timber;
import android.support.design.widget.FloatingActionButton;
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED; import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED;
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE; import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
import static java.lang.Long.min;
/** /**
* Activity for the title/desc screen after image is selected. Also starts processing image * Activity for the title/desc screen after image is selected. Also starts processing image
@ -95,6 +90,22 @@ public class ShareActivity
implements SingleUploadFragment.OnUploadActionInitiated, implements SingleUploadFragment.OnUploadActionInitiated,
OnCategoriesSaveHandler,SimilarImageDialogFragment.onResponse { OnCategoriesSaveHandler,SimilarImageDialogFragment.onResponse {
@BindView(R.id.container)
FrameLayout flContainer;
@BindView(R.id.backgroundImage)
SimpleDraweeView backgroundImageView;
@BindView(R.id.media_map)
FloatingActionButton mapsFragment; //Lets stick to camelCase
@BindView(R.id.media_upload_zoom_in)
FloatingActionButton zoomInButton;
@BindView(R.id.media_upload_zoom_out)
FloatingActionButton zoomOutButton;
@BindView(R.id.main_fab)
FloatingActionButton mainFab;
@BindView(R.id.expanded_image)
PhotoView expandedImageView;
private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1; private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1;
private static final int REQUEST_PERM_ON_CREATE_LOCATION = 2; private static final int REQUEST_PERM_ON_CREATE_LOCATION = 2;
private static final int REQUEST_PERM_ON_CREATE_STORAGE_AND_LOCATION = 3; private static final int REQUEST_PERM_ON_CREATE_STORAGE_AND_LOCATION = 3;
@ -120,9 +131,6 @@ public class ShareActivity
private Uri mediaUri; private Uri mediaUri;
private Contribution contribution; private Contribution contribution;
private SimpleDraweeView backgroundImageView;
private FloatingActionButton maps_fragment;
private boolean cacheFound; private boolean cacheFound;
private GPSExtractor imageObj; private GPSExtractor imageObj;
@ -143,11 +151,14 @@ public class ShareActivity
private Animator CurrentAnimator; private Animator CurrentAnimator;
private long ShortAnimationDuration; private long ShortAnimationDuration;
private FloatingActionButton zoomInButton;
private FloatingActionButton zoomOutButton;
private FloatingActionButton mainFab;
private boolean isFABOpen = false; private boolean isFABOpen = false;
//Had to make them class variables, to extract out the click listeners, also I see no harm in this
final Rect startBounds = new Rect();
final Rect finalBounds = new Rect();
final Point globalOffset = new Point();
private float startScaleFinal;
/** /**
* Called when user taps the submit button. * Called when user taps the submit button.
@ -257,7 +268,6 @@ public class ShareActivity
setContentView(R.layout.activity_share); setContentView(R.layout.activity_share);
ButterKnife.bind(this); ButterKnife.bind(this);
initBack(); initBack();
backgroundImageView = (SimpleDraweeView) findViewById(R.id.backgroundImage);
backgroundImageView.setHierarchy(GenericDraweeHierarchyBuilder backgroundImageView.setHierarchy(GenericDraweeHierarchyBuilder
.newInstance(getResources()) .newInstance(getResources())
.setPlaceholderImage(VectorDrawableCompat.create(getResources(), .setPlaceholderImage(VectorDrawableCompat.create(getResources(),
@ -286,37 +296,6 @@ public class ShareActivity
if (mediaUri != null) { if (mediaUri != null) {
backgroundImageView.setImageURI(mediaUri); backgroundImageView.setImageURI(mediaUri);
} }
mainFab = (FloatingActionButton) findViewById(R.id.main_fab);
/*
* called when upper arrow floating button
*/
mainFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!isFABOpen){
showFABMenu();
}else{
closeFABMenu();
}
}
});
zoomInButton = (FloatingActionButton) findViewById(R.id.media_upload_zoom_in);
try {
zoomInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zoomImageFromThumb(backgroundImageView, mediaUri);
}
});
} catch (Exception e){
Log.i("exception", e.toString());
}
zoomOutButton = (FloatingActionButton) findViewById(R.id.media_upload_zoom_out);
if (savedInstanceState != null) { if (savedInstanceState != null) {
contribution = savedInstanceState.getParcelable("contribution"); contribution = savedInstanceState.getParcelable("contribution");
} }
@ -378,25 +357,13 @@ public class ShareActivity
.commitAllowingStateLoss(); .commitAllowingStateLoss();
} }
uploadController.prepareService(); uploadController.prepareService();
maps_fragment = (FloatingActionButton) findViewById(R.id.media_map); mapsFragment.setVisibility(View.VISIBLE);
maps_fragment.setVisibility(View.VISIBLE);
if( imageObj == null || imageObj.imageCoordsExists != true){ if( imageObj == null || imageObj.imageCoordsExists != true){
maps_fragment.setVisibility(View.INVISIBLE); mapsFragment.setVisibility(View.INVISIBLE);
} }
}
maps_fragment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( imageObj != null && imageObj.imageCoordsExists == true) {
Uri gmmIntentUri = Uri.parse("google.streetview:cbll=" + imageObj.getDecLatitude() + "," + imageObj.getDecLongitude());
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
}
});
}
/* /*
* Function to display the zoom and map FAB * Function to display the zoom and map FAB
*/ */
@ -404,11 +371,11 @@ public class ShareActivity
isFABOpen=true; isFABOpen=true;
if( imageObj != null && imageObj.imageCoordsExists == true) if( imageObj != null && imageObj.imageCoordsExists == true)
maps_fragment.setVisibility(View.VISIBLE); mapsFragment.setVisibility(View.VISIBLE);
zoomInButton.setVisibility(View.VISIBLE); zoomInButton.setVisibility(View.VISIBLE);
mainFab.animate().rotationBy(180); mainFab.animate().rotationBy(180);
maps_fragment.animate().translationY(-getResources().getDimension(R.dimen.second_fab)); mapsFragment.animate().translationY(-getResources().getDimension(R.dimen.second_fab));
zoomInButton.animate().translationY(-getResources().getDimension(R.dimen.first_fab)); zoomInButton.animate().translationY(-getResources().getDimension(R.dimen.first_fab));
} }
@ -418,7 +385,7 @@ public class ShareActivity
private void closeFABMenu(){ private void closeFABMenu(){
isFABOpen=false; isFABOpen=false;
mainFab.animate().rotationBy(-180); mainFab.animate().rotationBy(-180);
maps_fragment.animate().translationY(0); mapsFragment.animate().translationY(0);
zoomInButton.animate().translationY(0).setListener(new Animator.AnimatorListener() { zoomInButton.animate().translationY(0).setListener(new Animator.AnimatorListener() {
@Override @Override
public void onAnimationStart(Animator animator) { public void onAnimationStart(Animator animator) {
@ -428,7 +395,7 @@ public class ShareActivity
@Override @Override
public void onAnimationEnd(Animator animator) { public void onAnimationEnd(Animator animator) {
if(!isFABOpen){ if(!isFABOpen){
maps_fragment.setVisibility(View.GONE); mapsFragment.setVisibility(View.GONE);
zoomInButton.setVisibility(View.GONE); zoomInButton.setVisibility(View.GONE);
} }
@ -700,8 +667,9 @@ public class ShareActivity
return; return;
} }
//I might not be supposed to change it, but still, I saw it
@Override @Override
public void onPostiveResponse() { public void onPositiveResponse() {
imageObj = tempImageObj; imageObj = tempImageObj;
decimalCoords = imageObj.getCoords(false);// Not necessary to use gps as image already ha EXIF data decimalCoords = imageObj.getCoords(false);// Not necessary to use gps as image already ha EXIF data
Timber.d("EXIF from tempImageObj"); Timber.d("EXIF from tempImageObj");
@ -865,26 +833,19 @@ public class ShareActivity
scaled = bitmap; scaled = bitmap;
} }
// Load the high-resolution "zoomed-in" image. // Load the high-resolution "zoomed-in" image.
PhotoView expandedImageView = (PhotoView) findViewById(
R.id.expanded_image);
expandedImageView.setImageBitmap(scaled); expandedImageView.setImageBitmap(scaled);
// Calculate the starting and ending bounds for the zoomed-in image. // Calculate the starting and ending bounds for the zoomed-in image.
// This step involves lots of math. Yay, math. // This step involves lots of math. Yay, math.
final Rect startBounds = new Rect();
final Rect finalBounds = new Rect();
final Point globalOffset = new Point();
// The start bounds are the global visible rectangle of the thumbnail, // The start bounds are the global visible rectangle of the thumbnail,
// and the final bounds are the global visible rectangle of the container // and the final bounds are the global visible rectangle of the container
// view. Also set the container view's offset as the origin for the // view. Also set the container view's offset as the origin for the
// bounds, since that's the origin for the positioning animation // bounds, since that's the origin for the positioning animation
// properties (X, Y). // properties (X, Y).
thumbView.getGlobalVisibleRect(startBounds); thumbView.getGlobalVisibleRect(startBounds);
findViewById(R.id.container) flContainer.getGlobalVisibleRect(finalBounds, globalOffset);
.getGlobalVisibleRect(finalBounds, globalOffset);
startBounds.offset(-globalOffset.x, -globalOffset.y); startBounds.offset(-globalOffset.x, -globalOffset.y);
finalBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y);
@ -955,10 +916,34 @@ public class ShareActivity
// Upon clicking the zoomed-in image, it should zoom back down // Upon clicking the zoomed-in image, it should zoom back down
// to the original bounds and show the thumbnail instead of // to the original bounds and show the thumbnail instead of
// the expanded image. // the expanded image.
final float startScaleFinal = startScale; startScaleFinal = startScale;
zoomOutButton.setOnClickListener(new View.OnClickListener() {
@Override }
public void onClick(View view) {
/*
* called when upper arrow floating button
*/
@OnClick(R.id.main_fab)
public void onMainFabClicked() {
if (!isFABOpen) {
showFABMenu();
} else {
closeFABMenu();
}
}
@OnClick(R.id.media_upload_zoom_in)
public void onZoomInFabClicked() {
//This try catch block was originally holding the entire click listener on the fab button, I did not wanted to risk exceptions
try {
zoomImageFromThumb(backgroundImageView, mediaUri);
} catch (Exception e) {
Log.i("exception", e.toString());
}
}
@OnClick(R.id.media_upload_zoom_out)
public void onZoomOutFabClicked() {
if (CurrentAnimator != null) { if (CurrentAnimator != null) {
CurrentAnimator.cancel(); CurrentAnimator.cancel();
} }
@ -984,24 +969,33 @@ public class ShareActivity
set.addListener(new AnimatorListenerAdapter() { set.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
thumbView.setAlpha(1f); //background image view is thumbView
backgroundImageView.setAlpha(1f);
expandedImageView.setVisibility(View.GONE); expandedImageView.setVisibility(View.GONE);
CurrentAnimator = null; CurrentAnimator = null;
} }
@Override @Override
public void onAnimationCancel(Animator animation) { public void onAnimationCancel(Animator animation) {
thumbView.setAlpha(1f); //background image view is thumbView
backgroundImageView.setAlpha(1f);
expandedImageView.setVisibility(View.GONE); expandedImageView.setVisibility(View.GONE);
CurrentAnimator = null; CurrentAnimator = null;
} }
}); });
set.start(); set.start();
CurrentAnimator = set; CurrentAnimator = set;
} }
}); @OnClick(R.id.media_map)
public void onFabShowMapsClicked() {
if (imageObj != null && imageObj.imageCoordsExists == true) {
Uri gmmIntentUri = Uri
.parse("google.streetview:cbll=" + imageObj.getDecLatitude() + "," + imageObj
.getDecLongitude());
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
}
} }
} }