Skip to content

Commit

Permalink
Merge pull request #57 from hyperrail/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Bertware authored Nov 9, 2017
2 parents bba1968 + b8f5b94 commit 7979ef5
Show file tree
Hide file tree
Showing 83 changed files with 799 additions and 222 deletions.
2 changes: 1 addition & 1 deletion Hyperrail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
}
}
compileSdkVersion 26
buildToolsVersion '26.0.0'
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "be.hyperrail.android"
minSdkVersion 19
Expand Down
15 changes: 13 additions & 2 deletions Hyperrail/src/main/java/be/hyperrail/android/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
Expand Down Expand Up @@ -55,6 +56,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On

private boolean mDualPane = false;

private final Handler mDrawerNavigationHandler = new Handler();

/**
* Create a new intent to open the main activity on the route page, with the 'to' field filled in.
*
Expand Down Expand Up @@ -169,7 +172,7 @@ protected void onSaveInstanceState(Bundle outState) {
* @param args The parameters for the fragment
*/
private void setView(int i, Bundle args) {
Fragment frg;
final Fragment frg;
switch (i) {
default:
case VIEW_TYPE_LIVEBOARD:
Expand All @@ -194,7 +197,15 @@ private void setView(int i, Bundle args) {
}
mCurrentFragment = frg;
mCurrentView = i;
getFragmentManager().beginTransaction().replace(R.id.activity_main_fragment_container, frg).commit();

mDrawerNavigationHandler.removeCallbacksAndMessages(null);
mDrawerNavigationHandler.postDelayed(new Runnable() {
@Override
public void run() {
getFragmentManager().beginTransaction().replace(R.id.activity_main_fragment_container, frg).commit();
}
},50);

}

@Override
Expand Down
42 changes: 39 additions & 3 deletions Hyperrail/src/main/java/be/hyperrail/android/OccupancyDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

package be.hyperrail.android;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.LinearLayout;

import org.joda.time.DateTime;

import be.hyperrail.android.irail.contracts.IRailErrorResponseListener;
import be.hyperrail.android.irail.contracts.IRailSuccessResponseListener;
import be.hyperrail.android.irail.contracts.IrailDataProvider;
import be.hyperrail.android.irail.contracts.OccupancyLevel;
import be.hyperrail.android.irail.factories.IrailFactory;
Expand All @@ -23,6 +27,7 @@
*/
public class OccupancyDialog {

private final View view;
private Context context;
private final String departureConnection;
private final String stationSemanticId;
Expand All @@ -35,6 +40,7 @@ public OccupancyDialog(Context context, TrainStop stop) {

public OccupancyDialog(Context context, String departureConnection, String stationSemanticId, String vehicleSemanticId, DateTime date) {
this.context = context;
this.view = ((Activity) context).getWindow().getDecorView().findViewById(android.R.id.content);
this.departureConnection = departureConnection;
this.stationSemanticId = stationSemanticId;
this.vehicleSemanticId = vehicleSemanticId;
Expand All @@ -61,7 +67,17 @@ public void onClick(View view) {
OccupancyDialog.this.vehicleSemanticId,
OccupancyDialog.this.date,
OccupancyLevel.LOW,
null, null, null);
new IRailSuccessResponseListener<Boolean>() {
@Override
public void onSuccessResponse(Boolean data, Object tag) {
Snackbar.make(OccupancyDialog.this.view, R.string.spitsgids_feedback_sent, Snackbar.LENGTH_LONG).show();
}
}, new IRailErrorResponseListener<Boolean>() {
@Override
public void onErrorResponse(Exception data, Object tag) {
Snackbar.make(OccupancyDialog.this.view, R.string.spitsgids_feedback_error, Snackbar.LENGTH_LONG).show();
}
}, null);
dialog.dismiss();
}
});
Expand All @@ -75,7 +91,17 @@ public void onClick(View view) {
OccupancyDialog.this.vehicleSemanticId,
OccupancyDialog.this.date,
OccupancyLevel.MEDIUM,
null, null, null);
new IRailSuccessResponseListener<Boolean>() {
@Override
public void onSuccessResponse(Boolean data, Object tag) {
Snackbar.make(OccupancyDialog.this.view, R.string.spitsgids_feedback_sent, Snackbar.LENGTH_LONG).show();
}
}, new IRailErrorResponseListener<Boolean>() {
@Override
public void onErrorResponse(Exception data, Object tag) {
Snackbar.make(OccupancyDialog.this.view, R.string.spitsgids_feedback_error, Snackbar.LENGTH_LONG).show();
}
}, null);
dialog.dismiss();
}
});
Expand All @@ -89,7 +115,17 @@ public void onClick(View view) {
OccupancyDialog.this.vehicleSemanticId,
OccupancyDialog.this.date,
OccupancyLevel.HIGH,
null, null, null);
new IRailSuccessResponseListener<Boolean>() {
@Override
public void onSuccessResponse(Boolean data, Object tag) {
Snackbar.make(OccupancyDialog.this.view, R.string.spitsgids_feedback_sent, Snackbar.LENGTH_LONG).show();
}
}, new IRailErrorResponseListener<Boolean>() {
@Override
public void onErrorResponse(Exception data, Object tag) {
Snackbar.make(OccupancyDialog.this.view, R.string.spitsgids_feedback_error, Snackbar.LENGTH_LONG).show();
}
}, null);
dialog.dismiss();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
Expand All @@ -40,6 +41,7 @@ public class RouteDetailActivity extends RecyclerViewActivity<Route> {
* The route to show
*/
private Route route;
private TextView vAlertsText;

public static Intent createIntent(Context c, Route r) {
Intent i = new Intent(c, RouteDetailActivity.class);
Expand All @@ -64,6 +66,24 @@ protected void onCreate(Bundle savedInstanceState) {
this.vRefreshLayout.setEnabled(false);

this.vWarningNotRealtime.setVisibility(View.GONE);

vAlertsText=findViewById(R.id.alert_message);
if (route.getAlerts() != null && route.getAlerts().length > 0) {
vAlertsText.setVisibility(View.VISIBLE);

StringBuilder text = new StringBuilder();
int n = route.getAlerts().length;
for (int i = 0; i < n; i++) {
text.append(route.getAlerts()[i].getDescription());
if (i < n - 1) {
text.append("\n");
}
}

vAlertsText.setText(text.toString());
} else {
vAlertsText.setVisibility(View.GONE);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ public void onBindItemViewHolder(RecyclerView.ViewHolder genericHolder, int posi
holder.vPlatform.setText("");
holder.vPlatformContainer.setBackground(ContextCompat.getDrawable(context, be.hyperrail.android.R.drawable.platform_train_canceled));
holder.vStatusText.setText(be.hyperrail.android.R.string.status_cancelled);
holder.vStatusContainer.setVisibility(View.VISIBLE);
holder.vOccupancy.setVisibility(View.GONE);
} else {
holder.vOccupancy.setVisibility(View.VISIBLE);
holder.vStatusContainer.setVisibility(View.GONE);
holder.vPlatformContainer.setBackground(ContextCompat.getDrawable(context, be.hyperrail.android.R.drawable.platform_train));
if (!stop.isPlatformNormal()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ public void onBindItemViewHolder(RecyclerView.ViewHolder genericHolder, int posi
holder.vPlatform.setText("");
holder.vPlatformContainer.setBackground(ContextCompat.getDrawable(context, R.drawable.platform_train_canceled));
holder.vStatusText.setText(R.string.status_cancelled);
holder.vStatusContainer.setVisibility(View.VISIBLE);
} else if (route.isPartiallyCanceled()){
holder.vPlatformContainer.setBackground(ContextCompat.getDrawable(context, R.drawable.platform_train));
holder.vStatusText.setText(R.string.status_partially_cancelled);
holder.vStatusContainer.setVisibility(View.VISIBLE);
} else {
holder.vStatusContainer.setVisibility(View.GONE);
holder.vPlatformContainer.setBackground(ContextCompat.getDrawable(context, R.drawable.platform_train));
Expand All @@ -219,6 +224,23 @@ public void onBindItemViewHolder(RecyclerView.ViewHolder genericHolder, int posi
drawable.setColorFilter(ContextCompat.getColor(context, R.color.colorDelay), PorterDuff.Mode.SRC_ATOP);
}

if (route.getAlerts() != null && route.getAlerts().length > 0) {
holder.vAlertsText.setVisibility(View.VISIBLE);

StringBuilder text = new StringBuilder();
int n = route.getAlerts().length;
for (int i = 0; i < n; i++) {
text.append(route.getAlerts()[i].getHeader());
if (i < n - 1) {
text.append("\n");
}
}

holder.vAlertsText.setText(text.toString());
} else {
holder.vAlertsText.setVisibility(View.GONE);
}

RouteDetailCardAdapter adapter = new RouteDetailCardAdapter(context, route, true);

// Launch intents to view details / click through
Expand Down Expand Up @@ -295,6 +317,7 @@ private class RouteViewHolder extends RecyclerView.ViewHolder {
protected final LinearLayout vDetailContainer;
protected final TextView vStatusText;
protected final LinearLayout vStatusContainer;
protected final TextView vAlertsText;

RouteViewHolder(View view) {
super(view);
Expand All @@ -319,6 +342,7 @@ private class RouteViewHolder extends RecyclerView.ViewHolder {

vStatusContainer = view.findViewById(R.id.layout_train_status_container);
vStatusText = view.findViewById(R.id.text_train_status);
vAlertsText = view.findViewById(R.id.alert_message);
}

}
Expand Down
Loading

0 comments on commit 7979ef5

Please sign in to comment.