Skip to content

Commit

Permalink
Replace Google maps by OpenStreetMap
Browse files Browse the repository at this point in the history
This is the first step towards becoming an true open source project.

Closes: #276
  • Loading branch information
saemy committed Aug 28, 2018
1 parent e0281f7 commit 5e6bd1e
Show file tree
Hide file tree
Showing 36 changed files with 950 additions and 917 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ repositories {
//}

ext {
androidMapsUtilsVersion = '0.3.4'
assertjVersion = '3.9.0'
butterknifeVersion = '8.8.1'
constraintLayoutVersion = '1.1.0'
constraintLayoutVersion = '1.1.2'
daggerVersion = '2.13'
gsonVersion = '2.8.1'
guavaVersion = '20.0'
jsonVersion = '20170516'
junitVersion = '4.12'
materialDialogsVersion = '0.9.6.0' // Depends on the android support lib. Their version must match ours.
multidexVersion = '1.0.3'
osmbonuspackVersion = '6.5.2'
osmdroidVersion = '6.0.2'
picassoVersion = '2.5.2'
playServicesVersion = '11.6.2'
retrofitVersion = '2.3.0'
robolectricVersion = '3.7'
rxAndroidVersion = '2.0.1'
rxAndroidVersion = '2.0.2'
rxJavaVersion = '2.1.7'
supportLibVersion = '27.0.1'
}
Expand All @@ -49,29 +50,28 @@ dependencies {
implementation "com.android.support:multidex:$multidexVersion"
implementation "com.android.support:preference-v14:$supportLibVersion"
implementation "com.android.support:support-v4:$supportLibVersion"
implementation "com.github.MKergall:osmbonuspack:$osmbonuspackVersion"
implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
implementation "com.google.android.gms:play-services-location:$playServicesVersion"
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
implementation "com.google.code.gson:gson:$gsonVersion"
implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
implementation "com.google.guava:guava:$guavaVersion"
implementation "com.google.maps.android:android-maps-utils:$androidMapsUtilsVersion"
implementation "com.jakewharton:butterknife:$butterknifeVersion"
implementation "com.squareup.picasso:picasso:$picassoVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"
implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
implementation "org.osmdroid:osmdroid-android:$osmdroidVersion"

testImplementation "junit:junit:$junitVersion"
testImplementation "org.assertj:assertj-core:$assertjVersion"
testImplementation "org.json:json:$jsonVersion"
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "org.robolectric:shadows-multidex:$robolectricVersion"
testImplementation "org.robolectric:shadows-supportv4:$robolectricVersion"
testImplementation "junit:junit:$junitVersion"
}

android {
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
Expand All @@ -28,8 +34,6 @@
android:label="@string/app_name"
android:theme="@style/wsAppTheme">

<uses-library android:name="com.google.android.maps" />

<!-- The authenticator service -->
<service
android:name=".auth.AuthenticationService"
Expand Down Expand Up @@ -84,9 +88,6 @@
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package fi.bitrite.android.ws.api.model;

import com.google.android.gms.maps.model.LatLng;
import com.google.gson.annotations.SerializedName;

import org.osmdroid.util.GeoPoint;

import java.util.Date;

import fi.bitrite.android.ws.model.SimpleUser;
Expand Down Expand Up @@ -85,7 +86,7 @@ public static class CommentNotifySettings {

public User toUser() {
return new User(id, name, fullname, street, additionalAddress, city, province, postalCode,
countryCode, new LatLng(latitude, longitude), mobilePhone, homePhone, workPhone,
countryCode, new GeoPoint(latitude, longitude), mobilePhone, homePhone, workPhone,
comments, preferredNotice, maximalCyclistCount, distanceToMotel,
distanceToCampground, distanceToBikeshop, hasStorage, hasShower, hasKitchen,
hasLawnspace, hasSag, hasBed, hasLaundry, hasFood, spokenLanguages,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package fi.bitrite.android.ws.api.response;

import com.google.android.gms.maps.model.LatLng;
import com.google.gson.annotations.SerializedName;

import org.osmdroid.util.GeoPoint;

import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -59,7 +60,7 @@ public static class User {

public SimpleUser toSimpleUser() {
return new SimpleUser(id, name, fullname, street, city, province, postalCode,
countryCode, new LatLng(latitude, longitude), !notCurrentlyAvailable,
countryCode, new GeoPoint(latitude, longitude), !notCurrentlyAvailable,
new SimpleUser.Picture(profilePictureUrl_179x200, profilePictureUrl_400x400),
created, lastAccess);
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/fi/bitrite/android/ws/model/SimpleUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.text.TextUtils;

import com.google.android.gms.maps.model.LatLng;
import org.osmdroid.api.IGeoPoint;

import java.util.Date;

Expand Down Expand Up @@ -34,7 +34,7 @@ public String getLargeUrl() {
public final String province;
public final String postalCode;
public final String countryCode;
public final LatLng location;
public final IGeoPoint location;

public final boolean isCurrentlyAvailable;
public final Picture profilePicture;
Expand All @@ -43,7 +43,7 @@ public String getLargeUrl() {
public final Date lastAccess;

public SimpleUser(int id, String name, String fullname, String street, String city,
String province, String postalCode, String countryCode, LatLng location,
String province, String postalCode, String countryCode, IGeoPoint location,
boolean isCurrentlyAvailable, Picture profilePicture, Date created,
Date lastAccess) {
this.id = id;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/fi/bitrite/android/ws/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.res.Resources;
import android.text.TextUtils;

import com.google.android.gms.maps.model.LatLng;
import org.osmdroid.api.IGeoPoint;

import java.util.Date;

Expand Down Expand Up @@ -37,7 +37,7 @@ public class User extends SimpleUser {

public User(int id, String name, String fullname, String street, String additionalAddress,
String city, String province, String postalCode, String countryCode,
LatLng location, String mobilePhone, String homePhone, String workPhone,
IGeoPoint location, String mobilePhone, String homePhone, String workPhone,
String comments, String preferredNotice, int maximalCyclistCount,
String distanceToMotel, String distanceToCampground, String distanceToBikeshop,
boolean hasStorage, boolean hasShower, boolean hasKitchen, boolean hasLawnspace,
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/fi/bitrite/android/ws/model/ZoomedLocation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fi.bitrite.android.ws.model;

import org.osmdroid.api.IGeoPoint;
import org.osmdroid.util.GeoPoint;

public class ZoomedLocation {
public final IGeoPoint location;
public final double zoom;

public ZoomedLocation(double lat, double lon, double zoom) {
this(new GeoPoint(lat, lon), zoom);
}
public ZoomedLocation(IGeoPoint location, double zoom) {
this.location = location;
this.zoom = zoom;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;

import com.google.android.gms.maps.model.LatLng;
import org.osmdroid.util.GeoPoint;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -144,8 +144,8 @@ public void save(SQLiteDatabase db, User user) {
cv.put("created", DateConverter.dateToLong(user.created));
cv.put("currently_available", user.isCurrentlyAvailable);
cv.put("spoken_languages", user.spokenLanguages);
cv.put("latitude", user.location.latitude);
cv.put("longitude", user.location.longitude);
cv.put("latitude", user.location.getLatitude());
cv.put("longitude", user.location.getLongitude());
cv.put("profile_picture_small", user.profilePicture.getSmallUrl());
cv.put("profile_picture_large", user.profilePicture.getLargeUrl());

Expand All @@ -170,7 +170,7 @@ private static User getUserFromCursor(@NonNull Cursor c) {
c.getString(COL_IDX_PROVINCE),
c.getString(COL_IDX_POSTAL_CODE),
c.getString(COL_IDX_COUNTRY_CODE),
new LatLng(c.getDouble(COL_IDX_LATITUDE), c.getDouble(COL_IDX_LONGITUDE)),
new GeoPoint(c.getDouble(COL_IDX_LATITUDE), c.getDouble(COL_IDX_LONGITUDE)),
c.getString(COL_IDX_MOBILE_PHONE),
c.getString(COL_IDX_HOME_PHONE),
c.getString(COL_IDX_WORK_PHONE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import android.preference.PreferenceManager;
import android.text.TextUtils;

import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;

import javax.inject.Inject;

import fi.bitrite.android.ws.R;
import fi.bitrite.android.ws.di.AppScope;
import fi.bitrite.android.ws.model.ZoomedLocation;

@AppScope
public class SettingsRepository {
Expand All @@ -29,11 +29,13 @@ public enum DistanceUnit {
private final static String KEYSUFFIX_LOCATION_ZOOM = "_zoom";

private final String mKeyDistanceUnit;
private final String mKeyTileSource;
private final String mKeyMessageRefreshInterval;
private final String mKeyGaCollectStats;
private final String mKeyDevSimulateNoNetwork;

private final String mDefaultDistanceUnit;
private final String mDefaultTileSource = TileSourceFactory.DEFAULT_TILE_SOURCE.name();
private final int mDefaultMessageRefreshInterval;
private final boolean mDefaultGaCollectStats;
private final boolean mDefaultDevSimulateNoNetwork;
Expand All @@ -55,6 +57,7 @@ public enum DistanceUnit {

final Resources res = context.getResources();
mKeyDistanceUnit = res.getString(R.string.prefs_distance_unit_key);
mKeyTileSource = res.getString(R.string.prefs_tile_source_key);
mKeyMessageRefreshInterval = res.getString(R.string.prefs_message_refresh_interval_min_key);
mKeyGaCollectStats = res.getString(R.string.prefs_ga_collect_stats_key);
mKeyDevSimulateNoNetwork = res.getString(R.string.prefs_dev_simulate_no_network_key);
Expand Down Expand Up @@ -113,17 +116,21 @@ public String getDistanceUnitShort() {
}
}

private void setLocation(String key, CameraPosition position) {
public String getTileSourceStr() {
return mSharedPreferences.getString(mKeyTileSource, mDefaultTileSource);
}

private void setLocation(String key, ZoomedLocation position) {
mSharedPreferences
.edit()
.putFloat(key + KEYSUFFIX_LOCATION_LATITUDE, (float) position.target.latitude)
.putFloat(key + KEYSUFFIX_LOCATION_LONGITUDE, (float) position.target.longitude)
.putFloat(key + KEYSUFFIX_LOCATION_ZOOM, position.zoom)
.putFloat(key + KEYSUFFIX_LOCATION_LATITUDE, (float) position.location.getLatitude())
.putFloat(key + KEYSUFFIX_LOCATION_LONGITUDE, (float) position.location.getLongitude())
.putFloat(key + KEYSUFFIX_LOCATION_ZOOM, (float) position.zoom)
.apply();

}

public CameraPosition getLastMapLocation(boolean defaultIfNone) {
public ZoomedLocation getLastMapLocation(boolean defaultIfNone) {
if (!mSharedPreferences.contains(KEY_MAP_LAST_LOCATION + KEYSUFFIX_LOCATION_LATITUDE)
&& !defaultIfNone) {
return null;
Expand All @@ -135,9 +142,9 @@ public CameraPosition getLastMapLocation(boolean defaultIfNone) {
float zoom = mSharedPreferences.getFloat(
KEY_MAP_LAST_LOCATION + KEYSUFFIX_LOCATION_ZOOM, mDefaultMapLocationZoom);

return new CameraPosition(new LatLng(latitude, longitude), zoom, 0, 0);
return new ZoomedLocation(latitude, longitude, zoom);
}
public void setLastMapLocation(CameraPosition position) {
public void setLastMapLocation(ZoomedLocation position) {
setLocation(KEY_MAP_LAST_LOCATION, position);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.support.annotation.NonNull;

import com.google.android.gms.maps.model.LatLng;
import org.osmdroid.util.BoundingBox;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -60,9 +60,9 @@ public Observable<List<Integer>> searchByKeyword(String keyword) {
return getAppUserRepository().searchByKeyword(keyword);
}

public Observable<List<UserSearchByLocationResponse.User>> searchByLocation(LatLng northEast,
LatLng southWest) {
return getAppUserRepository().searchByLocation(northEast, southWest);
public Observable<List<UserSearchByLocationResponse.User>> searchByLocation(
BoundingBox boundingBox) {
return getAppUserRepository().searchByLocation(boundingBox);
}

/**
Expand Down Expand Up @@ -151,13 +151,13 @@ Observable<List<Integer>> searchByKeyword(String keyword) {
});
}

Observable<List<UserSearchByLocationResponse.User>> searchByLocation(LatLng northEast,
LatLng southWest) {
Observable<List<UserSearchByLocationResponse.User>> searchByLocation(
BoundingBox boundingBox) {

final double minLat = southWest.latitude;
final double minLon = southWest.longitude;
final double maxLat = northEast.latitude;
final double maxLon = northEast.longitude;
final double minLat = boundingBox.getLatSouth();
final double minLon = boundingBox.getLonWest();
final double maxLat = boundingBox.getLatNorth();
final double maxLon = boundingBox.getLonEast();
final double centerLat = (minLat + maxLat) / 2.0f;
final double centerLon = (minLon + maxLon) / 2.0f;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ CompositeDisposable getStartStopDisposable() {
CompositeDisposable getResumePauseDisposable() {
return mResumePauseDisposable.get();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import butterknife.ButterKnife;
import butterknife.OnItemClick;
import fi.bitrite.android.ws.R;
import fi.bitrite.android.ws.model.SimpleUser;
import fi.bitrite.android.ws.model.User;
import fi.bitrite.android.ws.repository.FavoriteRepository;
import fi.bitrite.android.ws.repository.Resource;
Expand Down Expand Up @@ -74,15 +75,15 @@ public void onResume() {

@OnItemClick(R.id.favorites_lst_users)
public void onUserClicked(int position) {
User selectedUser = mUserListAdapter.getUser(position);
SimpleUser selectedUser = mUserListAdapter.getUser(position);
getNavigationController().navigateToUser(selectedUser.id);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
if (view.getId() == mLstUsers.getId()) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
User user = mUserListAdapter.getUser(info.position);
SimpleUser user = mUserListAdapter.getUser(info.position);

menu.setHeaderTitle(user.fullname);
menu.add(Menu.NONE, CONTEXT_MENU_DELETE, 0, R.string.delete);
Expand All @@ -96,7 +97,7 @@ public boolean onContextItemSelected(MenuItem item) {

switch (item.getItemId()) {
case CONTEXT_MENU_DELETE:
User user = mUserListAdapter.getUser(info.position);
SimpleUser user = mUserListAdapter.getUser(info.position);
mFavoriteRepository.remove(user.id);
updateFavoriteUsersList();
return true;
Expand Down
Loading

0 comments on commit 5e6bd1e

Please sign in to comment.