Skip to content

Commit

Permalink
Fix platform and some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeemakr committed Sep 12, 2017
1 parent fb7c447 commit 29dbc1a
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
mLocationResultAdapter = new StationListAdapter(this);
mLocationResultAdapter.setOnStationClickListener(new StationListAdapter.OnStationClickListener() {
@Override
public void onStationClicked(Location location) {
onLocationSelected(location);
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/ch/unstable/ost/ConnectionListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void onBindViewHolder(ConnectionViewHolder holder, int position) {
Section section = sections[0];
holder.firstEndDestination.setText(formatEndDestination(context, section.getHeadsign()));
holder.firstTransportName.setText(section.getLineShortName());
Log.d(TAG, "Binding departure plattform: " + section.getDeparturePlatform());
holder.platform.setText(formatPlatform(context, section.getDeparturePlatform()));
} else {
Log.e(TAG, "No sections");
Expand All @@ -234,8 +235,9 @@ public void onBindViewHolder(ConnectionViewHolder holder, int position) {

@Nullable
private String formatPlatform(Context context, @Nullable String platform) {
if (platform == null) return null;
if (platform.matches("^[0-9]+$")) {
if (platform == null) {
return null;
} else if (platform.matches("^[0-9]+$")) {
return context.getString(R.string.format_train_platform, platform);
} else if (platform.matches("^[A-z]+$")) {
return context.getString(R.string.format_bus_platform, platform);
Expand Down Expand Up @@ -363,7 +365,7 @@ public void onClick(View v) {
}
}

private class ProgressViewHolder extends RecyclerView.ViewHolder {
private static class ProgressViewHolder extends RecyclerView.ViewHolder {
private final View progressBar;

public ProgressViewHolder(View itemView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public boolean handleMessage(Message msg) {
break;
case MESSAGE_QUERY_CONNECTION_PAGE:
handleConnectionQuery((ConnectionQuery) msg.obj, msg.arg1);
break;
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
if (mSelectionState == null) {
mSelectionState = new SelectionState();
}
mSelectionState.getChangeObservable()
Disposable disposable = mSelectionState.getChangeObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getSelectionStateObserver());
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ch/unstable/ost/OSTApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ public class OSTApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
CaocConfig.Builder.create()
/*CaocConfig.Builder.create()
.errorActivity(ErrorReportActivity.class)
.apply();
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ViewHolder(View itemView) {
}
}

private class StopsListAdapter extends RecyclerView.Adapter<ViewHolder> {
private static class StopsListAdapter extends RecyclerView.Adapter<ViewHolder> {
private PassingCheckpoint[] stops;

public void setStops(PassingCheckpoint[] stops) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.unstable.ost.api.base;


import android.os.Build;
import android.util.Log;

import com.google.gson.Gson;
Expand All @@ -12,10 +13,12 @@
import java.lang.reflect.Type;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.logging.Level;
import java.util.logging.Logger;

import ch.unstable.ost.BuildConfig;
import ch.unstable.ost.utils.StandartCharsetCompat;


public class BaseHttpJsonAPI {
Expand Down Expand Up @@ -51,9 +54,10 @@ private InputStreamReader open(URL url) throws IOException {
if (code == HTTP_CODE_TOO_MANY_REQUESTS) {
throw new TooManyRequestsException();
}
return new InputStreamReader(urlConnection.getInputStream());
return new InputStreamReader(urlConnection.getInputStream(), StandartCharsetCompat.UTF_8);
}

@SuppressWarnings("TypeParameterUnusedInFormals")
protected <T> T loadJson(URL url, Type typeOfT) throws IOException {
InputStreamReader inputStreamReader = open(url);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

public class ConnectionQuery implements Parcelable {
public static final Parcelable.Creator<ConnectionQuery> CREATOR = new Parcelable.Creator<ConnectionQuery>() {

@Override
public ConnectionQuery createFromParcel(Parcel in) {
return new ConnectionQuery(in);
}

@Override
public ConnectionQuery[] newArray(int size) {
return new ConnectionQuery[size];
}
Expand Down Expand Up @@ -130,7 +133,7 @@ public Builder() {
@NonNull
@CanIgnoreReturnValue
public Builder setVia(@Nullable String... via) {
if (via == null || via.length == 1 && via[0] == null) {
if (via == null || (via.length == 1 && via[0] == null)) {
this.via.clear();
} else {
this.via = new ArrayList<>(Arrays.asList(via));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.unstable.ost.api.offline;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -29,6 +30,7 @@ private static String getFullQuery(String query) {
return fullQuery.toString();
}

@Override
public Location[] getStationsByQuery(String query) {
return getStationsByQuery(getFullQuery(query), 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ public enum DepartureCheckpointDeserializer implements JsonDeserializer<Departur

@Nullable
public static String getPlatform(JsonObject object) {
if (object.has(FIELD_PLATFORM)) return null;
JsonElement platform = object.get(FIELD_PLATFORM);
if (platform.isJsonNull()) {
if (!object.has(FIELD_PLATFORM)) {
return null;
} else {
}
JsonElement platform = object.get(FIELD_PLATFORM);
if (!platform.isJsonNull()) {
return platform.getAsString().trim();
}
return null;
}

@NonNull
Expand All @@ -47,6 +48,7 @@ public DepartureCheckpoint deserialize(JsonElement json, Type typeOfT, JsonDeser

Date departure = getDate(passObj, FIELD_DEPARTURE_TIMESTAMP);
String platform = getPlatform(passObj);
Log.d(TAG, "departure platform: " + platform);
return new DepartureCheckpoint(departure, platform, location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ private static class AndroidVersionViewHolder {
}
}

private class BuildInfoViewHolder {
private static class BuildInfoViewHolder {
private final TextView buildId;

public BuildInfoViewHolder(Activity activity) {
this.buildId = (TextView) activity.findViewById(R.id.appBuildId);
}
}

private class AppInfoViewHolder {
private static class AppInfoViewHolder {
private final TextView appVersion;
private final TextView appPackage;
private final TextView appSignature;
Expand All @@ -185,7 +185,7 @@ public AppInfoViewHolder(Activity activity) {
}
}

private class ErrorViewHolder {
private static class ErrorViewHolder {
private final TextView errorStackTrace;

public ErrorViewHolder(Activity activity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static StationsDAO createStationDAO(final Context context) {

try {
Class<?> clazz = Class.forName(preference);
StationDAOFactory daoFactory = (StationDAOFactory) clazz.newInstance();
StationDAOFactory daoFactory = (StationDAOFactory) clazz.getDeclaredConstructor().newInstance();
return daoFactory.getStationsDAO(context);
} catch (Exception e) {
throw new IllegalStateException("Couldn't get factory for StationsDAO", e);
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/ch/unstable/ost/utils/StandartCharsetCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ch.unstable.ost.utils;

import java.nio.charset.Charset;

/**
* Created by coffeemakr on 12.09.17.
*/

public class StandartCharsetCompat {
public static final Charset UTF_8 = Charset.forName("UTF-8");
}

0 comments on commit 29dbc1a

Please sign in to comment.