Commit 7f995a92 authored by Mudar Noufal's avatar Mudar Noufal

Cleanup

to avoid leaking activity
parent 749249e9
......@@ -57,11 +57,11 @@ public abstract class BaseActivity extends AppCompatActivity implements
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LangUtils.updateUiLanguage(this);
LangUtils.updateUiLanguage(getApplicationContext());
if (this instanceof MainActivity) {
// Only MainActivity needs to register for updates about LANGUAGE prefs
UserPrefs.getSharedPrefs(this).registerOnSharedPreferenceChangeListener(this);
UserPrefs.getSharedPrefs(getApplicationContext()).registerOnSharedPreferenceChangeListener(this);
}
}
......@@ -90,7 +90,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
if (this instanceof MainActivity) {
// Only MainActivity registered for updates about LANGUAGE prefs
try {
UserPrefs.getSharedPrefs(this).unregisterOnSharedPreferenceChangeListener(this);
UserPrefs.getSharedPrefs(getApplicationContext()).unregisterOnSharedPreferenceChangeListener(this);
} catch (Exception e) {
LogUtils.REMOTE_LOG(e);
}
......@@ -100,7 +100,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (Const.PrefsNames.LANGUAGE.equals(key)) {
LangUtils.updateUiLanguage(this);
LangUtils.updateUiLanguage(getApplicationContext());
recreate();
}
}
......@@ -109,19 +109,19 @@ public abstract class BaseActivity extends AppCompatActivity implements
public boolean onMenuItemClick(MenuItem item) {
final int id = item.getItemId();
if (id == R.id.action_settings) {
startActivity(SettingsActivity.newIntent(this));
startActivity(SettingsActivity.newIntent(getApplicationContext()));
return true;
} else if (id == R.id.action_about) {
startActivity(AboutActivity.newIntent(this));
startActivity(AboutActivity.newIntent(getApplicationContext()));
return true;
} else if (id == R.id.action_share) {
onShareItemSelected();
return true;
} else if (id == R.id.action_rate) {
IntentUtils.showWebsite(this, R.string.url_playstore);
IntentUtils.showWebsite(getApplicationContext(), R.string.url_playstore);
return true;
} else if (id == R.id.action_eula) {
startActivity(EulaActivity.newIntent(this, true));
startActivity(EulaActivity.newIntent(getApplicationContext(), true));
return true;
} else if (id == R.id.action_about_libs) {
onAboutLibsItemSelected();
......@@ -146,7 +146,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
* Show the AboutLibraries acknowledgements activity
*/
private void onAboutLibsItemSelected() {
LangUtils.updateUiLanguage(this);
LangUtils.updateUiLanguage(getApplicationContext());
new LibsBuilder()
.withActivityTitle(getString(R.string.title_activity_about_libs))
.withActivityTheme(R.style.AppTheme_AboutLibs)
......@@ -162,7 +162,7 @@ public abstract class BaseActivity extends AppCompatActivity implements
.withExcludedLibraries(
"AndroidIconics", "fastadapter", "okio", "support_v4"
)
.start(this);
.start(getApplicationContext());
}
/**
......
......@@ -69,7 +69,7 @@ public class EulaActivity extends BaseActivity implements View.OnClickListener {
@Override
public void onClick(View view) {
if (view.getId() == R.id.btn_accept_eula) {
UserPrefs.getInstance(this).setHasAcceptedEula();
UserPrefs.getInstance(getApplicationContext()).setHasAcceptedEula();
setResult(Activity.RESULT_OK);
finish();
}
......
......@@ -120,7 +120,7 @@ public class MainActivity extends BaseActivity implements
setupMap();
setupFAB();
final @MapType String lastMapType = UserPrefs.getInstance(this).getLastMapType();
final @MapType String lastMapType = UserPrefs.getInstance(getApplicationContext()).getLastMapType();
setupBottomBar(lastMapType);
setMapType(lastMapType, 0);
}
......@@ -148,7 +148,7 @@ public class MainActivity extends BaseActivity implements
try {
mLocationManger.onStop();
UserPrefs.getInstance(this).setLastMapType(mMapType);
UserPrefs.getInstance(getApplicationContext()).setLastMapType(mMapType);
} catch (Exception e) {
LogUtils.REMOTE_LOG(e);
}
......@@ -183,7 +183,7 @@ public class MainActivity extends BaseActivity implements
if (requestCode == Const.RequestCodes.LOCATION_PERMISSION) {
if (PermissionUtils.checkLocationPermission(this)) {
UserPrefs.getInstance(this).setPermissionDeniedForEver(true);
UserPrefs.getInstance(getApplicationContext()).setPermissionDeniedForEver(true);
mMyLocationFAB.show();
MapUtils.enableMyLocation(this, vMap);
......@@ -370,7 +370,7 @@ public class MainActivity extends BaseActivity implements
final RealmResults<RealmPlacemark> realmPlacemarks = RealmQueries
.queryPlacemarksByMapType(mRealm,
type,
UserPrefs.getInstance(this).getEnabledLayers()
UserPrefs.getInstance(getApplicationContext()).getEnabledLayers()
).findAll();
if (realmPlacemarks.size() > 0) {
......@@ -408,7 +408,7 @@ public class MainActivity extends BaseActivity implements
GoogleMap.OnCameraIdleListener cameraIdleListener;
// Enable this placemark's layer if necessary
final UserPrefs prefs = UserPrefs.getInstance(this);
final UserPrefs prefs = UserPrefs.getInstance(getApplicationContext());
final boolean updateLayers = !prefs.isLayerEnabled(placemark.getLayerType());
if (updateLayers) {
prefs.setLayerEnabledForced(placemark.getMapType(), placemark.getLayerType());
......@@ -465,7 +465,7 @@ public class MainActivity extends BaseActivity implements
* This method uses setVisibility() instead of show/hide methods.
*/
private void toggleMyLocationButton() {
if (PermissionUtils.checkPermissionWasDeniedForEver(this)) {
if (PermissionUtils.checkPermissionWasDeniedForEver(getApplicationContext())) {
mMyLocationFAB.hide();
} else {
mMyLocationFAB.show();
......
......@@ -85,7 +85,7 @@ public class PlacemarkInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
return mView.getContext().getString(R.string.info_window_snippet_distance,
snippet,
GeoUtils.getDistanceDisplay(mView.getContext(), distance)
GeoUtils.getDistanceDisplay(mView.getContext().getApplicationContext(), distance)
);
}
......
......@@ -94,7 +94,7 @@ public abstract class PermissionUtils {
})
.show();
} else {
UserPrefs.getInstance(activity).setPermissionDeniedForEver(true);
UserPrefs.getInstance(activity.getApplicationContext()).setPermissionDeniedForEver(true);
Snackbar
.make(view,
R.string.snackbar_location_permission_denied,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment