Skip to content

Commit

Permalink
Merge pull request #40 from hyperrail/development
Browse files Browse the repository at this point in the history
Version 0.9.3
  • Loading branch information
Bertware authored Jul 1, 2017
2 parents 64c1d94 + 7ef4aba commit 1440a9f
Show file tree
Hide file tree
Showing 50 changed files with 818 additions and 412 deletions.
5 changes: 3 additions & 2 deletions Hyperrail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'com.google.firebase.firebase-crash'

def VERSION_CODE = 4
def VERSION_NAME = '0.9.2'
def VERSION_CODE = 5
def VERSION_NAME = '0.9.3'

android {
signingConfigs {
Expand Down Expand Up @@ -55,6 +55,7 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'joda-time:joda-time:2.9.4'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
Expand Down
6 changes: 5 additions & 1 deletion Hyperrail/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keepattributes SourceFile,LineNumberTable
-keepattributes SourceFile,LineNumberTable
-dontwarn org.joda.convert.**
-dontwarn org.joda.time.**
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *;}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import android.view.View;
import android.view.ViewGroup;

import java.util.Date;
import org.joda.time.DateTime;

import be.hyperrail.android.adapter.DisturbanceCardAdapter;
import be.hyperrail.android.adapter.onRecyclerItemClickListener;
Expand All @@ -45,7 +45,7 @@ public class DisturbanceListFragment extends Fragment implements onRecyclerItemC
private RecyclerView vRecyclerView;
private SwipeRefreshLayout vRefreshLayout;
private Disturbance[] disturbances;
private Date lastUpdate;
private DateTime lastUpdate;

public DisturbanceListFragment() {
// Required empty public constructor
Expand Down Expand Up @@ -94,7 +94,7 @@ public void onRefresh() {

if (savedInstanceState != null) {
this.disturbances = (Disturbance[]) savedInstanceState.getSerializable("disturbances");
this.lastUpdate = new Date(savedInstanceState.getLong("updated"));
this.lastUpdate = new DateTime(savedInstanceState.getLong("updated"));
this.setData(this.disturbances);
} else {
loadDisturbances();
Expand All @@ -105,7 +105,7 @@ public void onRefresh() {
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("disturbances", disturbances);
outState.putLong("updated", lastUpdate.getTime());
outState.putLong("updated", lastUpdate.getMillis());
}

private void loadDisturbances() {
Expand All @@ -125,7 +125,7 @@ protected void onPostExecute(IrailDataResponse<Disturbance[]> response) {
vRefreshLayout.setRefreshing(false);

if (response.isSuccess()) {
lastUpdate = new Date();
lastUpdate = new DateTime();
setData(response.getData());
} else {
// Don't finish, this is the main activity
Expand Down Expand Up @@ -159,8 +159,10 @@ private void setData(Disturbance[] disturbances) {
}

@Override
public void onRecyclerItemClick(RecyclerView.Adapter sender, Disturbance object) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(object.getLink()));
startActivity(browserIntent);
public void onRecyclerItemClick(RecyclerView.Adapter sender, Disturbance disturbance) {
if (disturbance.getLink() != null && !disturbance.getLink().isEmpty()) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(disturbance.getLink()));
startActivity(browserIntent);
}
}
}
44 changes: 20 additions & 24 deletions Hyperrail/src/main/java/be/hyperrail/android/LiveboardActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

package be.hyperrail.android;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
Expand All @@ -24,8 +23,8 @@

import com.google.firebase.analytics.FirebaseAnalytics;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import be.hyperrail.android.adapter.LiveboardCardAdapter;
import be.hyperrail.android.adapter.onRecyclerItemClickListener;
Expand Down Expand Up @@ -80,6 +79,7 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("liveboard", mCurrentLiveboard);
}

@Override
protected LiveBoard getRestoredInstanceStateItems() {
return mCurrentLiveboard;
Expand All @@ -88,10 +88,11 @@ protected LiveBoard getRestoredInstanceStateItems() {
@Override
protected void onDestroy() {
super.onDestroy();
if (runningTask != null && runningTask.getStatus() != AsyncTask.Status.FINISHED){
if (runningTask != null && runningTask.getStatus() != AsyncTask.Status.FINISHED) {
runningTask.cancel(true);
}
}

@Override
protected int getLayout() {
return R.layout.activity_liveboard;
Expand All @@ -117,18 +118,14 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
protected InfiniteScrollingAdapter<TrainStop> getAdapter() {
LiveboardCardAdapter adapter = new LiveboardCardAdapter(this, vRecyclerView, this, null);
LiveboardCardAdapter adapter = new LiveboardCardAdapter(this, vRecyclerView, this);
adapter.setOnItemClickListener(this);
return adapter;
}

@Override
protected void getInitialData() {
if (mCurrentLiveboard == null) {
getData();
} else {
showData(mCurrentLiveboard);
}
getData();
}

@Override
Expand All @@ -153,7 +150,7 @@ protected void onPostExecute(IrailDataResponse<LiveBoard> response) {
LiveboardActivity.this.getNextData();
} else {
// Enable infinite scrolling, in case it was disabled during a previous search
((InfiniteScrollingAdapter)vRecyclerView.getAdapter()).setInfiniteScrolling(true);
((InfiniteScrollingAdapter) vRecyclerView.getAdapter()).setInfiniteScrolling(true);
}

} else {
Expand All @@ -168,25 +165,24 @@ protected void onPreExecute() {
super.onPreExecute();
if (mSearchDate != null) {
vWarningNotRealtime.setVisibility(View.VISIBLE);
@SuppressLint("SimpleDateFormat")
DateFormat df = new SimpleDateFormat(getString(R.string.warning_not_realtime_datetime));
vWarningNotRealtimeText.setText(String.format("%s %s", getString(R.string.warning_not_realtime), df.format(mSearchDate)));
DateTimeFormatter df = DateTimeFormat.forPattern(getString(R.string.warning_not_realtime_datetime));
vWarningNotRealtimeText.setText(String.format("%s %s", getString(R.string.warning_not_realtime), df.print(mSearchDate)));
} else {
vWarningNotRealtime.setVisibility(View.GONE);
}
}

@Override
protected IrailDataResponse<LiveBoard> doInBackground(Station... stations) {
if (mSearchDate == null) {
return stations[0].getLiveBoard();
} else {
return stations[0].getLiveBoard(mSearchDate);
}
if (mSearchDate == null) {
return stations[0].getLiveBoard();
} else {
return stations[0].getLiveBoard(mSearchDate);
}
}
};

if (runningTask != null && runningTask.getStatus() != AsyncTask.Status.FINISHED){
if (runningTask != null && runningTask.getStatus() != AsyncTask.Status.FINISHED) {
runningTask.cancel(true);
}

Expand All @@ -206,14 +202,14 @@ protected void getNextData() {
protected void onPostExecute(ApiResponse<TrainStop[]> liveboard) {
super.onPostExecute(liveboard);

if (! liveboard.isSuccess()) {
if (!liveboard.isSuccess()) {
ErrorDialogFactory.showErrorDialog(liveboard.getException(), LiveboardActivity.this, false);
((LiveboardCardAdapter) vRecyclerView.getAdapter()).resetInfiniteScrollingState();
return;
}

if ( liveboard.getData().length == 0){
((InfiniteScrollingAdapter)vRecyclerView.getAdapter()).setInfiniteScrolling(false);
if (liveboard.getData().length == 0) {
((InfiniteScrollingAdapter) vRecyclerView.getAdapter()).setInfiniteScrolling(false);
}

showData(mCurrentLiveboard);
Expand All @@ -234,7 +230,7 @@ protected void showData(LiveBoard liveBoard) {
setSubTitle(liveBoard.getLocalizedName());
}

if (mSearchDate == null){
if (mSearchDate == null) {
vWarningNotRealtime.setVisibility(View.GONE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ private void openLiveboard(Station station) {
* @param stations The new array of stations
*/
private void setStations(Station[] stations) {
FirebaseCrash.logcat(INFO.intValue(),LogTag,"Setting liveboard search list to " + stations.length + " stations");
if (stations != null){
FirebaseCrash.logcat(INFO.intValue(),LogTag,"Setting liveboard search list to " + stations.length + " stations");
} else {
FirebaseCrash.logcat(INFO.intValue(),LogTag,"Setting liveboard search list to 0 stations");
}

StationCardAdapter adapter = (StationCardAdapter) stationRecyclerView.getAdapter();
adapter.setStations(stations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.Date;
import org.joda.time.DateTime;

import be.hyperrail.android.infiniteScrolling.InfiniteScrollingDataSource;
import be.hyperrail.android.persistence.PersistentQueryProvider;
Expand Down Expand Up @@ -90,7 +90,7 @@ public abstract class RecyclerViewActivity<T> extends AppCompatActivity implemen
/**
* Date for which should be searched. Null for 'now'.
*/
protected Date mSearchDate;
protected DateTime mSearchDate;

/**
* Reference to shared preferences
Expand Down Expand Up @@ -267,7 +267,7 @@ protected void getInitialData() {
protected abstract void showData(T data);

@Override
public void onDateTimePicked(Date date) {
public void onDateTimePicked(DateTime date) {
mSearchDate = date;

// empty the view while loading
Expand Down
31 changes: 12 additions & 19 deletions Hyperrail/src/main/java/be/hyperrail/android/RouteActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import com.google.firebase.analytics.FirebaseAnalytics;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import be.hyperrail.android.adapter.RouteCardAdapter;
import be.hyperrail.android.infiniteScrolling.InfiniteScrollingDataSource;
Expand All @@ -47,14 +47,14 @@ public class RouteActivity extends RecyclerViewActivity<Route[]> implements Infi
private Station mSearchFrom;
private Station mSearchTo;
private RouteTimeDefinition mSearchTimeType = RouteTimeDefinition.DEPART;
private Date mSearchDate;
private DateTime mSearchDate;

private AsyncTask runningTask;
private FirebaseAnalytics mFirebaseAnalytics;

private boolean initialLoadCompleted = false;

public static Intent createIntent(Context context, Station from, Station to, Date date, RouteTimeDefinition datetype) {
public static Intent createIntent(Context context, Station from, Station to, DateTime date, RouteTimeDefinition datetype) {
Intent i = new Intent(context, RouteActivity.class);
i.putExtra("from", from);
i.putExtra("to", to);
Expand All @@ -65,7 +65,7 @@ public static Intent createIntent(Context context, Station from, Station to, Dat
return i;
}

public static Intent createIntent(Context context, Station from, Station to, Date date) {
public static Intent createIntent(Context context, Station from, Station to, DateTime date) {
Intent i = new Intent(context, RouteActivity.class);
i.putExtra("from", from);
i.putExtra("to", to);
Expand All @@ -89,7 +89,7 @@ protected void onCreate(Bundle savedInstanceState) {
mSearchTimeType = RouteTimeDefinition.valueOf(mSearchArgs.getString("arrivedepart"));

if (mSearchArgs.containsKey("date")) {
mSearchDate = (Date) mSearchArgs.getSerializable("date");
mSearchDate = (DateTime) mSearchArgs.getSerializable("date");
} else {
mSearchDate = null;
}
Expand Down Expand Up @@ -122,13 +122,6 @@ protected Route[] getRestoredInstanceStateItems() {

@Override
protected void getInitialData() {

if (mRoutes != null) {
// routes are already retrieved from instance state (e.g. on rotation)
showData(mRoutes.getRoutes());
return;
}

getData();
}

Expand Down Expand Up @@ -163,8 +156,8 @@ protected void onPreExecute() {
if (mSearchDate != null) {
vWarningNotRealtime.setVisibility(View.VISIBLE);
@SuppressLint("SimpleDateFormat")
DateFormat df = new SimpleDateFormat(getString(R.string.warning_not_realtime_datetime));
vWarningNotRealtimeText.setText(String.format("%s %s", getString(R.string.warning_not_realtime), df.format(mSearchDate)));
DateTimeFormatter df = DateTimeFormat.forPattern(getString(R.string.warning_not_realtime_datetime));
vWarningNotRealtimeText.setText(String.format("%s %s", getString(R.string.warning_not_realtime), df.print(mSearchDate)));
} else {
vWarningNotRealtime.setVisibility(View.GONE);
}
Expand All @@ -177,7 +170,7 @@ protected IrailDataResponse<RouteResult> doInBackground(Void... arglist) {
if (mSearchDate != null) {
return api.getRoute(mSearchFrom, mSearchTo, mSearchDate, mSearchTimeType);
} else {
return api.getRoute(mSearchFrom, mSearchTo, new Date(), mSearchTimeType);
return api.getRoute(mSearchFrom, mSearchTo, new DateTime(), mSearchTimeType);
}

}
Expand Down Expand Up @@ -274,11 +267,11 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
protected RecyclerView.Adapter getAdapter() {
return new RouteCardAdapter(this, vRecyclerView, this, null);
return new RouteCardAdapter(this, vRecyclerView, this);
}

@Override
public void onDateTimePicked(Date date) {
public void onDateTimePicked(DateTime date) {
mSearchDate = date;

// empty the view while loading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import android.support.v7.widget.RecyclerView;
import android.view.View;

import org.joda.time.DateTime;

import java.text.DateFormat;
import java.util.Date;

import be.hyperrail.android.adapter.RouteDetailCardAdapter;
import be.hyperrail.android.adapter.onRecyclerItemClickListener;
Expand Down Expand Up @@ -55,7 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {

DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);

setSubTitle(df.format(route.getDepartureTime().getTime()));
setSubTitle(df.format(route.getDepartureTime().toString()));

// disable pull-to-refresh
// TODO: support refreshing
Expand Down Expand Up @@ -89,7 +90,7 @@ public void onRecyclerItemClick(RecyclerView.Adapter sender, Object object) {
(TrainStub) ((Bundle) object).getSerializable("train"),
(Station) ((Bundle) object).getSerializable("from"),
(Station) ((Bundle) object).getSerializable("to"),
(Date) ((Bundle) object).getSerializable("date"));
(DateTime) ((Bundle) object).getSerializable("date"));

} else if (object instanceof Transfer) {
i = LiveboardActivity.createIntent(RouteDetailActivity.this, ((Transfer) object).getStation());
Expand Down
Loading

0 comments on commit 1440a9f

Please sign in to comment.