Fix coding style issues

This commit is contained in:
Yusuke Matsubara 2017-06-10 17:36:37 +09:00
parent 4f4388b04e
commit fd11c872b9
3 changed files with 37 additions and 30 deletions

View file

@ -25,17 +25,19 @@ public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
interface Callback { interface Callback {
void onResult(Result result); void onResult(Result result);
} }
public enum Result { public enum Result {
NO_DUPLICATE, NO_DUPLICATE,
DUPLICATE_PROCEED, DUPLICATE_PROCEED,
DUPLICATE_CANCELLED DUPLICATE_CANCELLED
} }
private final String fileSHA1;
private final String fileSha1;
private final Context context; private final Context context;
private final Callback callback; private final Callback callback;
public ExistingFileAsync(String fileSHA1, Context context, Callback callback) { public ExistingFileAsync(String fileSha1, Context context, Callback callback) {
this.fileSHA1 = fileSHA1; this.fileSha1 = fileSha1;
this.context = context; this.context = context;
this.callback = callback; this.callback = callback;
} }
@ -55,7 +57,7 @@ public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
result = api.action("query") result = api.action("query")
.param("format", "xml") .param("format", "xml")
.param("list", "allimages") .param("list", "allimages")
.param("aisha1", fileSHA1) .param("aisha1", fileSha1)
.get(); .get();
Timber.d("Searching Commons API for existing file: %s", result); Timber.d("Searching Commons API for existing file: %s", result);
} catch (IOException e) { } catch (IOException e) {

View file

@ -166,10 +166,11 @@ public class FileUtils {
* @param destination stream copied to * @param destination stream copied to
* @throws IOException thrown when failing to read source or opening destination file * @throws IOException thrown when failing to read source or opening destination file
*/ */
public static void copy(@NonNull FileInputStream source, @NonNull FileOutputStream destination) throws IOException { public static void copy(@NonNull FileInputStream source, @NonNull FileOutputStream destination)
FileChannel source_ = source.getChannel(); throws IOException {
FileChannel dest_ = destination.getChannel(); FileChannel sourceChannel = source.getChannel();
source_.transferTo(0, source_.size(), dest_); FileChannel destinationChannel = destination.getChannel();
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
} }
/** /**
@ -178,7 +179,8 @@ public class FileUtils {
* @param destination file path copied to * @param destination file path copied to
* @throws IOException thrown when failing to read source or opening destination file * @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)); copy(new FileInputStream(source), new FileOutputStream(destination));
} }

View file

@ -291,7 +291,9 @@ public class ShareActivity
+ getResources().getString(R.string.location_permission_rationale); + getResources().getString(R.string.location_permission_rationale);
snackbar = requestPermissionUsingSnackBar( snackbar = requestPermissionUsingSnackBar(
permissionRationales, 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); REQUEST_PERM_ON_CREATE_STORAGE_AND_LOCATION);
View snackbarView = snackbar.getView(); View snackbarView = snackbar.getView();
TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text); TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
@ -308,7 +310,7 @@ public class ShareActivity
REQUEST_PERM_ON_CREATE_LOCATION); REQUEST_PERM_ON_CREATE_LOCATION);
} }
} }
preuploadProcessingOfFile(); performPreuploadProcessingOfFile();
} }
@Override @Override
@ -320,7 +322,7 @@ public class ShareActivity
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
backgroundImageView.setImageURI(mediaUri); backgroundImageView.setImageURI(mediaUri);
storagePermitted = true; storagePermitted = true;
preuploadProcessingOfFile(); performPreuploadProcessingOfFile();
} }
return; return;
} }
@ -328,7 +330,7 @@ public class ShareActivity
if (grantResults.length >= 1 if (grantResults.length >= 1
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
locationPermitted = true; locationPermitted = true;
preuploadProcessingOfFile(); performPreuploadProcessingOfFile();
} }
return; return;
} }
@ -337,12 +339,12 @@ public class ShareActivity
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
backgroundImageView.setImageURI(mediaUri); backgroundImageView.setImageURI(mediaUri);
storagePermitted = true; storagePermitted = true;
preuploadProcessingOfFile(); performPreuploadProcessingOfFile();
} }
if (grantResults.length >= 2 if (grantResults.length >= 2
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) { && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
locationPermitted = true; locationPermitted = true;
preuploadProcessingOfFile(); performPreuploadProcessingOfFile();
} }
return; return;
} }
@ -353,7 +355,7 @@ public class ShareActivity
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) { && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//It is OK to call this at both (1) and (4) because if perm had been granted at //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 //snackbar, user should not be prompted at submit button
preuploadProcessingOfFile(); performPreuploadProcessingOfFile();
//Uploading only begins if storage permission granted from arrow icon //Uploading only begins if storage permission granted from arrow icon
uploadBegins(); uploadBegins();
@ -364,9 +366,8 @@ public class ShareActivity
} }
} }
private void preuploadProcessingOfFile() { private void performPreuploadProcessingOfFile() {
if (!useNewPermissions || storagePermitted) { if (!useNewPermissions || storagePermitted) {
if (!duplicateCheckPassed) { if (!duplicateCheckPassed) {
//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 {
@ -375,7 +376,8 @@ public class ShareActivity
String fileSHA1 = Utils.getSHA1(inputStream); String fileSHA1 = Utils.getSHA1(inputStream);
Timber.d("File SHA1 is: %s", fileSHA1); Timber.d("File SHA1 is: %s", fileSHA1);
ExistingFileAsync fileAsyncTask = new ExistingFileAsync(fileSHA1, this, new ExistingFileAsync.Callback() { ExistingFileAsync fileAsyncTask =
new ExistingFileAsync(fileSHA1, this, new ExistingFileAsync.Callback() {
@Override @Override
public void onResult(ExistingFileAsync.Result result) { public void onResult(ExistingFileAsync.Result result) {
Timber.d("%s duplicate check: %s", mediaUri.toString(), result); Timber.d("%s duplicate check: %s", mediaUri.toString(), result);
@ -392,12 +394,13 @@ public class ShareActivity
getFileMetadata(locationPermitted); getFileMetadata(locationPermitted);
} else { } 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); 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 snackbar = Snackbar.make(findViewById(android.R.id.content), rationale,
Snackbar.LENGTH_INDEFINITE) Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.ok, new View.OnClickListener() { .setAction(R.string.ok, new View.OnClickListener() {