mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Minor changes
As per @Niedzielski's feedback
This commit is contained in:
parent
b7ebd202f3
commit
77b8ab0c4c
2 changed files with 36 additions and 35 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package fr.free.nrw.commons.upload;
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.volley.Cache;
|
import com.android.volley.Cache;
|
||||||
|
|
@ -28,7 +29,39 @@ public class MwVolleyApi {
|
||||||
public MwVolleyApi(Context context) {
|
public MwVolleyApi(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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&
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
public String buildUrl (String coords){
|
||||||
|
|
||||||
|
Uri.Builder builder = Uri.parse("https://commons.wikimedia.org/").buildUpon();
|
||||||
|
|
||||||
|
builder.appendPath("w")
|
||||||
|
.appendPath("api.php")
|
||||||
|
.appendQueryParameter("action", "query")
|
||||||
|
.appendQueryParameter("prop", "categories|coordinates|pageprops")
|
||||||
|
.appendQueryParameter("format", "json")
|
||||||
|
.appendQueryParameter("clshow", "!hidden")
|
||||||
|
.appendQueryParameter("coprop", "type|name|dim|country|region|globe")
|
||||||
|
.appendQueryParameter("codistancefrompoint", coords)
|
||||||
|
.appendQueryParameter("generator", "geosearch")
|
||||||
|
.appendQueryParameter("ggscoord", coords)
|
||||||
|
.appendQueryParameter("ggsradius", "100")
|
||||||
|
.appendQueryParameter("ggslimit", "10")
|
||||||
|
.appendQueryParameter("ggsnamespace", "6")
|
||||||
|
.appendQueryParameter("ggsprop", "type|name|dim|country|region|globe")
|
||||||
|
.appendQueryParameter("ggsprimary", "all")
|
||||||
|
.appendQueryParameter("formatversion", "2");
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void request(String apiUrl) {
|
public void request(String apiUrl) {
|
||||||
|
|
||||||
JsonRequest<QueryResponse> request = new QueryRequest(apiUrl,
|
JsonRequest<QueryResponse> request = new QueryRequest(apiUrl,
|
||||||
new LogResponseListener<QueryResponse>(), new LogResponseErrorListener());
|
new LogResponseListener<QueryResponse>(), new LogResponseErrorListener());
|
||||||
getQueue().add(request);
|
getQueue().add(request);
|
||||||
|
|
|
||||||
|
|
@ -184,16 +184,15 @@ public class ShareActivity
|
||||||
String coords = imageObj.getCoords();
|
String coords = imageObj.getCoords();
|
||||||
Log.d("Image", "Coords of image: " + coords);
|
Log.d("Image", "Coords of image: " + coords);
|
||||||
|
|
||||||
|
MwVolleyApi apiCall = new MwVolleyApi(this);
|
||||||
|
|
||||||
//build URL with image coords for MediaWiki API calls
|
//build URL with image coords for MediaWiki API calls
|
||||||
String apiUrl = UrlBuilder.buildUrl(coords);
|
String apiUrl = apiCall.buildUrl(coords);
|
||||||
Log.d("Image", "URL: " + apiUrl);
|
Log.d("Image", "URL: " + apiUrl);
|
||||||
|
|
||||||
|
|
||||||
//asynchronous calls to MediaWiki Commons API to match image coords with nearby Commons categories
|
//asynchronous calls to MediaWiki Commons API to match image coords with nearby Commons categories
|
||||||
MwVolleyApi apiCall = new MwVolleyApi(this);
|
|
||||||
apiCall.request(apiUrl);
|
apiCall.request(apiUrl);
|
||||||
|
|
||||||
|
|
||||||
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
||||||
|
|
||||||
if(savedInstanceState != null) {
|
if(savedInstanceState != null) {
|
||||||
|
|
@ -220,35 +219,4 @@ public class ShareActivity
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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&
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
public static class UrlBuilder {
|
|
||||||
private static String buildUrl (String coords){
|
|
||||||
|
|
||||||
Uri.Builder builder = Uri.parse("https://commons.wikimedia.org/").buildUpon();
|
|
||||||
|
|
||||||
builder.appendPath("w")
|
|
||||||
.appendPath("api.php")
|
|
||||||
.appendQueryParameter("action", "query")
|
|
||||||
.appendQueryParameter("prop", "categories|coordinates|pageprops")
|
|
||||||
.appendQueryParameter("format", "json")
|
|
||||||
.appendQueryParameter("clshow", "!hidden")
|
|
||||||
.appendQueryParameter("coprop", "type|name|dim|country|region|globe")
|
|
||||||
.appendQueryParameter("codistancefrompoint", coords)
|
|
||||||
.appendQueryParameter("generator", "geosearch")
|
|
||||||
.appendQueryParameter("ggscoord", coords)
|
|
||||||
.appendQueryParameter("ggsradius", "100")
|
|
||||||
.appendQueryParameter("ggslimit", "10")
|
|
||||||
.appendQueryParameter("ggsnamespace", "6")
|
|
||||||
.appendQueryParameter("ggsprop", "type|name|dim|country|region|globe")
|
|
||||||
.appendQueryParameter("ggsprimary", "all")
|
|
||||||
.appendQueryParameter("formatversion", "2");
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue