Merge pull request #917 from RSBat/master

Fix Codacy issues
This commit is contained in:
Yusuke Matsubara 2017-10-27 22:26:44 +09:00 committed by GitHub
commit b0e8175003
20 changed files with 47 additions and 46 deletions

View file

@ -178,8 +178,8 @@ public class CommonsApplication extends Application {
public boolean deviceHasCamera() { public boolean deviceHasCamera() {
PackageManager pm = getPackageManager(); PackageManager pm = getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT); || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
} }
public void clearApplicationData(Context context, LogoutListener logoutListener) { public void clearApplicationData(Context context, LogoutListener logoutListener) {

View file

@ -152,7 +152,7 @@ public class MediaDataExtractor {
} }
private Node findTemplate(Element parentNode, String title_) throws IOException { private Node findTemplate(Element parentNode, String title_) throws IOException {
String title= new PageTitle(title_).getDisplayText(); String title = new PageTitle(title_).getDisplayText();
NodeList nodes = parentNode.getChildNodes(); NodeList nodes = parentNode.getChildNodes();
for (int i = 0, length = nodes.getLength(); i < length; i++) { for (int i = 0, length = nodes.getLength(); i < length; i++) {
Node node = nodes.item(i); Node node = nodes.item(i);

View file

@ -248,8 +248,8 @@ public class LoginActivity extends AccountAuthenticatorActivity {
@Override @Override
public void afterTextChanged(Editable editable) { public void afterTextChanged(Editable editable) {
boolean enabled = usernameEdit.getText().length() != 0 && passwordEdit.getText().length() != 0 && boolean enabled = usernameEdit.getText().length() != 0 && passwordEdit.getText().length() != 0
(BuildConfig.DEBUG || twoFactorEdit.getText().length() != 0 || twoFactorEdit.getVisibility() != View.VISIBLE); && (BuildConfig.DEBUG || twoFactorEdit.getText().length() != 0 || twoFactorEdit.getVisibility() != View.VISIBLE);
loginButton.setEnabled(enabled); loginButton.setEnabled(enabled);
} }
} }

View file

@ -34,7 +34,7 @@ class ContributionsListAdapter extends CursorAdapter {
views.seqNumView.setText(String.valueOf(cursor.getPosition() + 1)); views.seqNumView.setText(String.valueOf(cursor.getPosition() + 1));
views.seqNumView.setVisibility(View.VISIBLE); views.seqNumView.setVisibility(View.VISIBLE);
switch(contribution.getState()) { switch (contribution.getState()) {
case Contribution.STATE_COMPLETED: case Contribution.STATE_COMPLETED:
views.stateView.setVisibility(View.GONE); views.stateView.setVisibility(View.GONE);
views.progressView.setVisibility(View.GONE); views.progressView.setVisibility(View.GONE);
@ -50,7 +50,7 @@ class ContributionsListAdapter extends CursorAdapter {
views.progressView.setVisibility(View.VISIBLE); views.progressView.setVisibility(View.VISIBLE);
long total = contribution.getDataLength(); long total = contribution.getDataLength();
long transferred = contribution.getTransferred(); long transferred = contribution.getTransferred();
if(transferred == 0 || transferred >= total) { if (transferred == 0 || transferred >= total) {
views.progressView.setIndeterminate(true); views.progressView.setIndeterminate(true);
} else { } else {
views.progressView.setProgress((int)(((double)transferred / (double)total) * 100)); views.progressView.setProgress((int)(((double)transferred / (double)total) * 100));

View file

@ -7,7 +7,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import fr.free.nrw.commons.contributions.Contribution; import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.modifications.ModifierSequence; import fr.free.nrw.commons.modifications.ModifierSequence;
public class DBOpenHelper extends SQLiteOpenHelper{ public class DBOpenHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "commons.db"; private static final String DATABASE_NAME = "commons.db";
private static final int DATABASE_VERSION = 6; private static final int DATABASE_VERSION = 6;

View file

@ -13,7 +13,7 @@ public class LatLng {
* @param longitude double value * @param longitude double value
*/ */
public LatLng(double latitude, double longitude, float accuracy) { public LatLng(double latitude, double longitude, float accuracy) {
if(-180.0D <= longitude && longitude < 180.0D) { if (-180.0D <= longitude && longitude < 180.0D) {
this.longitude = longitude; this.longitude = longitude;
} else { } else {
this.longitude = ((longitude - 180.0D) % 360.0D + 360.0D) % 360.0D - 180.0D; this.longitude = ((longitude - 180.0D) % 360.0D + 360.0D) % 360.0D - 180.0D;
@ -33,9 +33,9 @@ public class LatLng {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
if(this == o) { if (this == o) {
return true; return true;
} else if(!(o instanceof LatLng)) { } else if (!(o instanceof LatLng)) {
return false; return false;
} else { } else {
LatLng var2 = (LatLng)o; LatLng var2 = (LatLng)o;

View file

@ -13,7 +13,7 @@ public class CategoryModifier extends PageModifier {
public CategoryModifier(String... categories) { public CategoryModifier(String... categories) {
super(MODIFIER_NAME); super(MODIFIER_NAME);
JSONArray categoriesArray = new JSONArray(); JSONArray categoriesArray = new JSONArray();
for(String category: categories) { for (String category: categories) {
categoriesArray.put(category); categoriesArray.put(category);
} }
try { try {
@ -34,7 +34,7 @@ public class CategoryModifier extends PageModifier {
categories = params.optJSONArray(PARAM_CATEGORIES); categories = params.optJSONArray(PARAM_CATEGORIES);
StringBuilder categoriesString = new StringBuilder(); StringBuilder categoriesString = new StringBuilder();
for(int i=0; i < categories.length(); i++) { for (int i = 0; i < categories.length(); i++) {
String category = categories.optString(i); String category = categories.optString(i);
categoriesString.append("\n[[Category:").append(category).append("]]"); categoriesString.append("\n[[Category:").append(category).append("]]");
} }

View file

@ -13,7 +13,7 @@ import android.text.TextUtils;
import fr.free.nrw.commons.CommonsApplication; import fr.free.nrw.commons.CommonsApplication;
import timber.log.Timber; import timber.log.Timber;
public class ModificationsContentProvider extends ContentProvider{ public class ModificationsContentProvider extends ContentProvider {
private static final int MODIFICATIONS = 1; private static final int MODIFICATIONS = 1;
private static final int MODIFICATIONS_ID = 2; private static final int MODIFICATIONS_ID = 2;
@ -46,7 +46,7 @@ public class ModificationsContentProvider extends ContentProvider{
int uriType = uriMatcher.match(uri); int uriType = uriMatcher.match(uri);
switch(uriType) { switch (uriType) {
case MODIFICATIONS: case MODIFICATIONS:
break; break;
default: default:
@ -107,7 +107,7 @@ public class ModificationsContentProvider extends ContentProvider{
sqlDB.beginTransaction(); sqlDB.beginTransaction();
switch (uriType) { switch (uriType) {
case MODIFICATIONS: case MODIFICATIONS:
for(ContentValues value: values) { for (ContentValues value: values) {
Timber.d("Inserting! %s", value); Timber.d("Inserting! %s", value);
sqlDB.insert(ModifierSequence.Table.TABLE_NAME, null, value); sqlDB.insert(ModifierSequence.Table.TABLE_NAME, null, value);
} }

View file

@ -27,7 +27,7 @@ public class ModifierSequence {
public ModifierSequence(Uri mediaUri, JSONObject data) { public ModifierSequence(Uri mediaUri, JSONObject data) {
this(mediaUri); this(mediaUri);
JSONArray modifiersJSON = data.optJSONArray("modifiers"); JSONArray modifiersJSON = data.optJSONArray("modifiers");
for (int i=0; i< modifiersJSON.length(); i++) { for (int i = 0; i < modifiersJSON.length(); i++) {
modifiers.add(PageModifier.fromJSON(modifiersJSON.optJSONObject(i))); modifiers.add(PageModifier.fromJSON(modifiersJSON.optJSONObject(i)));
} }
} }
@ -49,7 +49,7 @@ public class ModifierSequence {
public String getEditSummary() { public String getEditSummary() {
StringBuilder editSummary = new StringBuilder(); StringBuilder editSummary = new StringBuilder();
for(PageModifier modifier: modifiers) { for (PageModifier modifier: modifiers) {
editSummary.append(modifier.getEditSumary()).append(" "); editSummary.append(modifier.getEditSumary()).append(" ");
} }
editSummary.append("Via Commons Mobile App"); editSummary.append("Via Commons Mobile App");
@ -93,12 +93,12 @@ public class ModifierSequence {
public void save() { public void save() {
try { try {
if(contentUri == null) { if (contentUri == null) {
contentUri = client.insert(ModificationsContentProvider.BASE_URI, this.toContentValues()); contentUri = client.insert(ModificationsContentProvider.BASE_URI, this.toContentValues());
} else { } else {
client.update(contentUri, toContentValues(), null, null); client.update(contentUri, toContentValues(), null, null);
} }
} catch(RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }

View file

@ -7,9 +7,9 @@ public abstract class PageModifier {
public static PageModifier fromJSON(JSONObject data) { public static PageModifier fromJSON(JSONObject data) {
String name = data.optString("name"); String name = data.optString("name");
if(name.equals(CategoryModifier.MODIFIER_NAME)) { if (name.equals(CategoryModifier.MODIFIER_NAME)) {
return new CategoryModifier(data.optJSONObject("data")); return new CategoryModifier(data.optJSONObject("data"));
} else if(name.equals(TemplateRemoveModifier.MODIFIER_NAME)) { } else if (name.equals(TemplateRemoveModifier.MODIFIER_NAME)) {
return new TemplateRemoveModifier(data.optJSONObject("data")); return new TemplateRemoveModifier(data.optJSONObject("data"));
} }

View file

@ -41,18 +41,18 @@ public class TemplateRemoveModifier extends PageModifier {
Pattern templateStartPattern = Pattern.compile("\\{\\{" + templateNormalized, Pattern.CASE_INSENSITIVE); Pattern templateStartPattern = Pattern.compile("\\{\\{" + templateNormalized, Pattern.CASE_INSENSITIVE);
Matcher matcher = templateStartPattern.matcher(pageContents); Matcher matcher = templateStartPattern.matcher(pageContents);
while(matcher.find()) { while (matcher.find()) {
int braceCount = 1; int braceCount = 1;
int startIndex = matcher.start(); int startIndex = matcher.start();
int curIndex = matcher.end(); int curIndex = matcher.end();
Matcher openMatch = PATTERN_TEMPLATE_OPEN.matcher(pageContents); Matcher openMatch = PATTERN_TEMPLATE_OPEN.matcher(pageContents);
Matcher closeMatch = PATTERN_TEMPLATE_CLOSE.matcher(pageContents); Matcher closeMatch = PATTERN_TEMPLATE_CLOSE.matcher(pageContents);
while(curIndex < pageContents.length()) { while (curIndex < pageContents.length()) {
boolean openFound = openMatch.find(curIndex); boolean openFound = openMatch.find(curIndex);
boolean closeFound = closeMatch.find(curIndex); boolean closeFound = closeMatch.find(curIndex);
if(openFound && (!closeFound || openMatch.start() < closeMatch.start())) { if (openFound && (!closeFound || openMatch.start() < closeMatch.start())) {
braceCount++; braceCount++;
curIndex = openMatch.end(); curIndex = openMatch.end();
} else if (closeFound) { } else if (closeFound) {
@ -71,8 +71,8 @@ public class TemplateRemoveModifier extends PageModifier {
} }
// Strip trailing whitespace // Strip trailing whitespace
while(curIndex < pageContents.length()) { while (curIndex < pageContents.length()) {
if(pageContents.charAt(curIndex) == ' ' || pageContents.charAt(curIndex) == '\n') { if (pageContents.charAt(curIndex) == ' ' || pageContents.charAt(curIndex) == '\n') {
curIndex++; curIndex++;
} else { } else {
break; break;

View file

@ -390,7 +390,7 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
public UploadResult uploadFile(String filename, InputStream file, long dataLength, String pageContents, String editSummary, final ProgressListener progressListener) throws IOException { public UploadResult uploadFile(String filename, InputStream file, long dataLength, String pageContents, String editSummary, final ProgressListener progressListener) throws IOException {
ApiResult result = api.upload(filename, file, dataLength, pageContents, editSummary, progressListener::onProgress); ApiResult result = api.upload(filename, file, dataLength, pageContents, editSummary, progressListener::onProgress);
Log.e("WTF", "Result: " +result.toString()); Log.e("WTF", "Result: " + result.toString());
String resultStatus = result.getString("/api/upload/@result"); String resultStatus = result.getString("/api/upload/@result");
if (!resultStatus.equals("Success")) { if (!resultStatus.equals("Success")) {

View file

@ -14,7 +14,7 @@ public class BaseActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
if(Utils.isDarkTheme(this)){ if (Utils.isDarkTheme(this)) {
currentTheme = true; currentTheme = true;
setTheme(R.style.DarkAppTheme); setTheme(R.style.DarkAppTheme);
} else { } else {
@ -28,7 +28,7 @@ public class BaseActivity extends AppCompatActivity {
protected void onResume() { protected void onResume() {
// Restart activity if theme is changed // Restart activity if theme is changed
boolean newTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false); boolean newTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("theme",false);
if(currentTheme!=newTheme){ //is activity theme changed if (currentTheme != newTheme) { //is activity theme changed
Intent intent = getIntent(); Intent intent = getIntent();
finish(); finish();
startActivity(intent); startActivity(intent);

View file

@ -123,9 +123,10 @@ public class FileUtils {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Timber.d(e); Timber.d(e);
} finally { } finally {
if (cursor != null) if (cursor != null) {
cursor.close(); cursor.close();
} }
}
return null; return null;
} }

View file

@ -221,7 +221,7 @@ public class GPSExtractor {
return decimalCoords; return decimalCoords;
} }
private double convertToDegree(String stringDMS){ private double convertToDegree(String stringDMS) {
double result; double result;
String[] DMS = stringDMS.split(",", 3); String[] DMS = stringDMS.split(",", 3);

View file

@ -124,7 +124,7 @@ public class MultipleShareActivity
dialog.setTitle(getResources().getQuantityString(R.plurals.starting_multiple_uploads, photosList.size(), photosList.size())); dialog.setTitle(getResources().getQuantityString(R.plurals.starting_multiple_uploads, photosList.size(), photosList.size()));
dialog.show(); dialog.show();
for(int i = 0; i < photosList.size(); i++) { for (int i = 0; i < photosList.size(); i++) {
Contribution up = photosList.get(i); Contribution up = photosList.get(i);
final int uploadCount = i + 1; // Goddamn Java final int uploadCount = i + 1; // Goddamn Java
@ -164,7 +164,7 @@ public class MultipleShareActivity
public void onCategoriesSave(List<String> categories) { public void onCategoriesSave(List<String> categories) {
if (categories.size() > 0) { if (categories.size() > 0) {
ContentProviderClient client = getContentResolver().acquireContentProviderClient(ModificationsContentProvider.AUTHORITY); ContentProviderClient client = getContentResolver().acquireContentProviderClient(ModificationsContentProvider.AUTHORITY);
for(Contribution contribution: photosList) { for (Contribution contribution: photosList) {
ModifierSequence categoriesSequence = new ModifierSequence(contribution.getContentUri()); ModifierSequence categoriesSequence = new ModifierSequence(contribution.getContentUri());
categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{}))); categoriesSequence.queueModifier(new CategoryModifier(categories.toArray(new String[]{})));
@ -189,7 +189,7 @@ public class MultipleShareActivity
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: case android.R.id.home:
if (mediaDetails.isVisible()) { if (mediaDetails.isVisible()) {
getSupportFragmentManager().popBackStack(); getSupportFragmentManager().popBackStack();
@ -225,7 +225,7 @@ public class MultipleShareActivity
} }
private void showDetail(int i) { private void showDetail(int i) {
if (mediaDetails == null ||!mediaDetails.isVisible()) { if (mediaDetails == null || !mediaDetails.isVisible()) {
mediaDetails = new MediaDetailPagerFragment(true); mediaDetails = new MediaDetailPagerFragment(true);
getSupportFragmentManager() getSupportFragmentManager()
.beginTransaction() .beginTransaction()
@ -252,7 +252,7 @@ public class MultipleShareActivity
if (photosList == null) { if (photosList == null) {
photosList = new ArrayList<>(); photosList = new ArrayList<>();
ArrayList<Uri> urisList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); ArrayList<Uri> urisList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for(int i=0; i < urisList.size(); i++) { for (int i = 0; i < urisList.size(); i++) {
Contribution up = new Contribution(); Contribution up = new Contribution();
Uri uri = urisList.get(i); Uri uri = urisList.get(i);
up.setLocalUri(uri); up.setLocalUri(uri);

View file

@ -67,7 +67,7 @@ public class MwVolleyApi {
* @param coords Coordinates to build query with * @param coords Coordinates to build query with
* @return URL for API query * @return URL for API query
*/ */
private String buildUrl (String coords){ private String buildUrl(String coords) {
Uri.Builder builder = Uri.parse(MWURL).buildUpon(); Uri.Builder builder = Uri.parse(MWURL).buildUpon();

View file

@ -59,7 +59,7 @@ public class UploadController {
} }
public void cleanup() { public void cleanup() {
if(isUploadServiceConnected) { if (isUploadServiceConnected) {
app.unbindService(uploadServiceConnection); app.unbindService(uploadServiceConnection);
} }
} }
@ -82,11 +82,11 @@ public class UploadController {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(app);
//Set creator, desc, and license //Set creator, desc, and license
if(TextUtils.isEmpty(contribution.getCreator())) { if (TextUtils.isEmpty(contribution.getCreator())) {
contribution.setCreator(app.getCurrentAccount().name); contribution.setCreator(app.getCurrentAccount().name);
} }
if(contribution.getDescription() == null) { if (contribution.getDescription() == null) {
contribution.setDescription(""); contribution.setDescription("");
} }
@ -103,11 +103,11 @@ public class UploadController {
protected Contribution doInBackground(Void... voids /* stare into you */) { protected Contribution doInBackground(Void... voids /* stare into you */) {
long length; long length;
try { try {
if(contribution.getDataLength() <= 0) { if (contribution.getDataLength() <= 0) {
length = app.getContentResolver() length = app.getContentResolver()
.openAssetFileDescriptor(contribution.getLocalUri(), "r") .openAssetFileDescriptor(contribution.getLocalUri(), "r")
.getLength(); .getLength();
if(length == -1) { if (length == -1) {
// Let us find out the long way! // Let us find out the long way!
length = Utils.countBytes(app.getContentResolver() length = Utils.countBytes(app.getContentResolver()
.openInputStream(contribution.getLocalUri())); .openInputStream(contribution.getLocalUri()));

View file

@ -15,6 +15,6 @@ public class ExecutorUtils {
} }
}; };
public static Executor uiExecutor () { return uiExecutor;} public static Executor uiExecutor() { return uiExecutor; }
} }

View file

@ -23,8 +23,8 @@ public class FragmentUtils {
.commitNow(); .commitNow();
return true; return true;
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
Timber.e(e, "Could not add & commit fragment. " + Timber.e(e, "Could not add & commit fragment. "
"Did you mean to call commitAllowingStateLoss?"); + "Did you mean to call commitAllowingStateLoss?");
} }
return false; return false;
} }