Don't pass Activity into GPSExtractor.

This commit is contained in:
Dmitry Brant 2017-05-26 16:18:27 -04:00
parent 1809475fea
commit b07432fce2
3 changed files with 8 additions and 9 deletions

View file

@ -23,7 +23,7 @@ public class FileUtils {
*/
// Can be safely suppressed, checks for isKitKat before running isDocumentUri
@SuppressLint("NewApi")
public static String getPath(final Context context, final Uri uri) {
public static String getPath(Context context, Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

View file

@ -13,6 +13,7 @@ import android.support.annotation.Nullable;
import java.io.IOException;
import fr.free.nrw.commons.CommonsApplication;
import timber.log.Timber;
/**
@ -26,15 +27,13 @@ public class GPSExtractor {
private double decLatitude, decLongitude;
private Double currentLatitude = null;
private Double currentLongitude = null;
private Context context;
public boolean imageCoordsExists;
private MyLocationListener myLocationListener;
private LocationManager locationManager;
public GPSExtractor(String filePath, Context context){
public GPSExtractor(String filePath){
this.filePath = filePath;
this.context = context;
}
/**
@ -42,7 +41,7 @@ public class GPSExtractor {
* @return true if enabled, false if disabled
*/
private boolean gpsPreferenceEnabled() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(CommonsApplication.getInstance());
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
Timber.d("Gps pref set to: %b", gpsPref);
return gpsPref;
@ -52,7 +51,7 @@ public class GPSExtractor {
* Registers a LocationManager to listen for current location
*/
protected void registerLocationManager() {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
locationManager = (LocationManager) CommonsApplication.getInstance().getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
myLocationListener = new MyLocationListener();

View file

@ -196,7 +196,7 @@ public class ShareActivity
categorizationFragment = (CategorizationFragment) getSupportFragmentManager().findFragmentByTag("categorization");
if(shareView == null && categorizationFragment == null) {
shareView = new SingleUploadFragment();
this.getSupportFragmentManager()
getSupportFragmentManager()
.beginTransaction()
.add(R.id.single_upload_fragment_container, shareView, "shareView")
.commitAllowingStateLoss();
@ -373,11 +373,11 @@ public class ShareActivity
* @param gpsEnabled
*/
public void getFileMetadata(boolean gpsEnabled) {
String filePath = FileUtils.getPath(this, mediaUri);
String filePath = FileUtils.getPath(getApplicationContext(), mediaUri);
Timber.d("Filepath: %s", filePath);
Timber.d("Calling GPSExtractor");
if(imageObj == null) {
imageObj = new GPSExtractor(filePath, this);
imageObj = new GPSExtractor(filePath);
}
if (filePath != null && !filePath.equals("")) {