use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.StationResult in project TumCampusApp by TCA-Team.
the class TransportController method getStationsFromExternal.
/**
* Find stations by station name prefix
*
* @param prefix Name prefix
* @return List of StationResult
*/
public static List<StationResult> getStationsFromExternal(Context context, String prefix) {
prefix = Utils.escapeUmlauts(prefix);
try {
String language = LANGUAGE + Locale.getDefault().getLanguage();
// ISO-8859-1 is needed for mvv
String stationQuery = STATION_SEARCH_QUERY + UrlEscapers.urlPathSegmentEscaper().escape(prefix);
String query = STATION_SEARCH_CONST + language + '&' + stationQuery;
Utils.log(query);
NetUtils net = new NetUtils(context);
// Download possible stations
Optional<JSONObject> jsonObj = net.downloadJsonObject(query, CacheManager.VALIDITY_DO_NOT_CACHE, true);
if (!jsonObj.isPresent()) {
return Collections.emptyList();
}
List<StationResult> results = new ArrayList<>();
JSONObject stopfinder = jsonObj.get().getJSONObject("stopFinder");
// Possible values for points: Object, Array or null
JSONArray pointsArray = stopfinder.optJSONArray(POINTS);
if (pointsArray == null) {
JSONObject points = stopfinder.optJSONObject(POINTS);
if (points == null) {
return Collections.emptyList();
}
JSONObject point = points.getJSONObject("point");
addStationResult(results, point);
} else {
for (int i = 0; i < pointsArray.length(); i++) {
JSONObject point = pointsArray.getJSONObject(i);
addStationResult(results, point);
}
}
// Sort by quality
Collections.sort(results, (lhs, rhs) -> rhs.getQuality() - lhs.getQuality());
return results;
} catch (JSONException e) {
Utils.log(e, ERROR_INVALID_JSON + STATION_SEARCH);
}
return Collections.emptyList();
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.StationResult in project TumCampusApp by TCA-Team.
the class TransportationActivity method onItemClick.
/**
* Click on station in list
*/
@Override
public void onItemClick(final AdapterView<?> av, View v, int position, long id) {
StationResult stationResult = (StationResult) av.getAdapter().getItem(position);
showStation(stationResult);
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.StationResult in project TumCampusApp by TCA-Team.
the class MVVWidgetConfigureActivity method onSearchFinished.
/**
* Shows the stations
*
* @param possibleStationList list of possible StationResult
*/
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@Override
protected void onSearchFinished(Optional<List<StationResult>> possibleStationList) {
if (!possibleStationList.isPresent()) {
return;
}
List<StationResult> stationResultList = possibleStationList.get();
showLoadingEnded();
// mQuery is not null if it was a real search
if (stationResultList.isEmpty()) {
// So show no results found
listViewResults.setAdapter(new NoResultsAdapter(this));
listViewResults.requestFocus();
return;
}
adapterStations.clear();
adapterStations.addAll(stationResultList);
adapterStations.notifyDataSetChanged();
listViewResults.setAdapter(adapterStations);
listViewResults.requestFocus();
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.StationResult in project TumCampusApp by TCA-Team.
the class MVVWidgetConfigureActivity method onItemClick.
/**
* Click on station in list
*/
@Override
public void onItemClick(final AdapterView<?> av, View v, int position, long id) {
StationResult stationResult = (StationResult) av.getAdapter().getItem(position);
widgetDepartures.setStation(stationResult.getStation());
widgetDepartures.setStationId(stationResult.getId());
saveAndReturn();
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.StationResult in project TumCampusApp by TCA-Team.
the class TransportController method addStationResult.
private static void addStationResult(Collection<StationResult> results, JSONObject point) throws JSONException {
String name = point.getString("name");
String id = point.getJSONObject("ref").getString("id");
int quality = point.getInt("quality");
results.add(new StationResult(name, id, quality));
}
Aggregations