Commit b843b64b authored by Mudar Noufal's avatar Mudar Noufal

remember last section

fix #22
parent 1f0ca2fe
......@@ -141,6 +141,7 @@ public class Const {
// String LAST_UPDATE_LNG = "prefs_last_update_lng";
String PERMISSION_DENIED_FOR_EVER = "prefs_permission_denied";
String ITEM_UPDATED_AT = "prefs_updated_%s";
String LAST_MAP_TYPE = "prefs_last_map_type";
}
public interface PrefsValues {
......
......@@ -141,6 +141,17 @@ public class UserPrefs implements
.apply();
}
@SuppressWarnings("WrongConstant")
@MapType
public String getLastMapType() {
return mPrefs.getString(LAST_MAP_TYPE, Const.MapTypes._DEFAULT);
}
public void setLastMapType(@MapType String mapType) {
edit().putString(LAST_MAP_TYPE, mapType)
.apply();
}
@LayerType
public Set<String> getEnabledLayers() {
return mPrefs.getStringSet(LAYERS_ENABLED, Const.PrefsValues.DEFAULT_LAYERS);
......
......@@ -119,9 +119,10 @@ public class MainActivity extends BaseActivity implements
setupMap();
setupFAB();
setupBottomBar();
setMapType(Const.MapTypes._DEFAULT, 0);
final @MapType String lastMapType = UserPrefs.getInstance(this).getLastMapType();
setupBottomBar(lastMapType);
setMapType(lastMapType, 0);
}
protected void onStart() {
......@@ -144,16 +145,26 @@ public class MainActivity extends BaseActivity implements
protected void onStop() {
super.onStop();
mLocationManger.onStop();
try {
mLocationManger.onStop();
UserPrefs.getInstance(this).setLastMapType(mMapType);
} catch (Exception e) {
LogUtils.REMOTE_LOG(e);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
// Remove all change listeners to avoid leaks
mRealm.removeAllChangeListeners();
mRealm.close();
try {
// Remove all change listeners to avoid leaks
mRealm.removeAllChangeListeners();
mRealm.close();
} catch (Exception e) {
LogUtils.REMOTE_LOG(e);
}
}
@Override
......@@ -205,10 +216,10 @@ public class MainActivity extends BaseActivity implements
/**
* Show the bottom bar navigation items
*/
private void setupBottomBar() {
private void setupBottomBar(final @MapType String type) {
mBottomBar = (BottomBar) findViewById(R.id.bottom_bar);
assert mBottomBar != null;
mBottomBar.setDefaultTab(NavigUtils.getTabIdByMapType(Const.MapTypes._DEFAULT));
mBottomBar.setDefaultTab(NavigUtils.getTabIdByMapType(type));
mBottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes final int tabId) {
......
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