Commit 4ebe6a43 authored by Mudar Noufal's avatar Mudar Noufal

Refactoring map and data types, added layerTypes

renamed hospitals to health
renamed waterSupplies to heatWave (except drawables)
parent 58b27f6c
......@@ -40,10 +40,24 @@ public class Const {
public interface MapTypes {
String FIRE_HALLS = "fire_halls";
String SPVM_STATIONS = "spvm_stations";
String WATER_SUPPLIES = "water_supplies";
String HEAT_WAVE = "water_supplies";
String EMERGENCY_HOSTELS = "emergency_hostels";
String HEALTH = "health";
String _DEFAULT = HEALTH;
}
public interface LayerTypes {
String FIRE_HALLS = "fire_halls";
String SPVM_STATIONS = "spvm_stations";
String EMERGENCY_HOSTELS = "emergency_hostels";
// Heat wave x4
String AIR_CONDITIONING = "air_conditioning";
String POOLS = "pools";
String WADING_POOLS = "wading_pools";
String PLAY_FOUNTAINS = "play_fountains";
// Health x2
String HOSPITALS = "hospitals";
String _DEFAULT = HOSPITALS;
String CLSC = "clsc";
}
public static final double MAPS_GEOCODER_LIMITS[] = {
......@@ -64,13 +78,13 @@ public class Const {
public interface ApiValues {
String TYPE_PLACEMARKS = "placemarks";
String TYPE_SHAPES = "shapes";
// There's a slight difference between mapType and dataType
String TYPE_FIRE_HALLS = MapTypes.FIRE_HALLS;
String TYPE_SPVM_STATIONS = MapTypes.SPVM_STATIONS;
String TYPE_WATER_SUPPLIES = MapTypes.WATER_SUPPLIES;
String TYPE_AIR_CONDITIONING = "air_conditioning";
String TYPE_EMERGENCY_HOSTELS = MapTypes.EMERGENCY_HOSTELS;
String TYPE_HOSPITALS = MapTypes.HOSPITALS;
// Remote dataType is used to determine local layerType
String TYPE_PLAY_FOUNTAINS = "jeux-d-eau";
String TYPE_WADING_POOLS = "pataugeoire";
String TYPE_POOLS_EXT = "piscine-ext";
String TYPE_POOLS_INT = "piscine-int";
String TYPE_HOSPITALS = "hopital";
String TYPE_CLSC = "clsc";
}
public interface BundleKeys {
......
......@@ -30,6 +30,7 @@ import java.util.List;
import ca.mudar.mtlaucasou.model.MapType;
import ca.mudar.mtlaucasou.model.RealmPlacemark;
import ca.mudar.mtlaucasou.model.geojson.PointsFeature;
import ca.mudar.mtlaucasou.model.LayerType;
import io.realm.Case;
import io.realm.Realm;
import io.realm.RealmQuery;
......@@ -41,13 +42,13 @@ public class RealmQueries {
* Delete data from the Realm db
*
* @param realm
* @param dataType
* @param layerType
*/
public static void clearMapData(Realm realm, String dataType) {
public static void clearMapData(Realm realm, @LayerType String layerType) {
realm.beginTransaction();
realm.where(RealmPlacemark.class)
.equalTo(RealmPlacemark.FIELD_DATA_TYPE, dataType)
.equalTo(RealmPlacemark.FIELD_LAYER_TYPE, layerType)
.findAll()
.deleteAllFromRealm();
......@@ -60,10 +61,11 @@ public class RealmQueries {
* @param realm
* @param pointsFeatures
* @param mapType
* @param layerType
* @param transaction
*/
public static void cacheMapData(Realm realm, List<PointsFeature> pointsFeatures,
@MapType String mapType, String dataType, boolean transaction) {
@MapType String mapType, @LayerType String layerType, boolean transaction) {
if (transaction) {
realm.beginTransaction();
}
......@@ -71,7 +73,7 @@ public class RealmQueries {
for (PointsFeature feature : pointsFeatures) {
realm.copyToRealm(new RealmPlacemark.Builder(feature)
.mapType(mapType)
.dataType(dataType)
.layerType(layerType, feature.getProperties().getType())
.build());
}
......
......@@ -21,14 +21,28 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ca.mudar.mtlaucasou.util;
import java.util.Locale;
import static ca.mudar.mtlaucasou.Const.PrefsNames.ITEM_UPDATED_AT;
public class ApiUtils {
public static String getSharedPrefsKey(String id) {
return String.format(Locale.ROOT, ITEM_UPDATED_AT, id);
}
package ca.mudar.mtlaucasou.model;
import android.support.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import ca.mudar.mtlaucasou.Const;
@Retention(RetentionPolicy.SOURCE)
@StringDef({
Const.LayerTypes.FIRE_HALLS,
Const.LayerTypes.SPVM_STATIONS,
Const.LayerTypes.EMERGENCY_HOSTELS,
// Heat wave x4
Const.LayerTypes.AIR_CONDITIONING,
Const.LayerTypes.POOLS,
Const.LayerTypes.WADING_POOLS,
Const.LayerTypes.PLAY_FOUNTAINS,
// Health x2
Const.LayerTypes.HOSPITALS,
Const.LayerTypes.CLSC
})
public @interface LayerType {
}
......@@ -34,8 +34,8 @@ import ca.mudar.mtlaucasou.Const;
@StringDef({
Const.MapTypes.FIRE_HALLS,
Const.MapTypes.SPVM_STATIONS,
Const.MapTypes.WATER_SUPPLIES,
Const.MapTypes.HEAT_WAVE,
Const.MapTypes.EMERGENCY_HOSTELS,
Const.MapTypes.HOSPITALS})
Const.MapTypes.HEALTH})
public @interface MapType {
}
\ No newline at end of file
......@@ -23,9 +23,12 @@
package ca.mudar.mtlaucasou.model;
import android.text.TextUtils;
import com.google.android.gms.maps.model.LatLng;
import ca.mudar.mtlaucasou.model.geojson.PointsFeature;
import ca.mudar.mtlaucasou.util.ApiDataUtils;
import io.realm.RealmObject;
import io.realm.annotations.Ignore;
import io.realm.annotations.Index;
......@@ -35,7 +38,7 @@ public class RealmPlacemark extends RealmObject implements
@Ignore
public static final String FIELD_MAP_TYPE = "mapType";
@Ignore
public static final String FIELD_DATA_TYPE = "dataType";
public static final String FIELD_LAYER_TYPE = "layerType";
@Ignore
public static final String FIELD_COORDINATES = "coordinates";
@Ignore
......@@ -49,7 +52,9 @@ public class RealmPlacemark extends RealmObject implements
@MapType
@Index
private String mapType;
private String dataType;
@LayerType
@Index
private String layerType;
private PlacemarkProperties properties;
private LongitudeLatitude coordinates;
......@@ -65,7 +70,7 @@ public class RealmPlacemark extends RealmObject implements
private RealmPlacemark(Builder builder) {
this.id = builder.id;
this.mapType = builder.mapType;
this.dataType = builder.dataType;
this.layerType = builder.layerType;
this.properties = builder.properties;
this.coordinates = builder.coordinates;
}
......@@ -103,12 +108,13 @@ public class RealmPlacemark extends RealmObject implements
this.mapType = mapType;
}
public String getDataType() {
return dataType;
@LayerType
public String getLayerType() {
return layerType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
public void setLayerType(@LayerType String layerType) {
this.layerType = layerType;
}
public PlacemarkProperties getProperties() {
......@@ -134,7 +140,8 @@ public class RealmPlacemark extends RealmObject implements
private String id;
@MapType
private String mapType;
private String dataType;
@LayerType
private String layerType;
private PlacemarkProperties properties;
private LongitudeLatitude coordinates;
......@@ -153,8 +160,12 @@ public class RealmPlacemark extends RealmObject implements
return this;
}
public Builder dataType(String dataType) {
this.dataType = dataType;
public Builder layerType(@LayerType String layerType, String dataType) {
if (!TextUtils.isEmpty(layerType)) {
this.layerType = layerType;
} else {
this.layerType = ApiDataUtils.getLayerType(dataType, mapType);
}
return this;
}
......
......@@ -35,6 +35,7 @@ public class Attributes {
private Date updated;
@SerializedName("type")
private String dataType;
@MapType
private String mapType;
public String getTitle() {
......
......@@ -36,6 +36,8 @@ import java.io.InputStreamReader;
import java.util.Date;
import ca.mudar.mtlaucasou.Const;
import ca.mudar.mtlaucasou.Const.LayerTypes;
import ca.mudar.mtlaucasou.Const.MapTypes;
import ca.mudar.mtlaucasou.R;
import ca.mudar.mtlaucasou.api.ApiClient;
import ca.mudar.mtlaucasou.data.RealmQueries;
......@@ -45,7 +47,8 @@ import ca.mudar.mtlaucasou.model.geojson.PointsFeatureCollection;
import ca.mudar.mtlaucasou.model.jsonapi.Attributes;
import ca.mudar.mtlaucasou.model.jsonapi.DataItem;
import ca.mudar.mtlaucasou.model.jsonapi.HelloApi;
import ca.mudar.mtlaucasou.util.ApiUtils;
import ca.mudar.mtlaucasou.model.LayerType;
import ca.mudar.mtlaucasou.util.ApiDataUtils;
import ca.mudar.mtlaucasou.util.LogUtils;
import io.realm.Realm;
import retrofit2.Response;
......@@ -86,12 +89,12 @@ public class SyncService extends IntentService {
private void loadInitialLocalData() {
mRealm.beginTransaction();
importLocalData(R.raw.fire_halls, Const.MapTypes.FIRE_HALLS, Const.ApiValues.TYPE_FIRE_HALLS);
importLocalData(R.raw.spvm_stations, Const.MapTypes.SPVM_STATIONS, Const.ApiValues.TYPE_SPVM_STATIONS);
importLocalData(R.raw.water_supplies, Const.MapTypes.WATER_SUPPLIES, Const.ApiValues.TYPE_WATER_SUPPLIES);
importLocalData(R.raw.air_conditioning, Const.MapTypes.WATER_SUPPLIES, Const.ApiValues.TYPE_AIR_CONDITIONING);
importLocalData(R.raw.emergency_hostels, Const.MapTypes.EMERGENCY_HOSTELS, Const.ApiValues.TYPE_EMERGENCY_HOSTELS);
importLocalData(R.raw.hospitals, Const.MapTypes.HOSPITALS, Const.ApiValues.TYPE_HOSPITALS);
importLocalData(R.raw.fire_halls, MapTypes.FIRE_HALLS, LayerTypes.FIRE_HALLS);
importLocalData(R.raw.spvm_stations, MapTypes.SPVM_STATIONS, LayerTypes.SPVM_STATIONS);
importLocalData(R.raw.water_supplies, MapTypes.HEAT_WAVE, null);
importLocalData(R.raw.air_conditioning, MapTypes.HEAT_WAVE, LayerTypes.AIR_CONDITIONING);
importLocalData(R.raw.emergency_hostels, MapTypes.EMERGENCY_HOSTELS, LayerTypes.EMERGENCY_HOSTELS);
importLocalData(R.raw.hospitals, MapTypes.HEALTH, LayerTypes.HOSPITALS);
mRealm.commitTransaction();
}
......@@ -106,7 +109,7 @@ public class SyncService extends IntentService {
continue;
}
final String key = ApiUtils.getSharedPrefsKey(dataset.getId());
final String key = ApiDataUtils.getSharedPrefsKey(dataset.getId());
final Date updatedAt = dataset.getAttributes().getUpdated();
if (prefs.isApiDataNewer(key, updatedAt)) {
......@@ -123,14 +126,14 @@ public class SyncService extends IntentService {
}
}
private void importLocalData(@RawRes int resource, @MapType String mapType, String dataType) {
private void importLocalData(@RawRes int resource, @MapType String mapType, @LayerType String layerType) {
final InputStream inputStream = getResources().openRawResource(resource);
final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
final PointsFeatureCollection collection = new Gson()
.fromJson(inputStreamReader, PointsFeatureCollection.class);
RealmQueries.cacheMapData(mRealm, collection.getFeatures(), mapType, dataType, false);
RealmQueries.cacheMapData(mRealm, collection.getFeatures(), mapType, layerType, false);
}
/**
......@@ -147,11 +150,14 @@ public class SyncService extends IntentService {
PointsFeatureCollection collection = response.body();
if (collection != null && collection.getFeatures() != null) {
final Attributes attributes = dataset.getAttributes();
RealmQueries.clearMapData(mRealm, attributes.getDataType());
final @LayerType String layerType = ApiDataUtils
.getLayerType(attributes.getDataType(), attributes.getMapType());
RealmQueries.clearMapData(mRealm, layerType);
RealmQueries.cacheMapData(mRealm,
collection.getFeatures(),
attributes.getMapType(),
attributes.getDataType(),
layerType,
true);
}
......
/*
Montréal Just in Case
Copyright (C) 2011 Mudar Noufal <mn@mudar.ca>
Geographic locations of public safety services. A Montréal Open Data
project.
This file is part of Montréal Just in Case.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package ca.mudar.mtlaucasou.util;
import android.text.TextUtils;
import java.util.Locale;
import ca.mudar.mtlaucasou.Const.ApiValues;
import ca.mudar.mtlaucasou.Const.LayerTypes;
import ca.mudar.mtlaucasou.Const.MapTypes;
import ca.mudar.mtlaucasou.model.LayerType;
import ca.mudar.mtlaucasou.model.MapType;
import static ca.mudar.mtlaucasou.Const.PrefsNames.ITEM_UPDATED_AT;
public class ApiDataUtils {
public static String getSharedPrefsKey(String id) {
return String.format(Locale.ROOT, ITEM_UPDATED_AT, id);
}
/**
* Get the local layerType from the remote dataType
*
* @param dataType api values to convert to layerType
* @param mapType fallback value, used for single-layer datasets
* @return
*/
@LayerType
public static String getLayerType(String dataType, @MapType String mapType) {
if (!TextUtils.isEmpty(dataType)) {
switch (dataType) {
case ApiValues.TYPE_PLAY_FOUNTAINS:
return LayerTypes.PLAY_FOUNTAINS;
case ApiValues.TYPE_WADING_POOLS:
return LayerTypes.WADING_POOLS;
case ApiValues.TYPE_POOLS_EXT:
case ApiValues.TYPE_POOLS_INT:
return LayerTypes.POOLS;
case ApiValues.TYPE_HOSPITALS:
return LayerTypes.HOSPITALS;
case ApiValues.TYPE_CLSC:
return LayerTypes.CLSC;
}
}
if (!TextUtils.isEmpty(mapType)) {
// These 3 mapTypes have a single layer type, the same as the mapType
switch (mapType) {
case MapTypes.FIRE_HALLS:
return LayerTypes.FIRE_HALLS;
case MapTypes.SPVM_STATIONS:
return LayerTypes.SPVM_STATIONS;
case MapTypes.EMERGENCY_HOSTELS:
return LayerTypes.EMERGENCY_HOSTELS;
}
}
return null;
}
}
......@@ -69,7 +69,7 @@ public class MapUtils {
/**
* Get the map marker icon (round buttons)
*
* @param type Selected map type {fire_halls|spvm_stations|water_supplies|emergency_hostels}
* @param type Selected map type {fire_halls|spvm_stations|water_supplies|emergency_hostels|health}
* @return bitmap for MarkerOptions
*/
public static BitmapDescriptor getMarkerIcon(@MapType String type) {
......@@ -78,11 +78,11 @@ public class MapUtils {
return BitmapDescriptorFactory.fromResource(R.drawable.ic_maps_fire_halls);
case Const.MapTypes.SPVM_STATIONS:
return BitmapDescriptorFactory.fromResource(R.drawable.ic_maps_spvm);
case Const.MapTypes.WATER_SUPPLIES:
case Const.MapTypes.HEAT_WAVE:
return BitmapDescriptorFactory.fromResource(R.drawable.ic_maps_water_supplies);
case Const.MapTypes.EMERGENCY_HOSTELS:
return BitmapDescriptorFactory.fromResource(R.drawable.ic_maps_emergency_hostels);
case Const.MapTypes.HOSPITALS:
case Const.MapTypes.HEALTH:
return BitmapDescriptorFactory.fromResource(R.drawable.ic_maps_hospitals);
}
return null;
......@@ -92,7 +92,7 @@ public class MapUtils {
* Get the app's colors for each section. Used for ProgressBar
*
* @param context Context to resolve resources
* @return Selected map type {fire_halls|spvm_stations|water_supplies|emergency_hostels|hospitals}
* @param type Selected map type {fire_halls|spvm_stations|water_supplies|emergency_hostels|health}
* @return the section's color
*/
@ColorInt
......@@ -105,14 +105,14 @@ public class MapUtils {
case Const.MapTypes.SPVM_STATIONS:
color = R.color.color_spvm;
break;
case Const.MapTypes.WATER_SUPPLIES:
color = R.color.color_water_supplies;
case Const.MapTypes.HEAT_WAVE:
color = R.color.color_heat_wave;
break;
case Const.MapTypes.EMERGENCY_HOSTELS:
color = R.color.color_emergency_hostels;
break;
case Const.MapTypes.HOSPITALS:
color = R.color.color_hospitals;
case Const.MapTypes.HEALTH:
color = R.color.color_health;
break;
default:
color = R.color.color_primary;
......
......@@ -46,11 +46,11 @@ public class NavigUtils {
return R.id.tab_fire_halls;
case Const.MapTypes.SPVM_STATIONS:
return R.id.tab_spvm;
case Const.MapTypes.WATER_SUPPLIES:
case Const.MapTypes.HEAT_WAVE:
return R.id.tab_water_supplies;
case Const.MapTypes.EMERGENCY_HOSTELS:
return R.id.tab_emergency_hostels;
case Const.MapTypes.HOSPITALS:
case Const.MapTypes.HEALTH:
return R.id.tab_hospitals;
}
......@@ -71,11 +71,11 @@ public class NavigUtils {
case R.id.tab_spvm:
return Const.MapTypes.SPVM_STATIONS;
case R.id.tab_water_supplies:
return Const.MapTypes.WATER_SUPPLIES;
return Const.MapTypes.HEAT_WAVE;
case R.id.tab_emergency_hostels:
return Const.MapTypes.EMERGENCY_HOSTELS;
case R.id.tab_hospitals:
return Const.MapTypes.HOSPITALS;
return Const.MapTypes.HEALTH;
}
return null;
......@@ -94,11 +94,11 @@ public class NavigUtils {
return R.drawable.ic_fire_hall;
case Const.MapTypes.SPVM_STATIONS:
return R.drawable.ic_spvm;
case Const.MapTypes.WATER_SUPPLIES:
case Const.MapTypes.HEAT_WAVE:
return R.drawable.ic_water_supplies;
case Const.MapTypes.EMERGENCY_HOSTELS:
return R.drawable.ic_emergency_hostels;
case Const.MapTypes.HOSPITALS:
case Const.MapTypes.HEALTH:
return R.drawable.ic_hospitals;
}
return 0;
......
......@@ -21,7 +21,7 @@
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_air_conditioning"
style="@style/FabMenuItem.WaterSupplies"
style="@style/FabMenuItem.HeatWave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_water_supplies"
......@@ -29,7 +29,7 @@
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_pools"
style="@style/FabMenuItem.WaterSupplies"
style="@style/FabMenuItem.HeatWave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_water_supplies"
......@@ -37,7 +37,7 @@
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_wading_pools"
style="@style/FabMenuItem.WaterSupplies"
style="@style/FabMenuItem.HeatWave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_water_supplies"
......@@ -45,7 +45,7 @@
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_play_fountains"
style="@style/FabMenuItem.WaterSupplies"
style="@style/FabMenuItem.HeatWave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_water_supplies"
......@@ -53,7 +53,7 @@
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_hospitals"
style="@style/FabMenuItem.Hospitals"
style="@style/FabMenuItem.Health"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_hospitals"
......@@ -61,7 +61,7 @@
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_clsc"
style="@style/FabMenuItem.Hospitals"
style="@style/FabMenuItem.Health"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_hospitals"
......
......@@ -38,9 +38,9 @@
<!--BottomBar tabs-->
<string name="btn_fire_halls">Casernes</string>
<string name="btn_spvm_stations">Poste de police</string>
<string name="btn_water_supplies">Canicule</string>
<string name="btn_heat_wave">Canicule</string>
<string name="btn_emergency_hostels">Hébergement</string>
<string name="btn_hospitals">Santé</string>
<string name="btn_health">Santé</string>
<!--Menus-->
<string name="action_search">Recherche</string>
......
......@@ -66,9 +66,9 @@
<color name="color_background_dark">@color/grey_800</color>
<color name="color_fire_halls">@color/red_700</color>
<color name="color_spvm">@color/blue_500</color>
<color name="color_water_supplies">@color/blue_grey_400</color>
<color name="color_heat_wave">@color/blue_grey_400</color>
<color name="color_emergency_hostels">@color/light_green_700</color>
<color name="color_hospitals">@color/teal_500</color>
<color name="color_health">@color/teal_500</color>
<!--Map InfoWindow-->
<color name="map_info_title">@color/grey_900</color>
......
......@@ -38,9 +38,9 @@
<!--BottomBar tabs-->
<string name="btn_fire_halls">Fire Stations</string>
<string name="btn_spvm_stations">Police Stations</string>
<string name="btn_water_supplies">Heat Wave</string>
<string name="btn_heat_wave">Heat Wave</string>
<string name="btn_emergency_hostels">Emgcy Hostels</string>
<string name="btn_hospitals">Health</string>
<string name="btn_health">Health</string>
<!--Menus-->
<string name="action_search">Search</string>
......
......@@ -44,12 +44,12 @@
<item name="fab_colorNormal">@color/fab_menu_item_color_normal</item>
</style>
<style name="FabMenuItem.WaterSupplies">
<item name="fab_colorPressed">@color/color_water_supplies</item>
<style name="FabMenuItem.HeatWave">
<item name="fab_colorPressed">@color/color_heat_wave</item>
</style>
<style name="FabMenuItem.Hospitals">
<item name="fab_colorPressed">@color/color_hospitals</item>
<style name="FabMenuItem.Health">
<item name="fab_colorPressed">@color/color_health</item>
</style>
<style name="AboutPrimaryText">
......
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