diff --git a/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.java b/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.java index 0c587d566..206e44f81 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/FileUtils.java @@ -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; diff --git a/app/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java b/app/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java index 6d1a2ac95..1954dcb69 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/GPSExtractor.java @@ -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(); diff --git a/app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java b/app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java index 924557905..9372c78c0 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/ShareActivity.java @@ -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("")) {