Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Integrate electric bikes #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ android {
}

dependencies {
compile 'org.osmdroid:osmdroid-android:5.6.4'
compile 'org.osmdroid:osmdroid-android:6.1.8'
compile 'com.github.MKergall:osmbonuspack:6.3'
compile 'com.android.support:support-v4:23.0.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.osmdroid.api.IMapController;
import org.osmdroid.bonuspack.clustering.GridMarkerClusterer;
import org.osmdroid.config.Configuration;
import org.osmdroid.events.MapEventsReceiver;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
Expand All @@ -53,6 +55,7 @@
import java.util.ArrayList;

import be.brunoparmentier.openbikesharing.app.R;
import be.brunoparmentier.openbikesharing.app.BuildConfig;
import be.brunoparmentier.openbikesharing.app.db.StationsDataSource;
import be.brunoparmentier.openbikesharing.app.models.Station;
import be.brunoparmentier.openbikesharing.app.models.StationStatus;
Expand Down Expand Up @@ -96,6 +99,10 @@ protected void onCreate(Bundle savedInstanceState) {
stationsDataSource = new StationsDataSource(this);
ArrayList<Station> stations = stationsDataSource.getStations();

final Context context = getApplicationContext();
Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context));
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);

map = (MapView) findViewById(R.id.mapView);
stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map);

Expand All @@ -118,7 +125,7 @@ protected void onCreate(Bundle savedInstanceState) {

map.setMultiTouchControls(true);
map.setBuiltInZoomControls(true);
map.setMinZoomLevel(3);
map.setMinZoomLevel(Double.valueOf(3));

/* map tile source */
String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, "");
Expand All @@ -127,7 +134,7 @@ protected void onCreate(Bundle savedInstanceState) {
map.setTileSource(TileSourceFactory.MAPNIK);
break;
case MAP_LAYER_CYCLEMAP:
map.setTileSource(TileSourceFactory.CYCLEMAP);
map.setTileSource(TileSourceFactory.HIKEBIKEMAP);
break;
case MAP_LAYER_OSMPUBLICTRANSPORT:
map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
Expand Down Expand Up @@ -283,6 +290,23 @@ public void onOpen(Object item) {
ImageView emptySlotsLogo = (ImageView) getView().findViewById(R.id.bubble_emptyslots_logo);
emptySlotsLogo.setVisibility(View.GONE);
}

ImageView regularBikesLogo = (ImageView) getView().findViewById(R.id.bubble_freebikes_logo);
TextView regularBikesValue = (TextView) getView().findViewById(R.id.bubble_description);
ImageView eBikesLogo = (ImageView) getView().findViewById(R.id.bubble_ebikes_logo);
TextView eBikesValue = (TextView) getView().findViewById(R.id.bubble_ebikes_value);

int bikes = markerStation.getFreeBikes();
if(markerStation.getEBikes() != null && regularBikesLogo != null
&& eBikesLogo != null && regularBikesValue!= null && eBikesValue != null ) {
int ebikes = markerStation.getEBikes();
regularBikesValue.setText(String.valueOf(bikes-ebikes));
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
eBikesLogo.setVisibility(View.VISIBLE);
eBikesValue.setVisibility(View.VISIBLE);
eBikesValue.setText(String.valueOf(ebikes));
}

layout.setClickable(true);
layout.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
Expand All @@ -36,6 +37,7 @@
import android.widget.Toast;

import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
Expand All @@ -48,6 +50,7 @@
import java.util.TimeZone;

import be.brunoparmentier.openbikesharing.app.R;
import be.brunoparmentier.openbikesharing.app.BuildConfig;
import be.brunoparmentier.openbikesharing.app.db.StationsDataSource;
import be.brunoparmentier.openbikesharing.app.models.Station;
import be.brunoparmentier.openbikesharing.app.models.StationStatus;
Expand Down Expand Up @@ -79,6 +82,10 @@ protected void onCreate(Bundle savedInstanceState) {

station = (Station) getIntent().getSerializableExtra(KEY_STATION);

final Context context = getApplicationContext();
Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context));
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);

