Tidy up code

This commit is contained in:
misaochan 2018-05-26 00:30:57 +10:00
parent cc678baa5d
commit 11c35b55fc

View file

@ -80,6 +80,14 @@ public class ShareActivity
implements SingleUploadFragment.OnUploadActionInitiated, implements SingleUploadFragment.OnUploadActionInitiated,
OnCategoriesSaveHandler,SimilarImageDialogFragment.onResponse { OnCategoriesSaveHandler,SimilarImageDialogFragment.onResponse {
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_STORAGE_AND_LOCATION = 3;
private static final int REQUEST_PERM_ON_SUBMIT_STORAGE = 4;
//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();
@Inject @Inject
MediaWikiApi mwApi; MediaWikiApi mwApi;
@Inject @Inject
@ -93,7 +101,6 @@ public class ShareActivity
@Inject @Inject
@Named("default_preferences") @Named("default_preferences")
SharedPreferences prefs; SharedPreferences prefs;
@BindView(R.id.container) @BindView(R.id.container)
FrameLayout flContainer; FrameLayout flContainer;
@BindView(R.id.backgroundImage) @BindView(R.id.backgroundImage)
@ -108,45 +115,27 @@ public class ShareActivity
FloatingActionButton mainFab; FloatingActionButton mainFab;
@BindView(R.id.expanded_image) @BindView(R.id.expanded_image)
PhotoView expandedImageView; PhotoView expandedImageView;
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_STORAGE_AND_LOCATION = 3;
private static final int REQUEST_PERM_ON_SUBMIT_STORAGE = 4;
private String source; private String source;
private String mimeType; private String mimeType;
private CategorizationFragment categorizationFragment; private CategorizationFragment categorizationFragment;
private Uri mediaUri; private Uri mediaUri;
private Contribution contribution; private Contribution contribution;
private boolean cacheFound; private boolean cacheFound;
private GPSExtractor imageObj; private GPSExtractor imageObj;
private GPSExtractor tempImageObj; private GPSExtractor tempImageObj;
private String decimalCoords; private String decimalCoords;
private FileProcessor fileObj; private FileProcessor fileObj;
private boolean useNewPermissions = false; private boolean useNewPermissions = false;
private boolean storagePermitted = false; private boolean storagePermitted = false;
private boolean locationPermitted = false; private boolean locationPermitted = false;
private String title; private String title;
private String description; private String description;
private Snackbar snackbar; private Snackbar snackbar;
private boolean duplicateCheckPassed = false; private boolean duplicateCheckPassed = false;
private boolean isNearbyUpload = false; private boolean isNearbyUpload = false;
private Animator CurrentAnimator; private Animator CurrentAnimator;
private long ShortAnimationDuration; private long ShortAnimationDuration;
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; private float startScaleFinal;
/** /**
@ -274,14 +263,13 @@ public class ShareActivity
R.drawable.ic_error_outline_black_24dp, getTheme())) R.drawable.ic_error_outline_black_24dp, getTheme()))
.build()); .build());
receiveIntent(); receiveImageIntent();
if (savedInstanceState != null) { if (savedInstanceState != null) {
contribution = savedInstanceState.getParcelable("contribution"); contribution = savedInstanceState.getParcelable("contribution");
} }
requestAuthToken(); requestAuthToken();
Timber.d("Uri: %s", mediaUri.toString()); Timber.d("Uri: %s", mediaUri.toString());
Timber.d("Ext storage dir: %s", Environment.getExternalStorageDirectory()); Timber.d("Ext storage dir: %s", Environment.getExternalStorageDirectory());
@ -301,8 +289,6 @@ public class ShareActivity
REQUEST_PERM_ON_CREATE_LOCATION); REQUEST_PERM_ON_CREATE_LOCATION);
} }
ContentResolver contentResolver = this.getContentResolver();
SingleUploadFragment shareView = (SingleUploadFragment) getSupportFragmentManager().findFragmentByTag("shareView"); SingleUploadFragment shareView = (SingleUploadFragment) getSupportFragmentManager().findFragmentByTag("shareView");
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization"); categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
if (shareView == null && categorizationFragment == null) { if (shareView == null && categorizationFragment == null) {
@ -314,6 +300,7 @@ public class ShareActivity
} }
uploadController.prepareService(); uploadController.prepareService();
ContentResolver contentResolver = this.getContentResolver();
fileObj = new FileProcessor(mediaUri, contentResolver, prefs, this); fileObj = new FileProcessor(mediaUri, contentResolver, prefs, this);
checkIfFileExists(); checkIfFileExists();
fileObj.getFileCoordinates(locationPermitted); fileObj.getFileCoordinates(locationPermitted);
@ -322,7 +309,7 @@ public class ShareActivity
/** /**
* Receive intent from ContributionController.java when user selects picture to upload * Receive intent from ContributionController.java when user selects picture to upload
*/ */
private void receiveIntent() { private void receiveImageIntent() {
Intent intent = getIntent(); Intent intent = getIntent();
if (Intent.ACTION_SEND.equals(intent.getAction())) { if (Intent.ACTION_SEND.equals(intent.getAction())) {
@ -450,19 +437,16 @@ public class ShareActivity
//Test SHA1 of image to see if it matches SHA1 of a file on Commons //Test SHA1 of image to see if it matches SHA1 of a file on Commons
try { try {
InputStream inputStream = getContentResolver().openInputStream(mediaUri); InputStream inputStream = getContentResolver().openInputStream(mediaUri);
Timber.d("Input stream created from %s", mediaUri.toString());
String fileSHA1 = getSHA1(inputStream); String fileSHA1 = getSHA1(inputStream);
Timber.d("Input stream created from %s", mediaUri.toString());
Timber.d("File SHA1 is: %s", fileSHA1); Timber.d("File SHA1 is: %s", fileSHA1);
ExistingFileAsync fileAsyncTask = ExistingFileAsync fileAsyncTask =
new ExistingFileAsync(new WeakReference<Activity>(this), fileSHA1, new WeakReference<Context>(this), result -> { new ExistingFileAsync(new WeakReference<Activity>(this), fileSHA1, new WeakReference<Context>(this), result -> {
Timber.d("%s duplicate check: %s", mediaUri.toString(), result); Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
duplicateCheckPassed = (result == DUPLICATE_PROCEED || result == NO_DUPLICATE); duplicateCheckPassed = (result == DUPLICATE_PROCEED || result == NO_DUPLICATE);
//TODO: 16/9/17 should we run DetectUnwantedPicturesAsync if DUPLICATE_PROCEED is returned? Since that means
//we are processing images that are already on server???...
if (duplicateCheckPassed) { if (duplicateCheckPassed) {
//image can be uploaded, so now check if its a useless picture or not //image is not a duplicate, so now check if its a unwanted picture or not
detectUnwantedPictures(); detectUnwantedPictures();
} }
},mwApi); },mwApi);
@ -477,6 +461,7 @@ public class ShareActivity
} }
} }
//I might not be supposed to change it, but still, I saw it //I might not be supposed to change it, but still, I saw it
@Override @Override
public void onPositiveResponse() { public void onPositiveResponse() {
@ -503,7 +488,6 @@ public class ShareActivity
detectUnwantedPicturesAsync.execute(); detectUnwantedPicturesAsync.execute();
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();