mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Incomplete creation of FileProcessor object
This commit is contained in:
parent
953d00d2f6
commit
af51ffad86
3 changed files with 48 additions and 40 deletions
|
|
@ -19,48 +19,20 @@ import java.util.List;
|
|||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
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.FileUtils.getSHA1;
|
||||
|
||||
public class FileProcessor {
|
||||
|
||||
private Uri mediaUri;
|
||||
|
||||
/**
|
||||
* Check if file user wants to upload already exists on Commons
|
||||
*/
|
||||
private void checkIfFileExists() {
|
||||
if (!useNewPermissions || storagePermitted) {
|
||||
if (!duplicateCheckPassed) {
|
||||
//Test SHA1 of image to see if it matches SHA1 of a file on Commons
|
||||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(mediaUri);
|
||||
Timber.d("Input stream created from %s", mediaUri.toString());
|
||||
String fileSHA1 = getSHA1(inputStream);
|
||||
Timber.d("File SHA1 is: %s", fileSHA1);
|
||||
public FileProcessor(Uri mediaUri) {
|
||||
this.mediaUri = mediaUri;
|
||||
|
||||
ExistingFileAsync fileAsyncTask =
|
||||
new ExistingFileAsync(new WeakReference<Activity>(this), fileSHA1, new WeakReference<Context>(this), result -> {
|
||||
Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
|
||||
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) {
|
||||
//image can be uploaded, so now check if its a useless picture or not
|
||||
detectUnwantedPictures();
|
||||
}
|
||||
},mwApi);
|
||||
fileAsyncTask.execute();
|
||||
} catch (IOException e) {
|
||||
Timber.e(e, "IO Exception: ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Timber.w("not ready for preprocessing: useNewPermissions=%s storage=%s location=%s",
|
||||
useNewPermissions, storagePermitted, locationPermitted);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls the async task that detects if image is fuzzy, too dark, etc
|
||||
*/
|
||||
|
|
@ -108,7 +80,7 @@ public class FileProcessor {
|
|||
* Gets coordinates for category suggestions, either from EXIF data or user location
|
||||
* @param gpsEnabled if true use GPS
|
||||
*/
|
||||
private void getFileCoordinates(boolean gpsEnabled) {
|
||||
void getFileCoordinates(boolean gpsEnabled) {
|
||||
Timber.d("Calling GPSExtractor");
|
||||
try {
|
||||
if (imageObj == null) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import timber.log.Timber;
|
|||
* is uploaded, extract latitude and longitude from EXIF data of image. If a picture without
|
||||
* geolocation is uploaded, retrieve user's location (if enabled in Settings).
|
||||
*/
|
||||
public class GPSExtractor {
|
||||
public class GPSExtractor extends FileProcessor {
|
||||
|
||||
private final Context context;
|
||||
private SharedPreferences prefs;
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ import timber.log.Timber;
|
|||
|
||||
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.FileUtils.getSHA1;
|
||||
|
||||
/**
|
||||
* Activity for the title/desc screen after image is selected. Also starts processing image
|
||||
|
|
@ -307,8 +308,9 @@ public class ShareActivity
|
|||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
REQUEST_PERM_ON_CREATE_LOCATION);
|
||||
}
|
||||
FileProcessor fileObj = new FileProcessor(mediaUri);
|
||||
checkIfFileExists();
|
||||
getFileCoordinates(locationPermitted);
|
||||
fileObj.getFileCoordinates(locationPermitted);
|
||||
|
||||
SingleUploadFragment shareView = (SingleUploadFragment) getSupportFragmentManager().findFragmentByTag("shareView");
|
||||
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
|
||||
|
|
@ -436,9 +438,7 @@ public class ShareActivity
|
|||
/**
|
||||
* 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.LENGTH_INDEFINITE).setAction(R.string.ok,
|
||||
view -> ActivityCompat.requestPermissions(ShareActivity.this, perms, code));
|
||||
|
|
@ -446,6 +446,42 @@ public class ShareActivity
|
|||
return snackbar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if file user wants to upload already exists on Commons
|
||||
*/
|
||||
private void checkIfFileExists() {
|
||||
if (!useNewPermissions || storagePermitted) {
|
||||
if (!duplicateCheckPassed) {
|
||||
//Test SHA1 of image to see if it matches SHA1 of a file on Commons
|
||||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(mediaUri);
|
||||
Timber.d("Input stream created from %s", mediaUri.toString());
|
||||
String fileSHA1 = getSHA1(inputStream);
|
||||
Timber.d("File SHA1 is: %s", fileSHA1);
|
||||
|
||||
ExistingFileAsync fileAsyncTask =
|
||||
new ExistingFileAsync(new WeakReference<Activity>(this), fileSHA1, new WeakReference<Context>(this), result -> {
|
||||
Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
|
||||
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) {
|
||||
//image can be uploaded, so now check if its a useless picture or not
|
||||
detectUnwantedPictures();
|
||||
}
|
||||
},mwApi);
|
||||
fileAsyncTask.execute();
|
||||
} catch (IOException e) {
|
||||
Timber.e(e, "IO Exception: ");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Timber.w("not ready for preprocessing: useNewPermissions=%s storage=%s location=%s",
|
||||
useNewPermissions, storagePermitted, locationPermitted);
|
||||
}
|
||||
}
|
||||
|
||||
//I might not be supposed to change it, but still, I saw it
|
||||
@Override
|
||||
public void onPositiveResponse() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue