mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
commit
e56f8b88dd
8 changed files with 71 additions and 15 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
# Wikimedia Commons for Android
|
# Wikimedia Commons for Android
|
||||||
|
|
||||||
|
## v1.12
|
||||||
|
- Further bug fixes for Polish language
|
||||||
|
- Added Javadocs
|
||||||
|
|
||||||
## v1.11
|
## v1.11
|
||||||
- Bugfix for Polish language crash
|
- Bugfix for Polish language crash
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="fr.free.nrw.commons"
|
package="fr.free.nrw.commons"
|
||||||
android:versionCode="27"
|
android:versionCode="28"
|
||||||
android:versionName="1.11" >
|
android:versionName="1.12" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="9"
|
android:minSdkVersion="9"
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ import java.util.Set;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the category suggestion and selection screen. Category search is initiated here.
|
||||||
|
*/
|
||||||
public class CategorizationFragment extends SherlockFragment{
|
public class CategorizationFragment extends SherlockFragment{
|
||||||
public static interface OnCategoriesSaveHandler {
|
public static interface OnCategoriesSaveHandler {
|
||||||
public void onCategoriesSave(ArrayList<String> categories);
|
public void onCategoriesSave(ArrayList<String> categories);
|
||||||
|
|
@ -96,6 +98,10 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves recently-used categories and nearby categories, and merges them without duplicates.
|
||||||
|
* @return a list containing these categories
|
||||||
|
*/
|
||||||
protected ArrayList<String> recentCatQuery() {
|
protected ArrayList<String> recentCatQuery() {
|
||||||
ArrayList<String> items = new ArrayList<String>();
|
ArrayList<String> items = new ArrayList<String>();
|
||||||
Set<String> mergedItems = new LinkedHashSet<String>();
|
Set<String> mergedItems = new LinkedHashSet<String>();
|
||||||
|
|
@ -133,7 +139,11 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
return mergedItemsList;
|
return mergedItemsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays categories found to the user as they type in the search box
|
||||||
|
* @param categories a list of all categories found for the search string
|
||||||
|
* @param filter the search string
|
||||||
|
*/
|
||||||
protected void setCatsAfterAsync(ArrayList<String> categories, String filter) {
|
protected void setCatsAfterAsync(ArrayList<String> categories, String filter) {
|
||||||
|
|
||||||
if (getActivity() != null) {
|
if (getActivity() != null) {
|
||||||
|
|
@ -338,6 +348,12 @@ public class CategorizationFragment extends SherlockFragment{
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes asynchronous calls to the Commons MediaWiki API via anonymous subclasses of
|
||||||
|
* 'MethodAUpdater' and 'PrefixUpdater'. Some of their methods are overridden in order to
|
||||||
|
* aggregate the results. A CountDownLatch is used to ensure that MethodA results are shown
|
||||||
|
* above Prefix results.
|
||||||
|
*/
|
||||||
private void requestSearchResults() {
|
private void requestSearchResults() {
|
||||||
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package fr.free.nrw.commons.category;
|
package fr.free.nrw.commons.category;
|
||||||
|
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
@ -14,6 +13,11 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends asynchronous queries to the Commons MediaWiki API to retrieve categories that are close to
|
||||||
|
* the keyword typed in by the user. The 'srsearch' action-specific parameter is used for this
|
||||||
|
* purpose. This class should be subclassed in CategorizationFragment.java to aggregate the results.
|
||||||
|
*/
|
||||||
public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
||||||
|
|
||||||
private String filter;
|
private String filter;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,12 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends asynchronous queries to the Commons MediaWiki API to retrieve categories that share the
|
||||||
|
* same prefix as the keyword typed in by the user. The 'acprefix' action-specific parameter is used
|
||||||
|
* for this purpose. This class should be subclassed in CategorizationFragment.java to aggregate
|
||||||
|
* the results.
|
||||||
|
*/
|
||||||
public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
||||||
|
|
||||||
private String filter;
|
private String filter;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts geolocation to be passed to API for category suggestions. If a picture with geolocation
|
||||||
|
* is uploaded, extract latitude and longitude from EXIF data of image. If a picture without
|
||||||
|
* geolocation is uploaded, retrieve user's location (if enabled in Settings).
|
||||||
|
*/
|
||||||
public class GPSExtractor {
|
public class GPSExtractor {
|
||||||
|
|
||||||
private static final String TAG = GPSExtractor.class.getName();
|
private static final String TAG = GPSExtractor.class.getName();
|
||||||
|
|
@ -31,6 +36,10 @@ public class GPSExtractor {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if user enabled retrieval of their current location in Settings
|
||||||
|
* @return true if enabled, false if disabled
|
||||||
|
*/
|
||||||
private boolean gpsPreferenceEnabled() {
|
private boolean gpsPreferenceEnabled() {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
|
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
|
||||||
|
|
@ -38,6 +47,9 @@ public class GPSExtractor {
|
||||||
return gpsPref;
|
return gpsPref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a LocationManager to listen for current location
|
||||||
|
*/
|
||||||
protected void registerLocationManager() {
|
protected void registerLocationManager() {
|
||||||
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
|
||||||
criteria = new Criteria();
|
criteria = new Criteria();
|
||||||
|
|
@ -55,7 +67,10 @@ public class GPSExtractor {
|
||||||
locationManager.removeUpdates(myLocationListener);
|
locationManager.removeUpdates(myLocationListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Extract GPS coords of image
|
/**
|
||||||
|
* Extracts geolocation of image from EXIF data.
|
||||||
|
* @return coordinates of image as string (needs to be passed as a String in API query)
|
||||||
|
*/
|
||||||
public String getCoords() {
|
public String getCoords() {
|
||||||
|
|
||||||
ExifInterface exif;
|
ExifInterface exif;
|
||||||
|
|
@ -136,7 +151,10 @@ public class GPSExtractor {
|
||||||
return decLongitude;
|
return decLongitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Converts format of coords into decimal coords as required by MediaWiki API
|
/**
|
||||||
|
* Converts format of geolocation into decimal coordinates as required by MediaWiki API
|
||||||
|
* @return the coordinates in decimals
|
||||||
|
*/
|
||||||
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
||||||
|
|
||||||
if (latitude_ref.equals("N")) {
|
if (latitude_ref.equals("N")) {
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,17 @@ import com.android.volley.toolbox.Volley;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import fr.free.nrw.commons.caching.CacheController;
|
/**
|
||||||
|
* Uses the Volley library to implement asynchronous calls to the Commons MediaWiki API to match
|
||||||
|
* GPS coordinates with nearby Commons categories. Parses the results using GSON to obtain a list
|
||||||
|
* of relevant categories.
|
||||||
|
*/
|
||||||
public class MwVolleyApi {
|
public class MwVolleyApi {
|
||||||
|
|
||||||
private static RequestQueue REQUEST_QUEUE;
|
private static RequestQueue REQUEST_QUEUE;
|
||||||
|
|
@ -66,8 +68,9 @@ public class MwVolleyApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds URL with image coords for MediaWiki API calls
|
* Builds URL with image coords for MediaWiki API calls
|
||||||
* Example URL: https://commons.wikimedia.org/w/api.php?action=query&prop=categories|coordinates|pageprops&format=json&clshow=!hidden&coprop=type|name|dim|country|region|globe&codistancefrompoint=38.11386944444445|13.356263888888888&
|
* Example URL: https://commons.wikimedia.org/w/api.php?action=query&prop=categories|coordinates|pageprops&format=json&clshow=!hidden&coprop=type|name|dim|country|region|globe&codistancefrompoint=38.11386944444445|13.356263888888888&generator=geosearch&redirects=&ggscoord=38.11386944444445|1.356263888888888&ggsradius=100&ggslimit=10&ggsnamespace=6&ggsprop=type|name|dim|country|region|globe&ggsprimary=all&formatversion=2
|
||||||
* generator=geosearch&redirects=&ggscoord=38.11386944444445|13.356263888888888&ggsradius=100&ggslimit=10&ggsnamespace=6&ggsprop=type|name|dim|country|region|globe&ggsprimary=all&formatversion=2
|
* @param coords Coordinates to build query with
|
||||||
|
* @return URL for API query
|
||||||
*/
|
*/
|
||||||
private String buildUrl (String coords){
|
private String buildUrl (String coords){
|
||||||
|
|
||||||
|
|
@ -134,7 +137,6 @@ public class MwVolleyApi {
|
||||||
@Override
|
@Override
|
||||||
protected Response<QueryResponse> parseNetworkResponse(NetworkResponse response) {
|
protected Response<QueryResponse> parseNetworkResponse(NetworkResponse response) {
|
||||||
String json = parseString(response);
|
String json = parseString(response);
|
||||||
//Log.d(TAG, "json=" + json);
|
|
||||||
QueryResponse queryResponse = GSON.fromJson(json, QueryResponse.class);
|
QueryResponse queryResponse = GSON.fromJson(json, QueryResponse.class);
|
||||||
return Response.success(queryResponse, cacheEntry(response));
|
return Response.success(queryResponse, cacheEntry(response));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,10 @@ import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity for the title/desc screen after image is selected. Also starts processing image
|
||||||
|
* GPS coordinates or user location (if enabled in Settings) for category suggestions.
|
||||||
|
*/
|
||||||
public class ShareActivity
|
public class ShareActivity
|
||||||
extends AuthenticatedActivity
|
extends AuthenticatedActivity
|
||||||
implements SingleUploadFragment.OnUploadActionInitiated,
|
implements SingleUploadFragment.OnUploadActionInitiated,
|
||||||
|
|
@ -195,6 +197,10 @@ public class ShareActivity
|
||||||
requestAuthToken();
|
requestAuthToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiates retrieval of image coordinates or user coordinates, and caching of coordinates.
|
||||||
|
* Then initiates the calls to MediaWiki API through an instance of MwVolleyApi.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue