Merge pull request #563 from commons-app/prehackCleanup

Prehack cleanup
This commit is contained in:
Josephine Lim 2017-05-13 15:46:28 +02:00 committed by GitHub
commit 81d23a3b94
12 changed files with 55 additions and 65 deletions

View file

@ -94,9 +94,7 @@ public class EventLog {
data.put("appversion", "Android/" + BuildConfig.VERSION_NAME);
fullData.put("event", data);
return new URL(CommonsApplication.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";");
} catch (MalformedURLException e) {
throw new RuntimeException(e);
} catch (JSONException e) {
} catch (MalformedURLException | JSONException e) {
throw new RuntimeException(e);
}
}

View file

@ -69,9 +69,8 @@ public class LicenseList {
int nameId = stringIdByName(stringId);
//Log.d("Commons", "LicenseList.nameForTemplate: nameId: " + nameId);
if(nameId != 0) {
String name = res.getString(nameId);
//Log.d("Commons", "LicenseList.nameForTemplate: name: " + name);
return name;
return res.getString(nameId);
}
return template;
}

View file

@ -110,9 +110,7 @@ public class MediaDataExtractor {
doc = docBuilder.parse(new ByteArrayInputStream(source.getBytes("UTF-8")));
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (IllegalStateException e) {
throw new IOException(e);
} catch (SAXException e) {
} catch (IllegalStateException | SAXException e) {
throw new IOException(e);
}
Node templateNode = findTemplate(doc.getDocumentElement(), "information");

View file

@ -122,10 +122,7 @@ public class Utils {
Transformer transformer = null;
try {
transformer = TransformerFactory.newInstance().newTransformer();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
} catch (TransformerConfigurationException | TransformerFactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -202,53 +199,56 @@ public class Utils {
}
public static String licenseTemplateFor(String license) {
if (license.equals(Prefs.Licenses.CC_BY_3)) {
switch (license) {
case Prefs.Licenses.CC_BY_3:
return "{{self|cc-by-3.0}}";
} else if (license.equals(Prefs.Licenses.CC_BY_4)) {
case Prefs.Licenses.CC_BY_4:
return "{{self|cc-by-4.0}}";
} else if (license.equals(Prefs.Licenses.CC_BY_SA_3)) {
case Prefs.Licenses.CC_BY_SA_3:
return "{{self|cc-by-sa-3.0}}";
} else if (license.equals(Prefs.Licenses.CC_BY_SA_4)) {
case Prefs.Licenses.CC_BY_SA_4:
return "{{self|cc-by-sa-4.0}}";
} else if (license.equals(Prefs.Licenses.CC0)) {
case Prefs.Licenses.CC0:
return "{{self|cc-zero}}";
} else if (license.equals(Prefs.Licenses.CC_BY)) {
case Prefs.Licenses.CC_BY:
return "{{self|cc-by-3.0}}";
} else if (license.equals(Prefs.Licenses.CC_BY_SA)) {
case Prefs.Licenses.CC_BY_SA:
return "{{self|cc-by-sa-3.0}}";
}
throw new RuntimeException("Unrecognized license value: " + license);
}
public static int licenseNameFor(String license) {
if (license.equals(Prefs.Licenses.CC_BY_3)) {
switch (license) {
case Prefs.Licenses.CC_BY_3:
return R.string.license_name_cc_by;
} else if (license.equals(Prefs.Licenses.CC_BY_4)) {
case Prefs.Licenses.CC_BY_4:
return R.string.license_name_cc_by_four;
} else if (license.equals(Prefs.Licenses.CC_BY_SA_3)) {
case Prefs.Licenses.CC_BY_SA_3:
return R.string.license_name_cc_by_sa;
} else if (license.equals(Prefs.Licenses.CC_BY_SA_4)) {
case Prefs.Licenses.CC_BY_SA_4:
return R.string.license_name_cc_by_sa_four;
} else if (license.equals(Prefs.Licenses.CC0)) {
case Prefs.Licenses.CC0:
return R.string.license_name_cc0;
} else if (license.equals(Prefs.Licenses.CC_BY)) { // for backward compatibility to v2.1
case Prefs.Licenses.CC_BY: // for backward compatibility to v2.1
return R.string.license_name_cc_by_3_0;
} else if (license.equals(Prefs.Licenses.CC_BY_SA)) { // for backward compatibility to v2.1
case Prefs.Licenses.CC_BY_SA: // for backward compatibility to v2.1
return R.string.license_name_cc_by_sa_3_0;
}
throw new RuntimeException("Unrecognized license value: " + license);
}
public static String licenseUrlFor(String license) {
if (license.equals(Prefs.Licenses.CC_BY_3)) {
switch (license) {
case Prefs.Licenses.CC_BY_3:
return "https://creativecommons.org/licenses/by/3.0/";
} else if (license.equals(Prefs.Licenses.CC_BY_4)) {
case Prefs.Licenses.CC_BY_4:
return "https://creativecommons.org/licenses/by/4.0/";
} else if (license.equals(Prefs.Licenses.CC_BY_SA_3)) {
case Prefs.Licenses.CC_BY_SA_3:
return "https://creativecommons.org/licenses/by-sa/3.0/";
} else if (license.equals(Prefs.Licenses.CC_BY_SA_4)) {
case Prefs.Licenses.CC_BY_SA_4:
return "https://creativecommons.org/licenses/by-sa/4.0/";
} else if (license.equals(Prefs.Licenses.CC0)) {
case Prefs.Licenses.CC0:
return "https://creativecommons.org/publicdomain/zero/1.0/";
}
throw new RuntimeException("Unrecognized license value: " + license);

View file

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

View file

@ -357,8 +357,7 @@ public class CategorizationFragment extends Fragment {
new String[] {name},
null);
if (cursor.moveToFirst()) {
Category cat = Category.fromCursor(cursor);
return cat;
return Category.fromCursor(cursor);
}
} catch (RemoteException e) {
// This feels lazy, but to hell with checked exceptions. :)

View file

@ -108,7 +108,6 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
}
Timber.d("Found categories from Method A search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems;
return new ArrayList<>(filterYears(categories));
}
}

View file

@ -83,16 +83,14 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
if(TextUtils.isEmpty(filter)) {
ArrayList<String> mergedItems = new ArrayList<>(catFragment.mergeItems());
Timber.d("Merged items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(mergedItems));
return filteredItems;
return new ArrayList<>(filterYears(mergedItems));
}
//if user types in something that is in cache, return cached category
if(catFragment.categoriesCache.containsKey(filter)) {
ArrayList<String> cachedItems = new ArrayList<>(catFragment.categoriesCache.get(filter));
Timber.d("Found cache items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(cachedItems));
return filteredItems;
return new ArrayList<>(filterYears(cachedItems));
}
//otherwise if user has typed something in that isn't in cache, search API for matching categories
@ -119,7 +117,6 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
}
Timber.d("Found categories from Prefix search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems;
return new ArrayList<>(filterYears(categories));
}
}

View file

@ -195,7 +195,7 @@ public class Contribution extends Media {
cv.put(Table.COLUMN_LOCAL_URI, getLocalUri().toString());
}
if(getImageUrl() != null) {
cv.put(Table.COLUMN_IMAGE_URL, getImageUrl().toString());
cv.put(Table.COLUMN_IMAGE_URL, getImageUrl());
}
if(getDateUploaded() != null) {
cv.put(Table.COLUMN_UPLOADED, getDateUploaded().getTime());

View file

@ -38,7 +38,7 @@ public class ContributionController {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Commons/images/" + new Date().getTime() + ".jpg";
File _photoFile = new File(path);
try {
if(_photoFile.exists() == false) {
if(!_photoFile.exists()) {
_photoFile.getParentFile().mkdirs();
_photoFile.createNewFile();
}

View file

@ -220,7 +220,7 @@ public class MediaDetailFragment extends Fragment {
protected void onPostExecute(Boolean success) {
detailFetchTask = null;
if (success.booleanValue()) {
if (success) {
extractor.fill(media);
// Set text of desc, license, and categories

View file

@ -113,7 +113,7 @@ public class ShareActivity
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
startingToast.show();
if (cacheFound == false) {
if (!cacheFound) {
//Has to be called after apiCall.request()
app.cacheData.cacheCategory();
Timber.d("Cache the categories found");