mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Merge pull request #563 from commons-app/prehackCleanup
Prehack cleanup
This commit is contained in:
commit
81d23a3b94
12 changed files with 55 additions and 65 deletions
|
|
@ -94,9 +94,7 @@ public class EventLog {
|
||||||
data.put("appversion", "Android/" + BuildConfig.VERSION_NAME);
|
data.put("appversion", "Android/" + BuildConfig.VERSION_NAME);
|
||||||
fullData.put("event", data);
|
fullData.put("event", data);
|
||||||
return new URL(CommonsApplication.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";");
|
return new URL(CommonsApplication.EVENTLOG_URL + "?" + Utils.urlEncode(fullData.toString()) + ";");
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException | JSONException e) {
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,8 @@ public class LicenseList {
|
||||||
int nameId = stringIdByName(stringId);
|
int nameId = stringIdByName(stringId);
|
||||||
//Log.d("Commons", "LicenseList.nameForTemplate: nameId: " + nameId);
|
//Log.d("Commons", "LicenseList.nameForTemplate: nameId: " + nameId);
|
||||||
if(nameId != 0) {
|
if(nameId != 0) {
|
||||||
String name = res.getString(nameId);
|
|
||||||
//Log.d("Commons", "LicenseList.nameForTemplate: name: " + name);
|
//Log.d("Commons", "LicenseList.nameForTemplate: name: " + name);
|
||||||
return name;
|
return res.getString(nameId);
|
||||||
}
|
}
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,7 @@ public class MediaDataExtractor {
|
||||||
doc = docBuilder.parse(new ByteArrayInputStream(source.getBytes("UTF-8")));
|
doc = docBuilder.parse(new ByteArrayInputStream(source.getBytes("UTF-8")));
|
||||||
} catch (ParserConfigurationException e) {
|
} catch (ParserConfigurationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException | SAXException e) {
|
||||||
throw new IOException(e);
|
|
||||||
} catch (SAXException e) {
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
Node templateNode = findTemplate(doc.getDocumentElement(), "information");
|
Node templateNode = findTemplate(doc.getDocumentElement(), "information");
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,7 @@ public class Utils {
|
||||||
Transformer transformer = null;
|
Transformer transformer = null;
|
||||||
try {
|
try {
|
||||||
transformer = TransformerFactory.newInstance().newTransformer();
|
transformer = TransformerFactory.newInstance().newTransformer();
|
||||||
} catch (TransformerConfigurationException e) {
|
} catch (TransformerConfigurationException | TransformerFactoryConfigurationError e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (TransformerFactoryConfigurationError e) {
|
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -202,53 +199,56 @@ public class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String licenseTemplateFor(String license) {
|
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}}";
|
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}}";
|
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}}";
|
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}}";
|
return "{{self|cc-by-sa-4.0}}";
|
||||||
} else if (license.equals(Prefs.Licenses.CC0)) {
|
case Prefs.Licenses.CC0:
|
||||||
return "{{self|cc-zero}}";
|
return "{{self|cc-zero}}";
|
||||||
} else if (license.equals(Prefs.Licenses.CC_BY)) {
|
case Prefs.Licenses.CC_BY:
|
||||||
return "{{self|cc-by-3.0}}";
|
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}}";
|
return "{{self|cc-by-sa-3.0}}";
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Unrecognized license value: " + license);
|
throw new RuntimeException("Unrecognized license value: " + license);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int licenseNameFor(String 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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
return R.string.license_name_cc_by_sa_3_0;
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Unrecognized license value: " + license);
|
throw new RuntimeException("Unrecognized license value: " + license);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String licenseUrlFor(String 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/";
|
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/";
|
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/";
|
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/";
|
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/";
|
return "https://creativecommons.org/publicdomain/zero/1.0/";
|
||||||
}
|
}
|
||||||
throw new RuntimeException("Unrecognized license value: " + license);
|
throw new RuntimeException("Unrecognized license value: " + license);
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public class CacheController {
|
||||||
|
|
||||||
public void cacheCategory() {
|
public void cacheCategory() {
|
||||||
List<String> pointCatList = new ArrayList<>();
|
List<String> pointCatList = new ArrayList<>();
|
||||||
if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true) {
|
if (MwVolleyApi.GpsCatExists.getGpsCatExists()) {
|
||||||
pointCatList.addAll(MwVolleyApi.getGpsCat());
|
pointCatList.addAll(MwVolleyApi.getGpsCat());
|
||||||
Timber.d("Categories being cached: %s", pointCatList);
|
Timber.d("Categories being cached: %s", pointCatList);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -357,8 +357,7 @@ public class CategorizationFragment extends Fragment {
|
||||||
new String[] {name},
|
new String[] {name},
|
||||||
null);
|
null);
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
Category cat = Category.fromCursor(cursor);
|
return Category.fromCursor(cursor);
|
||||||
return cat;
|
|
||||||
}
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// This feels lazy, but to hell with checked exceptions. :)
|
// This feels lazy, but to hell with checked exceptions. :)
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,6 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.d("Found categories from Method A search, waiting for filter");
|
Timber.d("Found categories from Method A search, waiting for filter");
|
||||||
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
|
return new ArrayList<>(filterYears(categories));
|
||||||
return filteredItems;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,16 +83,14 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
||||||
if(TextUtils.isEmpty(filter)) {
|
if(TextUtils.isEmpty(filter)) {
|
||||||
ArrayList<String> mergedItems = new ArrayList<>(catFragment.mergeItems());
|
ArrayList<String> mergedItems = new ArrayList<>(catFragment.mergeItems());
|
||||||
Timber.d("Merged items, waiting for filter");
|
Timber.d("Merged items, waiting for filter");
|
||||||
ArrayList<String> filteredItems = new ArrayList<>(filterYears(mergedItems));
|
return new ArrayList<>(filterYears(mergedItems));
|
||||||
return filteredItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if user types in something that is in cache, return cached category
|
//if user types in something that is in cache, return cached category
|
||||||
if(catFragment.categoriesCache.containsKey(filter)) {
|
if(catFragment.categoriesCache.containsKey(filter)) {
|
||||||
ArrayList<String> cachedItems = new ArrayList<>(catFragment.categoriesCache.get(filter));
|
ArrayList<String> cachedItems = new ArrayList<>(catFragment.categoriesCache.get(filter));
|
||||||
Timber.d("Found cache items, waiting for filter");
|
Timber.d("Found cache items, waiting for filter");
|
||||||
ArrayList<String> filteredItems = new ArrayList<>(filterYears(cachedItems));
|
return new ArrayList<>(filterYears(cachedItems));
|
||||||
return filteredItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//otherwise if user has typed something in that isn't in cache, search API for matching categories
|
//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");
|
Timber.d("Found categories from Prefix search, waiting for filter");
|
||||||
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
|
return new ArrayList<>(filterYears(categories));
|
||||||
return filteredItems;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ public class Contribution extends Media {
|
||||||
cv.put(Table.COLUMN_LOCAL_URI, getLocalUri().toString());
|
cv.put(Table.COLUMN_LOCAL_URI, getLocalUri().toString());
|
||||||
}
|
}
|
||||||
if(getImageUrl() != null) {
|
if(getImageUrl() != null) {
|
||||||
cv.put(Table.COLUMN_IMAGE_URL, getImageUrl().toString());
|
cv.put(Table.COLUMN_IMAGE_URL, getImageUrl());
|
||||||
}
|
}
|
||||||
if(getDateUploaded() != null) {
|
if(getDateUploaded() != null) {
|
||||||
cv.put(Table.COLUMN_UPLOADED, getDateUploaded().getTime());
|
cv.put(Table.COLUMN_UPLOADED, getDateUploaded().getTime());
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class ContributionController {
|
||||||
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Commons/images/" + new Date().getTime() + ".jpg";
|
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Commons/images/" + new Date().getTime() + ".jpg";
|
||||||
File _photoFile = new File(path);
|
File _photoFile = new File(path);
|
||||||
try {
|
try {
|
||||||
if(_photoFile.exists() == false) {
|
if(!_photoFile.exists()) {
|
||||||
_photoFile.getParentFile().mkdirs();
|
_photoFile.getParentFile().mkdirs();
|
||||||
_photoFile.createNewFile();
|
_photoFile.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ public class MediaDetailFragment extends Fragment {
|
||||||
protected void onPostExecute(Boolean success) {
|
protected void onPostExecute(Boolean success) {
|
||||||
detailFetchTask = null;
|
detailFetchTask = null;
|
||||||
|
|
||||||
if (success.booleanValue()) {
|
if (success) {
|
||||||
extractor.fill(media);
|
extractor.fill(media);
|
||||||
|
|
||||||
// Set text of desc, license, and categories
|
// Set text of desc, license, and categories
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ public class ShareActivity
|
||||||
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
|
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
|
||||||
startingToast.show();
|
startingToast.show();
|
||||||
|
|
||||||
if (cacheFound == false) {
|
if (!cacheFound) {
|
||||||
//Has to be called after apiCall.request()
|
//Has to be called after apiCall.request()
|
||||||
app.cacheData.cacheCategory();
|
app.cacheData.cacheCategory();
|
||||||
Timber.d("Cache the categories found");
|
Timber.d("Cache the categories found");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue