Merge pull request #897 from poojithakr/codacy-issues

Fixing codacy issues. Reduced reported count from 550 to 518.
This commit is contained in:
Josephine Lim 2017-10-10 23:46:10 +10:00 committed by GitHub
commit 044659cd41
13 changed files with 51 additions and 41 deletions

View file

@ -147,10 +147,10 @@ public class CommonsApplication extends Application {
* @return Account|null
*/
public Account getCurrentAccount() {
if(currentAccount == null) {
if (currentAccount == null) {
AccountManager accountManager = AccountManager.get(this);
Account[] allAccounts = accountManager.getAccountsByType(AccountUtil.accountType());
if(allAccounts.length != 0) {
if (allAccounts.length != 0) {
currentAccount = allAccounts[0];
}
}
@ -161,7 +161,7 @@ public class CommonsApplication extends Application {
AccountManager accountManager = AccountManager.get(this);
Account curAccount = getCurrentAccount();
if(curAccount == null) {
if (curAccount == null) {
return false; // This should never happen
}
@ -224,11 +224,13 @@ public class CommonsApplication extends Application {
if (getIndex() == allAccounts.length) {
Timber.d("All accounts have been removed");
//TODO: fix preference manager
PreferenceManager.getDefaultSharedPreferences(getInstance()).edit().clear().commit();
PreferenceManager.getDefaultSharedPreferences(getInstance())
.edit().clear().commit();
SharedPreferences preferences = context
.getSharedPreferences("fr.free.nrw.commons", MODE_PRIVATE);
preferences.edit().clear().commit();
context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();
context.getSharedPreferences("prefs", Context.MODE_PRIVATE)
.edit().clear().commit();
preferences.edit().putBoolean("firstrun", false).apply();
updateAllDatabases();
currentAccount = null;

View file

@ -3,10 +3,10 @@ package fr.free.nrw.commons;
import android.support.annotation.Nullable;
public class License {
String key;
String template;
String url;
String name;
private String key;
private String template;
private String url;
private String name;
public License(String key, String template, String url, String name) {
if (key == null) {

View file

@ -242,9 +242,9 @@ public class Utils {
public static boolean xmlFastForward(XmlPullParser parser, String namespace, String element) {
try {
while (parser.next() != XmlPullParser.END_DOCUMENT) {
if (parser.getEventType() == XmlPullParser.START_TAG &&
parser.getNamespace().equals(namespace) &&
parser.getName().equals(element)) {
if (parser.getEventType() == XmlPullParser.START_TAG
&& parser.getNamespace().equals(namespace)
&& parser.getName().equals(element)) {
// We found it!
return true;
}
@ -267,7 +267,8 @@ public class Utils {
extension = "jpg";
}
title = jpegPattern.matcher(title).replaceFirst(".jpg");
if (extension != null && !title.toLowerCase(Locale.getDefault()).endsWith("." + extension.toLowerCase(Locale.ENGLISH))) {
if (extension != null && !title.toLowerCase(Locale.getDefault())
.endsWith("." + extension.toLowerCase(Locale.ENGLISH))) {
title += "." + extension;
}
return title;

View file

@ -14,7 +14,7 @@ import timber.log.Timber;
public abstract class AuthenticatedActivity extends NavigationBaseActivity {
String accountType;
private String accountType;
CommonsApplication app;
private String authCookie;

View file

@ -25,7 +25,8 @@ public class SignupActivity extends BaseActivity {
webView.setWebViewClient(new MyWebViewClient());
WebSettings webSettings = webView.getSettings();
//Needed to refresh Captcha. Might introduce XSS vulnerabilities, but we can trust Wikimedia's site... right?
/*Needed to refresh Captcha. Might introduce XSS vulnerabilities, but we can
trust Wikimedia's site... right?*/
webSettings.setJavaScriptEnabled(true);
webView.loadUrl(BuildConfig.SIGNUP_LANDING_URL);

View file

@ -32,7 +32,7 @@ public class CacheController {
public void cacheCategory() {
List<String> pointCatList = new ArrayList<>();
if (MwVolleyApi.GpsCatExists.getGpsCatExists()) {
pointCatList.addAll(MwVolleyApi.getGpsCat());
pointCatList.addAll(MwVolleyApi.getGpsCat());
Timber.d("Categories being cached: %s", pointCatList);
} else {
Timber.d("No categories found, so no categories cached");

View file

@ -197,7 +197,7 @@ public class CategorizationFragment extends Fragment {
.concatWith(
searchAll(filter)
.mergeWith(searchCategories(filter))
.concatWith( TextUtils.isEmpty(filter)
.concatWith(TextUtils.isEmpty(filter)
? defaultCategories() : Observable.empty())
)
.filter(categoryItem -> !containsYear(categoryItem.getName()))

View file

@ -142,11 +142,13 @@ public class CategoryContentProvider extends ContentProvider {
public int update(@NonNull Uri uri, ContentValues contentValues, String selection,
String[] selectionArgs) {
/*
SQL Injection warnings: First, note that we're not exposing this to the outside world (exported="false")
Even then, we should make sure to sanitize all user input appropriately. Input that passes through ContentValues
SQL Injection warnings: First, note that we're not exposing this to the
outside world (exported="false"). Even then, we should make sure to sanitize
all user input appropriately. Input that passes through ContentValues
should be fine. So only issues are those that pass in via concating.
In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise.
In here, the only concat created argument is for id. It is cast to an int,
and will error out otherwise.
*/
int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();

View file

@ -154,10 +154,12 @@ public class ContributionsContentProvider extends ContentProvider {
public int update(@NonNull Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) {
/*
SQL Injection warnings: First, note that we're not exposing this to the outside world (exported="false")
Even then, we should make sure to sanitize all user input appropriately. Input that passes through ContentValues
should be fine. So only issues are those that pass in via concating.
Even then, we should make sure to sanitize all user input appropriately.
Input that passes through ContentValuesshould be fine. So only issues are those that pass
in via concating.
In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise.
In here, the only concat created argument is for id. It is cast to an int, and will
error out otherwise.
*/
int uriType = uriMatcher.match(uri);
CommonsApplication app = (CommonsApplication) getContext().getApplicationContext();

View file

@ -27,7 +27,7 @@ public class ModifierSequence {
public ModifierSequence(Uri mediaUri, JSONObject data) {
this(mediaUri);
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)));
}
}
@ -41,7 +41,7 @@ public class ModifierSequence {
}
public String executeModifications(String pageName, String pageContents) {
for(PageModifier modifier: modifiers) {
for (PageModifier modifier: modifiers) {
pageContents = modifier.doModification(pageName, pageContents);
}
return pageContents;
@ -60,7 +60,7 @@ public class ModifierSequence {
JSONObject data = new JSONObject();
try {
JSONArray modifiersJSON = new JSONArray();
for(PageModifier modifier: modifiers) {
for (PageModifier modifier: modifiers) {
modifiersJSON.put(modifier.toJSON());
}
data.put("modifiers", modifiersJSON);
@ -81,7 +81,8 @@ public class ModifierSequence {
// Hardcoding column positions!
ModifierSequence ms = null;
try {
ms = new ModifierSequence(Uri.parse(cursor.getString(1)), new JSONObject(cursor.getString(2)));
ms = new ModifierSequence(Uri.parse(cursor.getString(1)),
new JSONObject(cursor.getString(2)));
} catch (JSONException e) {
throw new RuntimeException(e);
}

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 {
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");
if (!resultStatus.equals("Success")) {

View file

@ -63,7 +63,7 @@ public class MultipleShareActivity
@Override
public int getTotalMediaCount() {
if(photosList == null) {
if (photosList == null) {
return 0;
}
return photosList.size();
@ -71,7 +71,7 @@ public class MultipleShareActivity
@Override
public void notifyDatasetChanged() {
if(uploadsList != null) {
if (uploadsList != null) {
uploadsList.notifyDatasetChanged();
}
}
@ -145,7 +145,7 @@ public class MultipleShareActivity
uploadsList.setImageOnlyMode(true);
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
if(categorizationFragment == null) {
if (categorizationFragment == null) {
categorizationFragment = new CategorizationFragment();
}
// FIXME: Stops the keyboard from being shown 'stale' while moving out of this fragment into the next
@ -162,7 +162,7 @@ public class MultipleShareActivity
@Override
public void onCategoriesSave(List<String> categories) {
if(categories.size() > 0) {
if (categories.size() > 0) {
ContentProviderClient client = getContentResolver().acquireContentProviderClient(ModificationsContentProvider.AUTHORITY);
for(Contribution contribution: photosList) {
ModifierSequence categoriesSequence = new ModifierSequence(contribution.getContentUri());
@ -191,7 +191,7 @@ public class MultipleShareActivity
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
if(mediaDetails.isVisible()) {
if (mediaDetails.isVisible()) {
getSupportFragmentManager().popBackStack();
}
return true;
@ -209,7 +209,7 @@ public class MultipleShareActivity
ButterKnife.bind(this);
initDrawer();
if(savedInstanceState != null) {
if (savedInstanceState != null) {
photosList = savedInstanceState.getParcelableArrayList("uploadsList");
}
@ -225,7 +225,7 @@ public class MultipleShareActivity
}
private void showDetail(int i) {
if(mediaDetails == null ||!mediaDetails.isVisible()) {
if (mediaDetails == null ||!mediaDetails.isVisible()) {
mediaDetails = new MediaDetailPagerFragment(true);
getSupportFragmentManager()
.beginTransaction()
@ -248,8 +248,8 @@ public class MultipleShareActivity
app.getMWApi().setAuthCookie(authCookie);
Intent intent = getIntent();
if(intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
if(photosList == null) {
if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
if (photosList == null) {
photosList = new ArrayList<>();
ArrayList<Uri> urisList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for(int i=0; i < urisList.size(); i++) {
@ -265,7 +265,7 @@ public class MultipleShareActivity
}
uploadsList = (MultipleUploadListFragment) getSupportFragmentManager().findFragmentByTag("uploadsList");
if(uploadsList == null) {
if (uploadsList == null) {
uploadsList = new MultipleUploadListFragment();
getSupportFragmentManager()
.beginTransaction()
@ -287,7 +287,7 @@ public class MultipleShareActivity
@Override
public void onBackPressed() {
super.onBackPressed();
if(categorizationFragment != null && categorizationFragment.isVisible()) {
if (categorizationFragment != null && categorizationFragment.isVisible()) {
EventLog.schema(CommonsApplication.EVENT_CATEGORIZATION_ATTEMPT)
.param("username", app.getCurrentAccount().name)
.param("categories-count", categorizationFragment.getCurrentSelectedCount())
@ -307,7 +307,7 @@ public class MultipleShareActivity
@Override
public void onBackStackChanged() {
if(mediaDetails != null && mediaDetails.isVisible()) {
if (mediaDetails != null && mediaDetails.isVisible()) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} else {
getSupportActionBar().setDisplayHomeAsUpEnabled(false);

View file

@ -86,7 +86,8 @@ public class SingleUploadFragment extends Fragment {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_single_upload, container, false);
ButterKnife.bind(this, rootView);