mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge remote-tracking branch 'refs/remotes/commons-app/master'
This commit is contained in:
commit
8155a0d3d6
18 changed files with 122 additions and 288 deletions
|
|
@ -6,7 +6,6 @@ dependencies {
|
|||
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
|
||||
compile 'in.yuvi:http.fluent:1.3'
|
||||
compile 'com.android.volley:volley:1.0.0'
|
||||
compile 'com.nostra13.universalimageloader:universal-image-loader:1.8.4'
|
||||
compile 'ch.acra:acra:4.7.0'
|
||||
compile 'org.mediawiki:api:1.3'
|
||||
compile 'commons-codec:commons-codec:1.10'
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ SELECT
|
|||
SERVICE wikibase:around {
|
||||
?item wdt:P625 ?location.
|
||||
bd:serviceParam wikibase:center "Point(${LONG} ${LAT})"^^geo:wktLiteral.
|
||||
bd:serviceParam wikibase:radius "${RADIUS}" . # Radius in kilometers.
|
||||
bd:serviceParam wikibase:radius "${RAD}" . # Radius in kilometers.
|
||||
}
|
||||
|
||||
# ... and without an image.
|
||||
|
|
|
|||
|
|
@ -12,16 +12,17 @@ import android.os.Build;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.toolbox.BasicNetwork;
|
||||
import com.android.volley.toolbox.DiskBasedCache;
|
||||
import com.android.volley.toolbox.HurlStack;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.stetho.Stetho;
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.TotalSizeLimitedDiscCache;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||
|
||||
import fr.free.nrw.commons.caching.CacheController;
|
||||
import fr.free.nrw.commons.category.Category;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||
import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||
import fr.free.nrw.commons.auth.AccountUtil;
|
||||
import fr.free.nrw.commons.nearby.NearbyPlaces;
|
||||
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
|
||||
import org.acra.ACRA;
|
||||
|
|
@ -84,7 +85,6 @@ public class CommonsApplication extends Application {
|
|||
private AbstractHttpClient httpClient = null;
|
||||
private MWApi api = null;
|
||||
private CacheController cacheData = null;
|
||||
private RequestQueue volleyQueue = null;
|
||||
private DBOpenHelper dbOpenHelper = null;
|
||||
private NearbyPlaces nearbyPlaces = null;
|
||||
|
||||
|
|
@ -139,15 +139,6 @@ public class CommonsApplication extends Application {
|
|||
return cacheData;
|
||||
}
|
||||
|
||||
public RequestQueue getVolleyQueue() {
|
||||
if (volleyQueue == null) {
|
||||
DiskBasedCache cache = new DiskBasedCache(getCacheDir(), 16 * 1024 * 1024);
|
||||
volleyQueue = new RequestQueue(cache, new BasicNetwork(new HurlStack()));
|
||||
volleyQueue.start();
|
||||
}
|
||||
return volleyQueue;
|
||||
}
|
||||
|
||||
public synchronized DBOpenHelper getDBOpenHelper() {
|
||||
if (dbOpenHelper == null) {
|
||||
dbOpenHelper = new DBOpenHelper(this);
|
||||
|
|
@ -182,11 +173,6 @@ public class CommonsApplication extends Application {
|
|||
// Fire progress callbacks for every 3% of uploaded content
|
||||
System.setProperty("in.yuvi.http.fluent.PROGRESS_TRIGGER_THRESHOLD", "3.0");
|
||||
|
||||
ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(this)
|
||||
.discCache(new TotalSizeLimitedDiscCache(StorageUtils.getCacheDirectory(this), 128 * 1024 * 1024))
|
||||
.build();
|
||||
ImageLoader.getInstance().init(imageLoaderConfiguration);
|
||||
|
||||
Fresco.initialize(this);
|
||||
|
||||
// Initialize EventLogging
|
||||
|
|
@ -194,14 +180,6 @@ public class CommonsApplication extends Application {
|
|||
|
||||
//For caching area -> categories
|
||||
cacheData = new CacheController();
|
||||
|
||||
DiskBasedCache cache = new DiskBasedCache(getCacheDir(), 16 * 1024 * 1024);
|
||||
volleyQueue = new RequestQueue(cache, new BasicNetwork(new HurlStack()));
|
||||
volleyQueue.start();
|
||||
}
|
||||
|
||||
public MWApi getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -268,15 +246,14 @@ public class CommonsApplication extends Application {
|
|||
preferences.edit().clear().commit();
|
||||
context.getSharedPreferences("prefs", Context.MODE_PRIVATE).edit().clear().commit();
|
||||
preferences.edit().putBoolean("firstrun", false).apply();
|
||||
updateAllDatabases(context);
|
||||
updateAllDatabases();
|
||||
currentAccount = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all tables and re-creates them.
|
||||
* @param context context
|
||||
*/
|
||||
public void updateAllDatabases(Context context) {
|
||||
public void updateAllDatabases() {
|
||||
DBOpenHelper dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
|
||||
dbOpenHelper.getReadableDatabase().close();
|
||||
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
|
||||
|
|
|
|||
|
|
@ -116,10 +116,6 @@ public class Media implements Parcelable {
|
|||
this.creator = creator;
|
||||
}
|
||||
|
||||
public String getThumbnailUrl(int width) {
|
||||
return Utils.makeThumbUrl(getImageUrl(), getFilename(), width);
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.mediawiki.api.ApiResult;
|
||||
|
||||
class MediaThumbnailFetchTask extends AsyncTask<String, String, String> {
|
||||
private static final String THUMB_SIZE = "640";
|
||||
protected final Media media;
|
||||
|
||||
public MediaThumbnailFetchTask(@NonNull Media media) {
|
||||
this.media = media;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(String... params) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.AttributeSet;
|
||||
|
|
@ -27,15 +28,16 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
if (currentThumbnailTask != null) {
|
||||
currentThumbnailTask.cancel(true);
|
||||
}
|
||||
setImageURI((String) null);
|
||||
if(media == null) {
|
||||
setImageURI((String) null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (thumbnailUrlCache.get(media.getFilename()) != null) {
|
||||
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
|
||||
} else {
|
||||
currentThumbnailTask = new ThumbnailFetchTask();
|
||||
setImageURI((String) null);
|
||||
currentThumbnailTask = new ThumbnailFetchTask(media);
|
||||
currentThumbnailTask.execute(media.getFilename());
|
||||
}
|
||||
}
|
||||
|
|
@ -53,11 +55,16 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
}
|
||||
|
||||
private class ThumbnailFetchTask extends MediaThumbnailFetchTask {
|
||||
ThumbnailFetchTask(@NonNull Media media) {
|
||||
super(media);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String result) {
|
||||
if (isCancelled()) {
|
||||
return;
|
||||
}
|
||||
thumbnailUrlCache.put(media.getFilename(), result);
|
||||
setImageUrl(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,8 @@ package fr.free.nrw.commons;
|
|||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
|
||||
import fr.free.nrw.commons.settings.Prefs;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -142,26 +137,6 @@ public class Utils {
|
|||
return outputStream.toString();
|
||||
}
|
||||
|
||||
private static DisplayImageOptions.Builder defaultImageOptionsBuilder;
|
||||
|
||||
public static DisplayImageOptions.Builder getGenericDisplayOptions() {
|
||||
if (defaultImageOptionsBuilder == null) {
|
||||
defaultImageOptionsBuilder = new DisplayImageOptions.Builder().cacheInMemory()
|
||||
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
// List views flicker badly during data updates on Android 2.3; we
|
||||
// haven't quite figured out why but cells seem to be rearranged oddly.
|
||||
// Disable the fade-in on 2.3 to reduce the effect.
|
||||
defaultImageOptionsBuilder = defaultImageOptionsBuilder
|
||||
.displayer(new FadeInBitmapDisplayer(300));
|
||||
}
|
||||
defaultImageOptionsBuilder = defaultImageOptionsBuilder
|
||||
.cacheInMemory()
|
||||
.resetViewBeforeLoading();
|
||||
}
|
||||
return defaultImageOptionsBuilder;
|
||||
}
|
||||
|
||||
private static final URLCodec urlCodec = new URLCodec();
|
||||
|
||||
public static String urlEncode(String url) {
|
||||
|
|
@ -181,21 +156,6 @@ public class Utils {
|
|||
return count;
|
||||
}
|
||||
|
||||
public static String makeThumbUrl(String imageUrl, String filename, int width) {
|
||||
// Ugly Hack!
|
||||
// Update: OH DEAR GOD WHAT A HORRIBLE HACK I AM SO SORRY
|
||||
if (imageUrl.endsWith("webm")) {
|
||||
return imageUrl.replaceFirst("test/", "test/thumb/").replace("commons/", "commons/thumb/") + "/" + width + "px--" + filename.replaceAll("File:", "").replaceAll(" ", "_") + ".jpg";
|
||||
} else {
|
||||
String thumbUrl = imageUrl.replaceFirst("test/", "test/thumb/").replace("commons/", "commons/thumb/") + "/" + width + "px-" + filename.replaceAll("File:", "").replaceAll(" ", "_");
|
||||
if (thumbUrl.endsWith("jpg") || thumbUrl.endsWith("png") || thumbUrl.endsWith("jpeg")) {
|
||||
return thumbUrl;
|
||||
} else {
|
||||
return thumbUrl + ".png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String capitalize(String string) {
|
||||
return string.substring(0, 1).toUpperCase(Locale.getDefault()) + string.substring(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ class ContributionViewHolder {
|
|||
final TextView seqNumView;
|
||||
final ProgressBar progressView;
|
||||
|
||||
String url;
|
||||
|
||||
ContributionViewHolder(View parent) {
|
||||
imageView = (MediaWikiImageView) parent.findViewById(R.id.contributionImage);
|
||||
titleView = (TextView)parent.findViewById(R.id.contributionTitle);
|
||||
|
|
|
|||
|
|
@ -3,25 +3,13 @@ package fr.free.nrw.commons.contributions;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.support.v4.widget.CursorAdapter;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.assist.SimpleImageLoadingListener;
|
||||
|
||||
import fr.free.nrw.commons.MediaWikiImageView;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
|
||||
class ContributionsListAdapter extends CursorAdapter {
|
||||
|
||||
private DisplayImageOptions contributionDisplayOptions = Utils.getGenericDisplayOptions().build();
|
||||
|
||||
private Activity activity;
|
||||
|
||||
public ContributionsListAdapter(Activity activity, Cursor c, int flags) {
|
||||
|
|
@ -42,36 +30,7 @@ class ContributionsListAdapter extends CursorAdapter {
|
|||
final ContributionViewHolder views = (ContributionViewHolder)view.getTag();
|
||||
final Contribution contribution = Contribution.fromCursor(cursor);
|
||||
|
||||
String actualUrl = (contribution.getLocalUri() != null && !TextUtils.isEmpty(contribution.getLocalUri().toString())) ? contribution.getLocalUri().toString() : contribution.getThumbnailUrl(640);
|
||||
|
||||
if(views.url == null || !views.url.equals(actualUrl)) {
|
||||
if(actualUrl.startsWith("http")) {
|
||||
MediaWikiImageView mwImageView = views.imageView;
|
||||
mwImageView.setMedia(contribution);
|
||||
// FIXME: For transparent images
|
||||
} else {
|
||||
|
||||
ImageLoader.getInstance().displayImage(actualUrl, views.imageView, contributionDisplayOptions, new SimpleImageLoadingListener() {
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
if(loadedImage.hasAlpha()) {
|
||||
views.imageView.setBackgroundResource(android.R.color.white);
|
||||
}
|
||||
views.seqNumView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
super.onLoadingFailed(imageUri, view, failReason);
|
||||
MediaWikiImageView mwImageView = views.imageView;
|
||||
mwImageView.setMedia(contribution);
|
||||
}
|
||||
});
|
||||
}
|
||||
views.url = actualUrl;
|
||||
}
|
||||
|
||||
views.imageView.setMedia(contribution);
|
||||
views.titleView.setText(contribution.getDisplayTitle());
|
||||
|
||||
views.seqNumView.setText(String.valueOf(cursor.getPosition() + 1));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons.media;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.database.DataSetObserver;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
|
@ -17,10 +16,6 @@ import android.widget.ProgressBar;
|
|||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.assist.FailReason;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -38,14 +33,9 @@ import timber.log.Timber;
|
|||
public class MediaDetailFragment extends Fragment {
|
||||
|
||||
private boolean editable;
|
||||
private DisplayImageOptions displayOptions;
|
||||
private MediaDetailPagerFragment.MediaDetailProvider detailProvider;
|
||||
private int index;
|
||||
|
||||
public static MediaDetailFragment forMedia(int index) {
|
||||
return forMedia(index, false);
|
||||
}
|
||||
|
||||
public static MediaDetailFragment forMedia(int index, boolean editable) {
|
||||
MediaDetailFragment mf = new MediaDetailFragment();
|
||||
|
||||
|
|
@ -188,93 +178,44 @@ public class MediaDetailFragment extends Fragment {
|
|||
|
||||
private void displayMediaDetails(final Media media) {
|
||||
//Always load image from Internet to allow viewing the desc, license, and cats
|
||||
String actualUrl = media.getThumbnailUrl(640);
|
||||
if(actualUrl.startsWith("http")) {
|
||||
Timber.d("Actual URL starts with http and is: %s", actualUrl);
|
||||
MediaWikiImageView mwImage = (MediaWikiImageView) image;
|
||||
mwImage.setMedia(media);
|
||||
|
||||
MediaWikiImageView mwImage = (MediaWikiImageView)image;
|
||||
mwImage.setMedia(media);
|
||||
// FIXME: For transparent images
|
||||
// FIXME: keep the spinner going while we load data
|
||||
// FIXME: cache this data
|
||||
// Load image metadata: desc, license, categories
|
||||
detailFetchTask = new AsyncTask<Void, Void, Boolean>() {
|
||||
private MediaDataExtractor extractor;
|
||||
|
||||
// FIXME: For transparent images
|
||||
// FIXME: keep the spinner going while we load data
|
||||
// FIXME: cache this data
|
||||
// Load image metadata: desc, license, categories
|
||||
detailFetchTask = new AsyncTask<Void, Void, Boolean>() {
|
||||
private MediaDataExtractor extractor;
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
extractor = new MediaDataExtractor(media.getFilename(), licenseList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
extractor = new MediaDataExtractor(media.getFilename(), licenseList);
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
try {
|
||||
extractor.fetch();
|
||||
return Boolean.TRUE;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
try {
|
||||
extractor.fetch();
|
||||
return Boolean.TRUE;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Boolean success) {
|
||||
detailFetchTask = null;
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean success) {
|
||||
detailFetchTask = null;
|
||||
|
||||
if (success) {
|
||||
extractor.fill(media);
|
||||
|
||||
// Set text of desc, license, and categories
|
||||
desc.setText(prettyDescription(media));
|
||||
license.setText(prettyLicense(media));
|
||||
coordinates.setText(prettyCoordinates(media));
|
||||
uploadedDate.setText(prettyUploadedDate(media));
|
||||
|
||||
categoryNames.clear();
|
||||
categoryNames.addAll(media.getCategories());
|
||||
|
||||
categoriesLoaded = true;
|
||||
categoriesPresent = (categoryNames.size() > 0);
|
||||
if (!categoriesPresent) {
|
||||
// Stick in a filler element.
|
||||
categoryNames.add(getString(R.string.detail_panel_cats_none));
|
||||
}
|
||||
rebuildCatList();
|
||||
} else {
|
||||
Timber.d("Failed to load photo details.");
|
||||
}
|
||||
}
|
||||
};
|
||||
detailFetchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
//This should not usually happen, image along with associated details should always be loaded from Internet, but keeping this for now for backup.
|
||||
//Even if image is loaded from device storage, it will display, albeit with empty desc and cat.
|
||||
Timber.d("Actual URL does not start with http and is: %s", actualUrl);
|
||||
com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(actualUrl, image, displayOptions, new ImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingStarted(String s, View view) {
|
||||
loadingProgress.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String s, View view, FailReason failReason) {
|
||||
loadingProgress.setVisibility(View.GONE);
|
||||
loadingFailed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingComplete(String s, View view, Bitmap bitmap) {
|
||||
loadingProgress.setVisibility(View.GONE);
|
||||
loadingFailed.setVisibility(View.GONE);
|
||||
image.setVisibility(View.VISIBLE);
|
||||
if(bitmap.hasAlpha()) {
|
||||
image.setBackgroundResource(android.R.color.white);
|
||||
}
|
||||
if (success) {
|
||||
extractor.fill(media);
|
||||
|
||||
// Set text of desc, license, and categories
|
||||
desc.setText(prettyDescription(media));
|
||||
license.setText(prettyLicense(media));
|
||||
coordinates.setText(prettyCoordinates(media));
|
||||
uploadedDate.setText(prettyUploadedDate(media));
|
||||
|
||||
categoryNames.clear();
|
||||
categoryNames.addAll(media.getCategories());
|
||||
|
|
@ -286,27 +227,18 @@ public class MediaDetailFragment extends Fragment {
|
|||
categoryNames.add(getString(R.string.detail_panel_cats_none));
|
||||
}
|
||||
rebuildCatList();
|
||||
} else {
|
||||
Timber.d("Failed to load photo details.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingCancelled(String s, View view) {
|
||||
Timber.e("Image loading cancelled. But why?");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
detailFetchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
title.setText(media.getDisplayTitle());
|
||||
desc.setText(""); // fill in from network...
|
||||
license.setText(""); // fill in from network...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
displayOptions = Utils.getGenericDisplayOptions().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (detailFetchTask != null) {
|
||||
|
|
|
|||
|
|
@ -149,6 +149,12 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
checkGps();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
nearbyAsyncTask.cancel(true);
|
||||
}
|
||||
|
||||
protected void refreshView() {
|
||||
nearbyAsyncTask = new NearbyAsyncTask(this);
|
||||
nearbyAsyncTask.execute();
|
||||
|
|
|
|||
|
|
@ -41,10 +41,7 @@ public class NearbyController {
|
|||
NearbyPlaces nearbyPlaces = CommonsApplication.getInstance().getNearbyPlaces();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
List<Place> places = prefs.getBoolean("useWikidata", true)
|
||||
? nearbyPlaces.getFromWikidataQuery(
|
||||
context,
|
||||
curLatLng,
|
||||
Locale.getDefault().getLanguage())
|
||||
? nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage())
|
||||
: nearbyPlaces.getFromWikiNeedsPictures();
|
||||
if (curLatLng != null) {
|
||||
Timber.d("Sorting places by distance...");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
|
||||
|
|
@ -9,7 +8,6 @@ import java.io.IOException;
|
|||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
|
@ -25,22 +23,32 @@ import timber.log.Timber;
|
|||
public class NearbyPlaces {
|
||||
|
||||
private static final int MIN_RESULTS = 40;
|
||||
private static final double INITIAL_RADIUS = 1.0; // in kilometer
|
||||
private static final double MAX_RADIUS = 300.0; // in kilometer
|
||||
private static final double INITIAL_RADIUS = 1.0; // in kilometers
|
||||
private static final double MAX_RADIUS = 300.0; // in kilometers
|
||||
private static final double RADIUS_MULTIPLIER = 1.618;
|
||||
private static final String WIKIDATA_QUERY_URL = "https://query.wikidata.org/sparql?query=${QUERY}";
|
||||
private static final Uri WIKIDATA_QUERY_URL = Uri.parse("https://query.wikidata.org/sparql");
|
||||
private static final Uri WIKIDATA_QUERY_UI_URL = Uri.parse("https://query.wikidata.org/");
|
||||
private final String wikidataQuery;
|
||||
private double radius = INITIAL_RADIUS;
|
||||
private List<Place> places;
|
||||
|
||||
List<Place> getFromWikidataQuery(Context context,
|
||||
LatLng curLatLng,
|
||||
String lang) {
|
||||
public NearbyPlaces() {
|
||||
try {
|
||||
String query = FileUtils.readFromResource("/assets/queries/nearby_query.rq");
|
||||
wikidataQuery = query;
|
||||
Timber.v(wikidataQuery);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
List<Place> getFromWikidataQuery(LatLng curLatLng, String lang) {
|
||||
List<Place> places = Collections.emptyList();
|
||||
|
||||
try {
|
||||
// increase the radius gradually to find a satisfactory number of nearby places
|
||||
while (radius < MAX_RADIUS) {
|
||||
places = getFromWikidataQuery(context, curLatLng, lang, radius);
|
||||
places = getFromWikidataQuery(curLatLng, lang, radius);
|
||||
Timber.d("%d results at radius: %f", places.size(), radius);
|
||||
if (places.size() >= MIN_RESULTS) {
|
||||
break;
|
||||
|
|
@ -58,28 +66,24 @@ public class NearbyPlaces {
|
|||
return places;
|
||||
}
|
||||
|
||||
private List<Place> getFromWikidataQuery(Context context,
|
||||
LatLng cur,
|
||||
private List<Place> getFromWikidataQuery(LatLng cur,
|
||||
String lang,
|
||||
double radius)
|
||||
throws IOException {
|
||||
List<Place> places = new ArrayList<>();
|
||||
|
||||
String query = FileUtils.readFromFile(context, "queries/nearby_query.rq")
|
||||
.replace("${RADIUS}", String.format(Locale.ROOT, "%.2f", radius))
|
||||
String query = wikidataQuery
|
||||
.replace("${RAD}", String.format(Locale.ROOT, "%.2f", radius))
|
||||
.replace("${LAT}", String.format(Locale.ROOT, "%.4f", cur.latitude))
|
||||
.replace("${LONG}", String.format(Locale.ROOT, "%.4f", cur.longitude))
|
||||
.replace("${LANG}", lang);
|
||||
|
||||
Timber.d("Wikidata query "+ query);
|
||||
Timber.v("# Wikidata query: \n" + query);
|
||||
|
||||
// format as a URL
|
||||
String url = WIKIDATA_QUERY_URL.replace(
|
||||
"${QUERY}",
|
||||
URLEncoder.encode(query, "utf-8").replace("+", "%20")
|
||||
);
|
||||
|
||||
Timber.d(url);
|
||||
Timber.d(WIKIDATA_QUERY_UI_URL.buildUpon().fragment(query).build().toString());
|
||||
String url = WIKIDATA_QUERY_URL.buildUpon()
|
||||
.appendQueryParameter("query", query).build().toString();
|
||||
URLConnection conn = new URL(url).openConnection();
|
||||
conn.setRequestProperty("Accept", "text/tab-separated-values");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
|
|
|||
|
|
@ -21,15 +21,11 @@ import android.widget.BaseAdapter;
|
|||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
|
||||
import fr.free.nrw.commons.MediaWikiImageView;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||
|
||||
|
|
@ -48,14 +44,12 @@ public class MultipleUploadListFragment extends Fragment {
|
|||
private MediaDetailPagerFragment.MediaDetailProvider detailProvider;
|
||||
private OnMultipleUploadInitiatedHandler multipleUploadInitiatedHandler;
|
||||
|
||||
private DisplayImageOptions uploadDisplayOptions;
|
||||
|
||||
private boolean imageOnlyMode;
|
||||
|
||||
private static class UploadHolderView {
|
||||
Uri imageUri;
|
||||
|
||||
ImageView image;
|
||||
MediaWikiImageView image;
|
||||
TextView title;
|
||||
|
||||
RelativeLayout overlay;
|
||||
|
|
@ -85,7 +79,7 @@ public class MultipleUploadListFragment extends Fragment {
|
|||
if(view == null) {
|
||||
view = getLayoutInflater(null).inflate(R.layout.layout_upload_item, null);
|
||||
holder = new UploadHolderView();
|
||||
holder.image = (ImageView) view.findViewById(R.id.uploadImage);
|
||||
holder.image = (MediaWikiImageView) view.findViewById(R.id.uploadImage);
|
||||
holder.title = (TextView) view.findViewById(R.id.uploadTitle);
|
||||
holder.overlay = (RelativeLayout) view.findViewById(R.id.uploadOverlay);
|
||||
|
||||
|
|
@ -100,7 +94,7 @@ public class MultipleUploadListFragment extends Fragment {
|
|||
Contribution up = (Contribution)this.getItem(i);
|
||||
|
||||
if(holder.imageUri == null || !holder.imageUri.equals(up.getLocalUri())) {
|
||||
ImageLoader.getInstance().displayImage(up.getLocalUri().toString(), holder.image, uploadDisplayOptions);
|
||||
holder.image.setImageURI(up.getLocalUri().toString());
|
||||
holder.imageUri = up.getLocalUri();
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +215,6 @@ public class MultipleUploadListFragment extends Fragment {
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
uploadDisplayOptions = Utils.getGenericDisplayOptions().build();
|
||||
detailProvider = (MediaDetailPagerFragment.MediaDetailProvider)getActivity();
|
||||
multipleUploadInitiatedHandler = (OnMultipleUploadInitiatedHandler) getActivity();
|
||||
|
||||
|
|
|
|||
|
|
@ -14,11 +14,10 @@ import android.support.v4.app.NavUtils;
|
|||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -59,7 +58,7 @@ public class ShareActivity
|
|||
|
||||
private Uri mediaUri;
|
||||
private Contribution contribution;
|
||||
private ImageView backgroundImageView;
|
||||
private SimpleDraweeView backgroundImageView;
|
||||
private UploadController uploadController;
|
||||
|
||||
private CommonsApplication cacheObj;
|
||||
|
|
@ -222,7 +221,7 @@ public class ShareActivity
|
|||
ButterKnife.bind(this);
|
||||
initDrawer();
|
||||
app = CommonsApplication.getInstance();
|
||||
backgroundImageView = (ImageView)findViewById(R.id.backgroundImage);
|
||||
backgroundImageView = (SimpleDraweeView)findViewById(R.id.backgroundImage);
|
||||
|
||||
//Receive intent from ContributionController.java when user selects picture to upload
|
||||
Intent intent = getIntent();
|
||||
|
|
@ -239,7 +238,7 @@ public class ShareActivity
|
|||
|
||||
if (mediaUri != null) {
|
||||
mediaUriString = mediaUri.toString();
|
||||
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
||||
backgroundImageView.setImageURI(mediaUriString);
|
||||
|
||||
//Test SHA1 of image to see if it matches SHA1 of a file on Commons
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,37 +1,36 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import timber.log.Timber;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
|
||||
public class FileUtils {
|
||||
public static String readFromFile(Context context, String fileName) {
|
||||
String stringBuilder = "";
|
||||
/**
|
||||
* Read and return the content of a resource file as string.
|
||||
*
|
||||
* @param fileName asset file's path (e.g. "/assets/queries/nearby_query.rq")
|
||||
* @return the content of the file
|
||||
*/
|
||||
public static String readFromResource(String fileName) throws IOException {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(context.getAssets().open(fileName)));
|
||||
String mLine;
|
||||
while ((mLine = reader.readLine()) != null) {
|
||||
stringBuilder += mLine + "\n";
|
||||
new InputStreamReader(
|
||||
CommonsApplication.class.getResourceAsStream(fileName), "UTF-8"));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
buffer.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Timber.e("File not found exception", e);
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
//log the exception
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
return stringBuilder;
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
|
@ -20,11 +21,11 @@
|
|||
android:layout_below="@id/toolbar"
|
||||
android:background="?attr/mainBackground">
|
||||
|
||||
<ImageView
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/backgroundImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop" />
|
||||
app:actualImageScaleType="centerCrop" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/single_upload_fragment_container"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -8,11 +9,11 @@
|
|||
android:background="#000000"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/uploadImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="192dp"
|
||||
android:scaleType="centerCrop"
|
||||
app:actualImageScaleType="centerCrop"
|
||||
/>
|
||||
|
||||
<RelativeLayout
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue