mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Fix coding style issues
This commit is contained in:
parent
4f4388b04e
commit
fd11c872b9
3 changed files with 37 additions and 30 deletions
|
|
@ -25,17 +25,19 @@ public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
|
|||
interface Callback {
|
||||
void onResult(Result result);
|
||||
}
|
||||
|
||||
public enum Result {
|
||||
NO_DUPLICATE,
|
||||
DUPLICATE_PROCEED,
|
||||
DUPLICATE_CANCELLED
|
||||
}
|
||||
private final String fileSHA1;
|
||||
|
||||
private final String fileSha1;
|
||||
private final Context context;
|
||||
private final Callback callback;
|
||||
|
||||
public ExistingFileAsync(String fileSHA1, Context context, Callback callback) {
|
||||
this.fileSHA1 = fileSHA1;
|
||||
public ExistingFileAsync(String fileSha1, Context context, Callback callback) {
|
||||
this.fileSha1 = fileSha1;
|
||||
this.context = context;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
|
@ -55,7 +57,7 @@ public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
|
|||
result = api.action("query")
|
||||
.param("format", "xml")
|
||||
.param("list", "allimages")
|
||||
.param("aisha1", fileSHA1)
|
||||
.param("aisha1", fileSha1)
|
||||
.get();
|
||||
Timber.d("Searching Commons API for existing file: %s", result);
|
||||
} catch (IOException e) {
|
||||
|
|
|
|||
|
|
@ -166,10 +166,11 @@ public class FileUtils {
|
|||
* @param destination stream copied to
|
||||
* @throws IOException thrown when failing to read source or opening destination file
|
||||
*/
|
||||
public static void copy(@NonNull FileInputStream source, @NonNull FileOutputStream destination) throws IOException {
|
||||
FileChannel source_ = source.getChannel();
|
||||
FileChannel dest_ = destination.getChannel();
|
||||
source_.transferTo(0, source_.size(), dest_);
|
||||
public static void copy(@NonNull FileInputStream source, @NonNull FileOutputStream destination)
|
||||
throws IOException {
|
||||
FileChannel sourceChannel = source.getChannel();
|
||||
FileChannel destinationChannel = destination.getChannel();
|
||||
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -178,7 +179,8 @@ public class FileUtils {
|
|||
* @param destination file path copied to
|
||||
* @throws IOException thrown when failing to read source or opening destination file
|
||||
*/
|
||||
public static void copy(@NonNull FileDescriptor source, @NonNull String destination) throws IOException {
|
||||
public static void copy(@NonNull FileDescriptor source, @NonNull String destination)
|
||||
throws IOException {
|
||||
copy(new FileInputStream(source), new FileOutputStream(destination));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -291,7 +291,9 @@ public class ShareActivity
|
|||
+ getResources().getString(R.string.location_permission_rationale);
|
||||
snackbar = requestPermissionUsingSnackBar(
|
||||
permissionRationales,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
new String[]{
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
REQUEST_PERM_ON_CREATE_STORAGE_AND_LOCATION);
|
||||
View snackbarView = snackbar.getView();
|
||||
TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
|
||||
|
|
@ -308,7 +310,7 @@ public class ShareActivity
|
|||
REQUEST_PERM_ON_CREATE_LOCATION);
|
||||
}
|
||||
}
|
||||
preuploadProcessingOfFile();
|
||||
performPreuploadProcessingOfFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -320,7 +322,7 @@ public class ShareActivity
|
|||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
backgroundImageView.setImageURI(mediaUri);
|
||||
storagePermitted = true;
|
||||
preuploadProcessingOfFile();
|
||||
performPreuploadProcessingOfFile();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -328,7 +330,7 @@ public class ShareActivity
|
|||
if (grantResults.length >= 1
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
locationPermitted = true;
|
||||
preuploadProcessingOfFile();
|
||||
performPreuploadProcessingOfFile();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -337,12 +339,12 @@ public class ShareActivity
|
|||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
backgroundImageView.setImageURI(mediaUri);
|
||||
storagePermitted = true;
|
||||
preuploadProcessingOfFile();
|
||||
performPreuploadProcessingOfFile();
|
||||
}
|
||||
if (grantResults.length >= 2
|
||||
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
|
||||
locationPermitted = true;
|
||||
preuploadProcessingOfFile();
|
||||
performPreuploadProcessingOfFile();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -353,7 +355,7 @@ public class ShareActivity
|
|||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
//It is OK to call this at both (1) and (4) because if perm had been granted at
|
||||
//snackbar, user should not be prompted at submit button
|
||||
preuploadProcessingOfFile();
|
||||
performPreuploadProcessingOfFile();
|
||||
|
||||
//Uploading only begins if storage permission granted from arrow icon
|
||||
uploadBegins();
|
||||
|
|
@ -364,9 +366,8 @@ public class ShareActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void preuploadProcessingOfFile() {
|
||||
if(!useNewPermissions || storagePermitted) {
|
||||
|
||||
private void performPreuploadProcessingOfFile() {
|
||||
if (!useNewPermissions || storagePermitted) {
|
||||
if (!duplicateCheckPassed) {
|
||||
//Test SHA1 of image to see if it matches SHA1 of a file on Commons
|
||||
try {
|
||||
|
|
@ -375,15 +376,16 @@ public class ShareActivity
|
|||
String fileSHA1 = Utils.getSHA1(inputStream);
|
||||
Timber.d("File SHA1 is: %s", fileSHA1);
|
||||
|
||||
ExistingFileAsync fileAsyncTask = new ExistingFileAsync(fileSHA1, this, new ExistingFileAsync.Callback() {
|
||||
@Override
|
||||
public void onResult(ExistingFileAsync.Result result) {
|
||||
Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
|
||||
duplicateCheckPassed =
|
||||
result == ExistingFileAsync.Result.DUPLICATE_PROCEED
|
||||
|| result == ExistingFileAsync.Result.NO_DUPLICATE;
|
||||
}
|
||||
});
|
||||
ExistingFileAsync fileAsyncTask =
|
||||
new ExistingFileAsync(fileSHA1, this, new ExistingFileAsync.Callback() {
|
||||
@Override
|
||||
public void onResult(ExistingFileAsync.Result result) {
|
||||
Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
|
||||
duplicateCheckPassed =
|
||||
result == ExistingFileAsync.Result.DUPLICATE_PROCEED
|
||||
|| result == ExistingFileAsync.Result.NO_DUPLICATE;
|
||||
}
|
||||
});
|
||||
fileAsyncTask.execute();
|
||||
} catch (IOException e) {
|
||||
Timber.d(e, "IO Exception: ");
|
||||
|
|
@ -392,12 +394,13 @@ public class ShareActivity
|
|||
|
||||
getFileMetadata(locationPermitted);
|
||||
} else {
|
||||
Timber.w("not ready for preprocess: useNewPermissions=%s storage=%s location=%s",
|
||||
Timber.w("not ready for preprocessing: useNewPermissions=%s storage=%s location=%s",
|
||||
useNewPermissions, storagePermitted, locationPermitted);
|
||||
}
|
||||
}
|
||||
|
||||
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, new View.OnClickListener() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue