mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Get rid of other singletons
This commit is contained in:
parent
bdfbdc7579
commit
c712b561d4
7 changed files with 31 additions and 31 deletions
|
|
@ -30,6 +30,7 @@ import fr.free.nrw.commons.contributions.Contribution;
|
||||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||||
import fr.free.nrw.commons.modifications.ModifierSequence;
|
import fr.free.nrw.commons.modifications.ModifierSequence;
|
||||||
import fr.free.nrw.commons.auth.AccountUtil;
|
import fr.free.nrw.commons.auth.AccountUtil;
|
||||||
|
import fr.free.nrw.commons.nearby.NearbyPlaces;
|
||||||
|
|
||||||
import org.acra.ACRA;
|
import org.acra.ACRA;
|
||||||
import org.acra.ReportingInteractionMode;
|
import org.acra.ReportingInteractionMode;
|
||||||
|
|
@ -85,6 +86,8 @@ public class CommonsApplication extends Application {
|
||||||
private MWApi api = null;
|
private MWApi api = null;
|
||||||
private CacheController cacheData = null;
|
private CacheController cacheData = null;
|
||||||
private RequestQueue volleyQueue = null;
|
private RequestQueue volleyQueue = null;
|
||||||
|
private DBOpenHelper dbOpenHelper = null;
|
||||||
|
private NearbyPlaces nearbyPlaces = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should not be called by ANY application code (other than the magic Android glue)
|
* This should not be called by ANY application code (other than the magic Android glue)
|
||||||
|
|
@ -146,6 +149,20 @@ public class CommonsApplication extends Application {
|
||||||
return volleyQueue;
|
return volleyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized DBOpenHelper getDBOpenHelper() {
|
||||||
|
if(dbOpenHelper == null) {
|
||||||
|
dbOpenHelper = new DBOpenHelper(this);
|
||||||
|
}
|
||||||
|
return dbOpenHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized NearbyPlaces getNearbyPlaces() {
|
||||||
|
if (nearbyPlaces == null) {
|
||||||
|
nearbyPlaces = new NearbyPlaces();
|
||||||
|
}
|
||||||
|
return nearbyPlaces;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ public class CategoryContentProvider extends ContentProvider {
|
||||||
private DBOpenHelper dbOpenHelper;
|
private DBOpenHelper dbOpenHelper;
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
dbOpenHelper = DBOpenHelper.getInstance(getContext());
|
dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
@ -35,7 +36,7 @@ public class ContributionsContentProvider extends ContentProvider{
|
||||||
private DBOpenHelper dbOpenHelper;
|
private DBOpenHelper dbOpenHelper;
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
dbOpenHelper = DBOpenHelper.getInstance(getContext());
|
dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,16 +12,11 @@ public class DBOpenHelper extends SQLiteOpenHelper{
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "commons.db";
|
private static final String DATABASE_NAME = "commons.db";
|
||||||
private static final int DATABASE_VERSION = 6;
|
private static final int DATABASE_VERSION = 6;
|
||||||
private static DBOpenHelper singleton = null;
|
|
||||||
|
|
||||||
public static synchronized DBOpenHelper getInstance(Context context) {
|
/**
|
||||||
if ( singleton == null ) {
|
* Do not use, please call CommonsApplication.getDBOpenHelper()
|
||||||
singleton = new DBOpenHelper(context);
|
*/
|
||||||
}
|
public DBOpenHelper(Context context) {
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DBOpenHelper(Context context) {
|
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.data.DBOpenHelper;
|
import fr.free.nrw.commons.data.DBOpenHelper;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
@ -35,7 +36,7 @@ public class ModificationsContentProvider extends ContentProvider{
|
||||||
private DBOpenHelper dbOpenHelper;
|
private DBOpenHelper dbOpenHelper;
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
dbOpenHelper = DBOpenHelper.getInstance(getContext());
|
dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
@ -37,13 +38,14 @@ public class NearbyController {
|
||||||
if (curLatLng == null) {
|
if (curLatLng == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
NearbyPlaces nearbyPlaces = CommonsApplication.getInstance().getNearbyPlaces();
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
List<Place> places = prefs.getBoolean("useWikidata", true)
|
List<Place> places = prefs.getBoolean("useWikidata", true)
|
||||||
? NearbyPlaces.getInstance().getFromWikidataQuery(
|
? nearbyPlaces.getFromWikidataQuery(
|
||||||
context,
|
context,
|
||||||
curLatLng,
|
curLatLng,
|
||||||
Locale.getDefault().getLanguage())
|
Locale.getDefault().getLanguage())
|
||||||
: NearbyPlaces.getInstance().getFromWikiNeedsPictures();
|
: nearbyPlaces.getFromWikiNeedsPictures();
|
||||||
if (curLatLng != null) {
|
if (curLatLng != null) {
|
||||||
Timber.d("Sorting places by distance...");
|
Timber.d("Sorting places by distance...");
|
||||||
final Map<Place, Double> distances = new HashMap<>();
|
final Map<Place, Double> distances = new HashMap<>();
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,9 @@ public class NearbyPlaces {
|
||||||
private static final double MAX_RADIUS = 300.0; // in kilometer
|
private static final double MAX_RADIUS = 300.0; // in kilometer
|
||||||
private static final double RADIUS_MULTIPLIER = 1.618;
|
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 String WIKIDATA_QUERY_URL = "https://query.wikidata.org/sparql?query=${QUERY}";
|
||||||
private static NearbyPlaces singleton;
|
|
||||||
private double radius = INITIAL_RADIUS;
|
private double radius = INITIAL_RADIUS;
|
||||||
private List<Place> places;
|
private List<Place> places;
|
||||||
|
|
||||||
private NearbyPlaces(){
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Place> getFromWikidataQuery(Context context,
|
List<Place> getFromWikidataQuery(Context context,
|
||||||
LatLng curLatLng,
|
LatLng curLatLng,
|
||||||
String lang) {
|
String lang) {
|
||||||
|
|
@ -199,17 +195,4 @@ public class NearbyPlaces {
|
||||||
}
|
}
|
||||||
return places;
|
return places;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the singleton instance of this class.
|
|
||||||
* The instance is created upon the first invocation of this method, and then reused.
|
|
||||||
*
|
|
||||||
* @return The singleton instance
|
|
||||||
*/
|
|
||||||
public static synchronized NearbyPlaces getInstance() {
|
|
||||||
if (singleton == null) {
|
|
||||||
singleton = new NearbyPlaces();
|
|
||||||
}
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue