I would like to read your thoughts on how to solve the following problem. Here are the basic requirements of the application I am working on.
- Display multiple locations one city on a map.
- Support for multiple cities.
- Display the properties of a location on a separate details view.
- Location properties of each city differ.
I would like to implement a flexible decision logic that switches between cities based on the location that the map is at. That means, the initial information I rely on, is the map center. Here is the theoretical workflow.
- Get the current center location from the map.
- Translate the location into a city url and uri.
- Download locations via HTTP using the url.
- Store the locations in local database. One table for each city since location properties differ.
- Load cached or downloaded data from a content resolver using the uri.
- Create overlay items and include the uri reference and a unique id.
- Open a details view when tapping on a location.
- The details view should render the city specific location properties.
- The location properties again are loaded via a content resolver based on the passed uri and unique id.
Questions:
- I am particular interested on how you would switch cities, query parameters such as column names using the
UriMatcher
class. - Would you prepare one details view for each city? Or do you see any practical solution to swap text fields, label, .. based on the available property information?
To illustrate the different properties, here are two example cities and a content provider.
Example:
public class DatabaseParis {
public static final class Contract {
public static final String COLUMN_LATITUDE = "latitude";
public static final String COLUMN_LONGITUDE = "longitude";
public static final String COLUMN_NAME = "name";
}
And another city ...
public class DatabaseDenver {
public static final class Contract {
public static final String COLUMN_LATITUDE = "lat";
public static final String COLUMN_LONGITUDE = "lon";
public static final String COLUMN_HEIGHT = "height";
public static final String COLUMN_DIAMETER = "diameter";
}
And a content provider ...
public class CustomContentProvider extends ContentProvider {
public static final class Contract {
public static final Uri URI_PARIS = Uri.parse("content://" + AUTHORITY + "/cities/paris");
}
private static final String AUTHORITY = "com.example.cities.locations";
private static final int URI_CODE_PARIS = 0;
private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
static {
URI_MATCHER.addURI(AUTHORITY, "cities/paris", URI_CODE_PARIS);
}
I am unsure about using one or multiple content provider since I read putting all database references into one can be a problem when the data should be synced in the future.