Commit fb841a4d authored by Mudar Noufal's avatar Mudar Noufal

enable layer for search placemark

fix #32
parent 7271b25e
...@@ -27,6 +27,7 @@ import android.annotation.SuppressLint; ...@@ -27,6 +27,7 @@ import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
...@@ -36,6 +37,8 @@ import java.util.Set; ...@@ -36,6 +37,8 @@ import java.util.Set;
import ca.mudar.mtlaucasou.Const; import ca.mudar.mtlaucasou.Const;
import ca.mudar.mtlaucasou.R; import ca.mudar.mtlaucasou.R;
import ca.mudar.mtlaucasou.model.LayerType; import ca.mudar.mtlaucasou.model.LayerType;
import ca.mudar.mtlaucasou.model.MapType;
import ca.mudar.mtlaucasou.util.MapUtils;
import static ca.mudar.mtlaucasou.util.LogUtils.makeLogTag; import static ca.mudar.mtlaucasou.util.LogUtils.makeLogTag;
...@@ -148,7 +151,21 @@ public class UserPrefs implements ...@@ -148,7 +151,21 @@ public class UserPrefs implements
.contains(layerType); .contains(layerType);
} }
public void setLayerEnabledForced(@MapType String mapType, @LayerType String layerType) {
if (MapUtils.isMultiLayerMapType(mapType)) {
setLayerEnabled(layerType, true, true);
}
}
public void setLayerEnabled(@LayerType String layerType, boolean enabled) { public void setLayerEnabled(@LayerType String layerType, boolean enabled) {
setLayerEnabled(layerType, enabled, false);
}
private void setLayerEnabled(@LayerType String layerType, boolean enabled, boolean commit) {
if (TextUtils.isEmpty(layerType)) {
return;
}
// We need to make a copy of the hashset, not just get a reference // We need to make a copy of the hashset, not just get a reference
final Set<String> enabledLayers = new HashSet<>(mPrefs.getStringSet(LAYERS_ENABLED, final Set<String> enabledLayers = new HashSet<>(mPrefs.getStringSet(LAYERS_ENABLED,
Const.PrefsValues.DEFAULT_LAYERS)); Const.PrefsValues.DEFAULT_LAYERS));
...@@ -161,8 +178,12 @@ public class UserPrefs implements ...@@ -161,8 +178,12 @@ public class UserPrefs implements
} }
if (result) { if (result) {
edit().putStringSet(LAYERS_ENABLED, enabledLayers) final SharedPreferences.Editor editor = edit().putStringSet(LAYERS_ENABLED, enabledLayers);
.apply(); if (commit) {
editor.commit();
} else {
editor.apply();
}
} }
} }
......
...@@ -395,6 +395,15 @@ public class MainActivity extends BaseActivity implements ...@@ -395,6 +395,15 @@ public class MainActivity extends BaseActivity implements
@Override @Override
public void moveCameraToPlacemark(Placemark placemark) { public void moveCameraToPlacemark(Placemark placemark) {
GoogleMap.OnCameraIdleListener cameraIdleListener; GoogleMap.OnCameraIdleListener cameraIdleListener;
// Enable this placemark's layer if necessary
final UserPrefs prefs = UserPrefs.getInstance(this);
final boolean updateLayers = !prefs.isLayerEnabled(placemark.getLayerType());
if (updateLayers) {
prefs.setLayerEnabledForced(placemark.getMapType(), placemark.getLayerType());
mLayersManager.setupEnabledLayers(prefs);
}
if (mMapType != null && !mMapType.equals(placemark.getMapType())) { if (mMapType != null && !mMapType.equals(placemark.getMapType())) {
final int tabId = NavigUtils.getTabIdByMapType(placemark.getMapType()); final int tabId = NavigUtils.getTabIdByMapType(placemark.getMapType());
...@@ -408,6 +417,16 @@ public class MainActivity extends BaseActivity implements ...@@ -408,6 +417,16 @@ public class MainActivity extends BaseActivity implements
mBottomBar.selectTabWithId(tabId); mBottomBar.selectTabWithId(tabId);
} }
}; };
} else if (updateLayers) {
cameraIdleListener = new GoogleMap.OnCameraIdleListener() {
/**
* After the camera animation, we need to
*/
@Override
public void onCameraIdle() {
onFiltersApply();
}
};
} else { } else {
// Selected placemark is of current type: ignore // Selected placemark is of current type: ignore
cameraIdleListener = null; cameraIdleListener = null;
......
...@@ -92,7 +92,7 @@ public class MapLayersManager implements ...@@ -92,7 +92,7 @@ public class MapLayersManager implements
mHospitalsFAB = (FloatingActionButton) mMenuFAB.findViewById(R.id.fab_hospitals); mHospitalsFAB = (FloatingActionButton) mMenuFAB.findViewById(R.id.fab_hospitals);
mClscFAB = (FloatingActionButton) mMenuFAB.findViewById(R.id.fab_clsc); mClscFAB = (FloatingActionButton) mMenuFAB.findViewById(R.id.fab_clsc);
setupInitialValues(UserPrefs.getInstance(context)); setupEnabledLayers(UserPrefs.getInstance(context));
setupMenuItemsListeners(); setupMenuItemsListeners();
} }
...@@ -174,6 +174,7 @@ public class MapLayersManager implements ...@@ -174,6 +174,7 @@ public class MapLayersManager implements
@Override @Override
public void onMenuToggle(boolean opened) { public void onMenuToggle(boolean opened) {
if (!opened && mHasChangedFilters && mListener != null) { if (!opened && mHasChangedFilters && mListener != null) {
mHasChangedFilters = false;
mListener.onFiltersApply(); mListener.onFiltersApply();
} }
} }
...@@ -185,7 +186,7 @@ public class MapLayersManager implements ...@@ -185,7 +186,7 @@ public class MapLayersManager implements
* @return true if map type has a FloatingActionMenu * @return true if map type has a FloatingActionMenu
*/ */
public boolean toggleFilterMenu(@MapType String type) { public boolean toggleFilterMenu(@MapType String type) {
mMapTypeHasMenu = MapTypes.HEAT_WAVE.equals(type) || MapTypes.HEALTH.equals(type); mMapTypeHasMenu = MapUtils.isMultiLayerMapType(type);
mHasChangedFilters = false; mHasChangedFilters = false;
toggleWaterSupplyFilterItems(MapTypes.HEAT_WAVE.equals(type)); toggleWaterSupplyFilterItems(MapTypes.HEAT_WAVE.equals(type));
...@@ -242,7 +243,7 @@ public class MapLayersManager implements ...@@ -242,7 +243,7 @@ public class MapLayersManager implements
mMenuFAB.setMenuButtonColorPressed(mMapTypeColor); mMenuFAB.setMenuButtonColorPressed(mMapTypeColor);
} }
private void setupInitialValues(UserPrefs prefs) { public void setupEnabledLayers(UserPrefs prefs) {
final @LayerType Set<String> enabledLayers = prefs.getEnabledLayers(); final @LayerType Set<String> enabledLayers = prefs.getEnabledLayers();
mMapTypeColor = MapUtils.getMapTypeColor(mContext, MapTypes.HEAT_WAVE); mMapTypeColor = MapUtils.getMapTypeColor(mContext, MapTypes.HEAT_WAVE);
......
...@@ -144,6 +144,10 @@ public class MapUtils { ...@@ -144,6 +144,10 @@ public class MapUtils {
return null; return null;
} }
public static boolean isMultiLayerMapType(@MapType String mapType) {
return MapTypes.HEAT_WAVE.equals(mapType) || MapTypes.HEALTH.equals(mapType);
}
/** /**
* Clean the HTML description provided by the city's data. Also removes duplicate title. * Clean the HTML description provided by the city's data. Also removes duplicate title.
* *
......
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