Optimize formatting and imports

This commit is contained in:
misaochan 2018-06-04 19:40:49 +10:00
parent 4e1bf80361
commit c9ae7176c0
2 changed files with 59 additions and 54 deletions

View file

@ -33,18 +33,7 @@ import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
/** /**
* Processing of the image file that is about to be uploaded via ShareActivity is done here * Processing of the image file that is about to be uploaded via ShareActivity is done here
*/ */
public class FileProcessor implements SimilarImageDialogFragment.onResponse{ public class FileProcessor implements SimilarImageDialogFragment.onResponse {
private Uri mediaUri;
private ContentResolver contentResolver;
private GPSExtractor imageObj;
private Context context;
private String decimalCoords;
private boolean haveCheckedForOtherImages = false;
private String filePath;
private boolean useExtStorage;
private boolean cacheFound;
private GPSExtractor tempImageObj;
@Inject @Inject
CacheController cacheController; CacheController cacheController;
@ -55,6 +44,16 @@ public class FileProcessor implements SimilarImageDialogFragment.onResponse{
@Inject @Inject
@Named("default_preferences") @Named("default_preferences")
SharedPreferences prefs; SharedPreferences prefs;
private Uri mediaUri;
private ContentResolver contentResolver;
private GPSExtractor imageObj;
private Context context;
private String decimalCoords;
private boolean haveCheckedForOtherImages = false;
private String filePath;
private boolean useExtStorage;
private boolean cacheFound;
private GPSExtractor tempImageObj;
FileProcessor(Uri mediaUri, ContentResolver contentResolver, Context context) { FileProcessor(Uri mediaUri, ContentResolver contentResolver, Context context) {
this.mediaUri = mediaUri; this.mediaUri = mediaUri;
@ -67,6 +66,7 @@ public class FileProcessor implements SimilarImageDialogFragment.onResponse{
/** /**
* Gets file path from media URI. * Gets file path from media URI.
* In older devices getPath() may fail depending on the source URI, creating and using a copy of the file seems to work instead. * In older devices getPath() may fail depending on the source URI, creating and using a copy of the file seems to work instead.
*
* @return file path of media * @return file path of media
*/ */
@Nullable @Nullable
@ -97,32 +97,32 @@ public class FileProcessor implements SimilarImageDialogFragment.onResponse{
/** /**
* Processes file coordinates, either from EXIF data or user location * Processes file coordinates, either from EXIF data or user location
*
* @param gpsEnabled if true use GPS * @param gpsEnabled if true use GPS
*/ */
GPSExtractor processFileCoordinates(boolean gpsEnabled) { GPSExtractor processFileCoordinates(boolean gpsEnabled) {
Timber.d("Calling GPSExtractor"); Timber.d("Calling GPSExtractor");
try { try {
ParcelFileDescriptor descriptor = contentResolver.openFileDescriptor(mediaUri, "r"); ParcelFileDescriptor descriptor = contentResolver.openFileDescriptor(mediaUri, "r");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
if (descriptor != null) { if (descriptor != null) {
imageObj = new GPSExtractor(descriptor.getFileDescriptor(), context, prefs); imageObj = new GPSExtractor(descriptor.getFileDescriptor(), context, prefs);
} }
} else { } else {
String filePath = getPathOfMediaOrCopy(); String filePath = getPathOfMediaOrCopy();
if (filePath != null) { if (filePath != null) {
imageObj = new GPSExtractor(filePath, context, prefs); imageObj = new GPSExtractor(filePath, context, prefs);
} }
} }
decimalCoords = imageObj.getCoords(gpsEnabled); decimalCoords = imageObj.getCoords(gpsEnabled);
if (decimalCoords == null || !imageObj.imageCoordsExists){ if (decimalCoords == null || !imageObj.imageCoordsExists) {
//Find other photos taken around the same time which has gps coordinates //Find other photos taken around the same time which has gps coordinates
if(!haveCheckedForOtherImages) if (!haveCheckedForOtherImages)
findOtherImages(gpsEnabled);// Do not do repeat the process findOtherImages(gpsEnabled);// Do not do repeat the process
} } else {
else { useImageCoords();
useImageCoords(); }
}
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Timber.w("File not found: " + mediaUri, e); Timber.w("File not found: " + mediaUri, e);
@ -136,21 +136,22 @@ public class FileProcessor implements SimilarImageDialogFragment.onResponse{
/** /**
* Find other images around the same location that were taken within the last 20 sec * Find other images around the same location that were taken within the last 20 sec
*
* @param gpsEnabled True if GPS is enabled * @param gpsEnabled True if GPS is enabled
*/ */
private void findOtherImages(boolean gpsEnabled) { private void findOtherImages(boolean gpsEnabled) {
Timber.d("filePath"+getPathOfMediaOrCopy()); Timber.d("filePath" + getPathOfMediaOrCopy());
long timeOfCreation = new File(filePath).lastModified();//Time when the original image was created long timeOfCreation = new File(filePath).lastModified();//Time when the original image was created
File folder = new File(filePath.substring(0,filePath.lastIndexOf('/'))); File folder = new File(filePath.substring(0, filePath.lastIndexOf('/')));
File[] files = folder.listFiles(); File[] files = folder.listFiles();
Timber.d("folderTime Number:"+files.length); Timber.d("folderTime Number:" + files.length);
for(File file : files){ for (File file : files) {
if(file.lastModified()-timeOfCreation<=(120*1000) && file.lastModified()-timeOfCreation>=-(120*1000)){ if (file.lastModified() - timeOfCreation <= (120 * 1000) && file.lastModified() - timeOfCreation >= -(120 * 1000)) {
//Make sure the photos were taken within 20seconds //Make sure the photos were taken within 20seconds
Timber.d("fild date:"+file.lastModified()+ " time of creation"+timeOfCreation); Timber.d("fild date:" + file.lastModified() + " time of creation" + timeOfCreation);
tempImageObj = null;//Temporary GPSExtractor to extract coords from these photos tempImageObj = null;//Temporary GPSExtractor to extract coords from these photos
ParcelFileDescriptor descriptor = null; ParcelFileDescriptor descriptor = null;
try { try {
@ -168,17 +169,17 @@ public class FileProcessor implements SimilarImageDialogFragment.onResponse{
} }
} }
if(tempImageObj!=null){ if (tempImageObj != null) {
Timber.d("not null fild EXIF"+tempImageObj.imageCoordsExists +" coords"+tempImageObj.getCoords(gpsEnabled)); Timber.d("not null fild EXIF" + tempImageObj.imageCoordsExists + " coords" + tempImageObj.getCoords(gpsEnabled));
if(tempImageObj.getCoords(gpsEnabled)!=null && tempImageObj.imageCoordsExists){ if (tempImageObj.getCoords(gpsEnabled) != null && tempImageObj.imageCoordsExists) {
// Current image has gps coordinates and it's not current gps locaiton // Current image has gps coordinates and it's not current gps locaiton
Timber.d("This file has image coords:"+ file.getAbsolutePath()); Timber.d("This file has image coords:" + file.getAbsolutePath());
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment(); SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("originalImagePath",filePath); args.putString("originalImagePath", filePath);
args.putString("possibleImagePath",file.getAbsolutePath()); args.putString("possibleImagePath", file.getAbsolutePath());
newFragment.setArguments(args); newFragment.setArguments(args);
newFragment.show(((AppCompatActivity)context).getSupportFragmentManager(), "dialog"); newFragment.show(((AppCompatActivity) context).getSupportFragmentManager(), "dialog");
break; break;
} }
} }
@ -195,7 +196,7 @@ public class FileProcessor implements SimilarImageDialogFragment.onResponse{
public void useImageCoords() { public void useImageCoords() {
if (decimalCoords != null) { if (decimalCoords != null) {
Timber.d("Decimal coords of image: %s", decimalCoords); Timber.d("Decimal coords of image: %s", decimalCoords);
Timber.d("is EXIF data present:"+imageObj.imageCoordsExists+" from findOther image"); Timber.d("is EXIF data present:" + imageObj.imageCoordsExists + " from findOther image");
// Only set cache for this point if image has coords // Only set cache for this point if image has coords
if (imageObj.imageCoordsExists) { if (imageObj.imageCoordsExists) {

View file

@ -166,6 +166,7 @@ public class ShareActivity
/** /**
* Checks whether storage permissions need to be requested. * Checks whether storage permissions need to be requested.
* Permissions are needed if the file is not owned by this application, (e.g. shared from the Gallery) * Permissions are needed if the file is not owned by this application, (e.g. shared from the Gallery)
*
* @return true if file is not owned by this application and permission hasn't been granted beforehand * @return true if file is not owned by this application and permission hasn't been granted beforehand
*/ */
@RequiresApi(16) @RequiresApi(16)
@ -211,6 +212,7 @@ public class ShareActivity
/** /**
* Send categories to modifications queue after they are selected * Send categories to modifications queue after they are selected
*
* @param categories categories selected * @param categories categories selected
*/ */
@Override @Override
@ -339,9 +341,9 @@ public class ShareActivity
* Function to display the zoom and map FAB * Function to display the zoom and map FAB
*/ */
private void showFABMenu() { private void showFABMenu() {
isFABOpen=true; isFABOpen = true;
if( gpsObj != null && gpsObj.imageCoordsExists) if (gpsObj != null && gpsObj.imageCoordsExists)
mapButton.setVisibility(View.VISIBLE); mapButton.setVisibility(View.VISIBLE);
zoomInButton.setVisibility(View.VISIBLE); zoomInButton.setVisibility(View.VISIBLE);
@ -353,8 +355,8 @@ public class ShareActivity
/** /**
* Function to close the zoom and map FAB * Function to close the zoom and map FAB
*/ */
private void closeFABMenu(){ private void closeFABMenu() {
isFABOpen=false; isFABOpen = false;
mainFab.animate().rotationBy(-180); mainFab.animate().rotationBy(-180);
mapButton.animate().translationY(0); mapButton.animate().translationY(0);
zoomInButton.animate().translationY(0).setListener(new Animator.AnimatorListener() { zoomInButton.animate().translationY(0).setListener(new Animator.AnimatorListener() {
@ -364,7 +366,7 @@ public class ShareActivity
@Override @Override
public void onAnimationEnd(Animator animator) { public void onAnimationEnd(Animator animator) {
if(!isFABOpen){ if (!isFABOpen) {
mapButton.setVisibility(View.GONE); mapButton.setVisibility(View.GONE);
zoomInButton.setVisibility(View.GONE); zoomInButton.setVisibility(View.GONE);
} }
@ -382,6 +384,7 @@ public class ShareActivity
/** /**
* Checks if upload was initiated via Nearby * Checks if upload was initiated via Nearby
*
* @return true if upload was initiated via Nearby * @return true if upload was initiated via Nearby
*/ */
protected boolean isNearbyUpload() { protected boolean isNearbyUpload() {
@ -390,8 +393,9 @@ public class ShareActivity
/** /**
* Handles BOTH snackbar permission request (for location) and submit button permission request (for storage) * Handles BOTH snackbar permission request (for location) and submit button permission request (for storage)
* @param requestCode type of request *
* @param permissions permissions requested * @param requestCode type of request
* @param permissions permissions requested
* @param grantResults grant results * @param grantResults grant results
*/ */
@Override @Override
@ -422,7 +426,7 @@ public class ShareActivity
} }
/** /**
* Displays Snackbar to ask for location permissions * Displays Snackbar to ask for location permissions
*/ */
private Snackbar requestPermissionUsingSnackBar(String rationale, final String[] perms, final int code) { private Snackbar requestPermissionUsingSnackBar(String rationale, final String[] perms, final int code) {
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), rationale, Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), rationale,
@ -453,7 +457,7 @@ public class ShareActivity
//image is not a duplicate, so now check if its a unwanted picture or not //image is not a duplicate, so now check if its a unwanted picture or not
fileObj.detectUnwantedPictures(); fileObj.detectUnwantedPictures();
} }
},mwApi); }, mwApi);
fileAsyncTask.execute(); fileAsyncTask.execute();
} catch (IOException e) { } catch (IOException e) {
Timber.e(e, "IO Exception: "); Timber.e(e, "IO Exception: ");