map = (MapView) findViewById(R.id.mapView);
final GeoPoint stationLocation = new GeoPoint((int) (station.getLatitude() * 1000000),
(int) (station.getLongitude() * 1000000));
Expand All @@ -93,7 +100,7 @@ protected void onCreate(Bundle savedInstanceState) {
map.setTileSource(TileSourceFactory.MAPNIK);
break;
case MAP_LAYER_CYCLEMAP:
map.setTileSource(TileSourceFactory.CYCLEMAP);
map.setTileSource(TileSourceFactory.HIKEBIKEMAP);
break;
case MAP_LAYER_OSMPUBLICTRANSPORT:
map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT);
Expand Down Expand Up @@ -164,6 +171,7 @@ public boolean onMarkerClick(Marker marker, MapView mapView) {
Boolean isBankingStation = station.isBanking();
Boolean isBonusStation = station.isBonus();
StationStatus stationStatus = station.getStatus();
Integer stationEBikes = station.getEBikes();

if (isBankingStation != null) {
ImageView stationBanking = (ImageView) findViewById(R.id.stationBanking);
Expand Down Expand Up @@ -201,6 +209,19 @@ public void onClick(View view) {
stationName.setPaintFlags(stationName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}

if (stationEBikes != null) {
ImageView eBikesLogo = (ImageView) findViewById(R.id.stationEBikesLogo);
ImageView regularBikesLogo = (ImageView) findViewById(R.id.stationFreeBikesLogo);
TextView stationEBikesValue = (TextView) findViewById(R.id.stationEBikesValue);
int ebikes = station.getEBikes();

eBikesLogo.setVisibility(View.VISIBLE);
stationEBikesValue.setVisibility(View.VISIBLE);
stationEBikesValue.setText(String.valueOf(ebikes));
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
stationFreeBikes.setText(String.valueOf(freeBikes - ebikes)); //display regular bikes only
}

mapController.setCenter(stationLocation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (station != null) {
TextView stationNameTitle = (TextView) v.findViewById(R.id.stationNameTitle);
TextView freeBikesValue = (TextView) v.findViewById(R.id.freeBikesValue);
ImageView regularBikesLogo = (ImageView) v.findViewById(R.id.freeBikesLogo);
TextView freeEBikesValue = (TextView) v.findViewById(R.id.freeEBikesValue);
ImageView eBikesLogo = (ImageView) v.findViewById(R.id.freeEBikesLogo);
TextView emptySlotsValue = (TextView) v.findViewById(R.id.emptySlotsValue);
StationStatus stationStatus = station.getStatus();

Expand All @@ -72,7 +75,17 @@ public View getView(int position, View convertView, ViewGroup parent) {

if (freeBikesValue != null) {
int bikes = station.getFreeBikes();
freeBikesValue.setText(String.valueOf(bikes));
if(station.getEBikes() != null && regularBikesLogo != null
&& eBikesLogo != null && freeEBikesValue != null ) {
int ebikes = station.getEBikes();
freeBikesValue.setText(String.valueOf(bikes-ebikes));
regularBikesLogo.setImageResource(R.drawable.ic_regular_bike);
eBikesLogo.setVisibility(View.VISIBLE);
freeEBikesValue.setVisibility(View.VISIBLE);
freeEBikesValue.setText(String.valueOf(ebikes));
} else {
freeBikesValue.setText(String.valueOf(bikes));
}
}

if (emptySlotsValue != null) {
Expand All @@ -91,4 +104,4 @@ public View getView(int position, View convertView, ViewGroup parent) {

return v;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private static DatabaseHelper instance;

private static final String DB_NAME = "openbikesharing.sqlite";
private static final int DB_VERSION = 1;
private static final int DB_VERSION = 2;

public static final String STATIONS_TABLE_NAME = "stations";
public static final String STATIONS_COLUMN_ID = "id";
Expand All @@ -39,6 +39,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
public static final String STATIONS_COLUMN_BANKING = "banking";
public static final String STATIONS_COLUMN_BONUS = "bonus";
public static final String STATIONS_COLUMN_STATUS = "status";
public static final String STATIONS_COLUMN_EBIKES = "ebikes";

public static final String FAV_STATIONS_TABLE_NAME = "fav_stations";
public static final String FAV_STATIONS_COLUMN_ID = "id";
Expand All @@ -61,7 +62,8 @@ public void onCreate(SQLiteDatabase db) {
+ "(id TEXT PRIMARY KEY, name TEXT NOT NULL, last_update TEXT NOT NULL, "
+ "latitude NUMERIC NOT NULL, longitude NUMERIC NOT NULL, "
+ "free_bikes INTEGER NOT NULL, empty_slots INTEGER NOT NULL, "
+ "address TEXT, banking INTEGER, bonus INTEGER, status TEXT)"
+ "address TEXT, banking INTEGER, bonus INTEGER, status TEXT, "
+ "ebikes INTEGER) "
);
db.execSQL("CREATE TABLE " + FAV_STATIONS_TABLE_NAME
+ "(id TEXT PRIMARY KEY)"
Expand All @@ -71,6 +73,9 @@ public void onCreate(SQLiteDatabase db) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

if (oldVersion < 2) {
db.execSQL("ALTER TABLE " + STATIONS_TABLE_NAME + " ADD COLUMN ebikes INTEGER;");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public void storeStations(ArrayList<Station> stations) {
values.put(DatabaseHelper.STATIONS_COLUMN_BONUS, station.isBonus() ? 1 : 0);
if (station.getStatus() != null)
values.put(DatabaseHelper.STATIONS_COLUMN_STATUS, station.getStatus().name());

if (station.getEBikes() != null) {
values.put(DatabaseHelper.STATIONS_COLUMN_EBIKES, String.valueOf(station.getEBikes()));
}
db.insert(DatabaseHelper.STATIONS_TABLE_NAME, null, values);
}
db.setTransactionSuccessful();
Expand All @@ -75,7 +77,7 @@ public ArrayList<Station> getStations() {
SQLiteDatabase db = dbHelper.getReadableDatabase();
ArrayList<Station> stations = new ArrayList<>();
Cursor cursor = db.rawQuery("SELECT id as _id, name, last_update, latitude, longitude, "
+ "free_bikes, empty_slots, address, banking, bonus, status "
+ "free_bikes, empty_slots, address, banking, bonus, status, ebikes "
+ "FROM " + DatabaseHelper.STATIONS_TABLE_NAME, null);

try {
Expand All @@ -97,7 +99,7 @@ public Station getStation(String id) {
SQLiteDatabase db = dbHelper.getReadableDatabase();

Cursor cursor = db.rawQuery("SELECT id as _id, name, last_update, latitude, longitude, "
+ "free_bikes, empty_slots, address, banking, bonus, status "
+ "free_bikes, empty_slots, address, banking, bonus, status, ebikes "
+ "FROM " + DatabaseHelper.STATIONS_TABLE_NAME + " "
+ "WHERE id = ?", new String[] { id });
try {
Expand Down Expand Up @@ -127,7 +129,7 @@ public ArrayList<Station> getFavoriteStations() {
SQLiteDatabase db = dbHelper.getReadableDatabase();
ArrayList<Station> favStations = new ArrayList<>();
Cursor cursor = db.rawQuery("SELECT sta.id as _id, name, last_update, latitude, longitude, "
+ "free_bikes, empty_slots, address, banking, bonus, status "
+ "free_bikes, empty_slots, address, banking, bonus, status, ebikes "
+ "FROM " + DatabaseHelper.FAV_STATIONS_TABLE_NAME + " sta "
+ "INNER JOIN " + DatabaseHelper.STATIONS_TABLE_NAME + " fav "
+ "ON sta.id = fav.id", null);
Expand Down Expand Up @@ -181,6 +183,9 @@ private Station toStation(Cursor cursor) {
if (!cursor.isNull(10)) {
station.setStatus(StationStatus.valueOf(cursor.getString(10))); // status
}
if (!cursor.isNull(11)) {
station.setEBikes(cursor.getInt(11)); // ebikes
}

return station;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Station implements Serializable, Comparable<Station> {
private Boolean banking;
private Boolean bonus;
private StationStatus status;
private Integer eBikes;

public Station(String id, String name, String lastUpdate, double latitude, double longitude, int freeBikes, int emptySlots) {
this.id = id;
Expand All @@ -49,6 +50,7 @@ public Station(String id, String name, String lastUpdate, double latitude, doubl
this.banking = null;
this.bonus = null;
this.status = null;
this.eBikes = null;
}

public String getId() {
Expand Down Expand Up @@ -95,6 +97,10 @@ public Boolean isBonus() {
return bonus;
}

public Integer getEBikes() {
return eBikes;
}

public StationStatus getStatus() {
return status;
}
Expand All @@ -111,6 +117,10 @@ public void setBonus(boolean bonus) {
this.bonus = bonus;
}

public void setEBikes(int eBikes) {
this.eBikes = eBikes;
}

@Override
public int compareTo(Station another) {
return name.compareToIgnoreCase(another.getName()) > 0 ? 1 :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public BikeNetworkParser(String toParse, boolean stripIdFromStationName) throws
station.setStatus(StationStatus.OPEN);
}
}

/* electric bikes */
if (rawExtra.has("ebikes")) {
station.setEBikes(rawExtra.getInt("ebikes"));
}
}
stations.add(station);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;

Expand Down Expand Up @@ -88,9 +89,19 @@ public RemoteViews getViewAt(int position) {
// We construct a remote views item based on our widget item xml file, and set the
// text based on the position.
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.app_widget_item);
rv.setTextViewText(R.id.widgetStationNameTitle, stations.get(position).getName());
rv.setTextViewText(R.id.widgetFreeBikesValue, String.valueOf(stations.get(position).getFreeBikes()));
rv.setTextViewText(R.id.widgetEmptySlotsValue, String.valueOf(stations.get(position).getEmptySlots()));
Station mStation = stations.get(position);
rv.setTextViewText(R.id.widgetStationNameTitle, mStation.getName());
int bikes = mStation.getFreeBikes();
if(mStation.getEBikes() != null) {
int ebikes = mStation.getEBikes();
rv.setImageViewResource(R.id.widgetFreeBikesLogo, R.drawable.ic_regular_bike);
rv.setViewVisibility(R.id.widgetEBikesLogo, View.VISIBLE);
rv.setViewVisibility(R.id.widgetEBikesValue, View.VISIBLE);
rv.setTextViewText(R.id.widgetEBikesValue, String.valueOf(ebikes));
bikes = bikes - ebikes;
}
rv.setTextViewText(R.id.widgetFreeBikesValue, String.valueOf(bikes));
rv.setTextViewText(R.id.widgetEmptySlotsValue, String.valueOf(mStation.getEmptySlots()));

// Next, we set a fill-intent which will be used to fill-in the pending intent template
// which is set on the collection view in StationsListAppWidgetProvider.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading