use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.Departure in project TumCampusApp by TCA-Team.
the class MVVCard method updateViewHolder.
@Override
public void updateViewHolder(RecyclerView.ViewHolder viewHolder) {
super.updateViewHolder(viewHolder);
mCard = viewHolder.itemView;
mLinearLayout = mCard.findViewById(R.id.card_view);
mTitleView = mCard.findViewById(R.id.card_title);
mTitleView.setText(mStationNameIDPair.first);
mCard.findViewById(R.id.place_holder).setVisibility(View.VISIBLE);
// Remove old DepartureViews
for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
if (mLinearLayout.getChildAt(i) instanceof DepartureView) {
mLinearLayout.removeViewAt(i);
// Check the same location again, since the childCount changed
i--;
}
}
// Fetch transport favorites, can only be updated in the detailed view
TransportController transportManager = new TransportController(mContext);
for (int i = 0; i < mDepartures.size() && i < 5; i++) {
Departure curr = mDepartures.get(i);
DepartureView view = new DepartureView(mContext);
if (transportManager.isFavorite(curr.getSymbol())) {
view.setSymbol(curr.getSymbol(), true);
} else {
view.setSymbol(curr.getSymbol(), false);
}
view.setLine(curr.getDirection());
view.setTime(curr.getDepartureTime());
mLinearLayout.addView(view);
}
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.Departure in project TumCampusApp by TCA-Team.
the class MVVCard method fillNotification.
@Override
protected Notification fillNotification(NotificationCompat.Builder notificationBuilder) {
NotificationCompat.WearableExtender morePageNotification = new NotificationCompat.WearableExtender();
String firstContent = "";
String firstTime = "";
for (Departure d : mDepartures) {
if (firstTime.isEmpty()) {
firstTime = d.getCountDown() + "min";
firstContent = d.getServingLine() + " " + d.getDirection();
}
NotificationCompat.Builder pageNotification = new NotificationCompat.Builder(mContext, Const.NOTIFICATION_CHANNEL_MVV).setContentTitle(d.getCountDown() + "min").setSmallIcon(R.drawable.ic_notification).setLargeIcon(Utils.getLargeIcon(mContext, R.drawable.ic_mvv)).setContentText(d.getServingLine() + " " + d.getDirection());
morePageNotification.addPage(pageNotification.build());
}
notificationBuilder.setContentTitle(firstTime);
notificationBuilder.setContentText(firstContent);
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.wear_mvv);
morePageNotification.setBackground(bm);
return morePageNotification.extend(notificationBuilder).build();
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.Departure in project TumCampusApp by TCA-Team.
the class TransportController method getDeparturesFromExternal.
/**
* Get all departures for a station.
*
* @param stationID Station ID, station name might or might not work
* @return List of departures
*/
public static List<Departure> getDeparturesFromExternal(Context context, String stationID) {
List<Departure> result = new ArrayList<>();
try {
String language = LANGUAGE + Locale.getDefault().getLanguage();
// ISO-8859-1 is needed for mvv
String departureQuery = DEPARTURE_QUERY_STATION + UrlEscapers.urlPathSegmentEscaper().escape(stationID);
String query = DEPARTURE_QUERY_CONST + language + '&' + departureQuery;
Utils.logv(query);
NetUtils net = new NetUtils(context);
// Download departures
Optional<JSONObject> departures = net.downloadJson(query);
if (!departures.isPresent()) {
return result;
}
if (departures.get().isNull("departureList")) {
return result;
}
JSONArray arr = departures.get().getJSONArray("departureList");
for (int i = 0; i < arr.length(); i++) {
JSONObject departure = arr.getJSONObject(i);
JSONObject servingLine = departure.getJSONObject("servingLine");
JSONObject time = departure.getJSONObject("dateTime");
Date date = new GregorianCalendar(time.getInt("year"), time.getInt("month") - 1, time.getInt("day"), time.getInt("hour"), time.getInt("minute")).getTime();
result.add(new Departure(servingLine.getString("name"), servingLine.getString("direction"), // Limit symbol length to 3, longer symbols are pointless
String.format("%3.3s", servingLine.getString("symbol")).trim(), departure.getInt("countdown"), date.getTime()));
}
Collections.sort(result, (lhs, rhs) -> lhs.getCountDown() - rhs.getCountDown());
} catch (JSONException e) {
// We got no valid JSON, mvg-live is probably bugged
Utils.log(e, ERROR_INVALID_JSON + DEPARTURE_QUERY);
}
return result;
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.Departure in project TumCampusApp by TCA-Team.
the class TransportController method onRequestCard.
/**
* Inserts a MVV card for the nearest public transport station
*
* @param context Context
*/
@Override
public void onRequestCard(Context context) {
if (!NetUtils.isConnected(context)) {
return;
}
// Get station for current campus
LocationManager locMan = new LocationManager(context);
StationResult station = locMan.getStation();
if (station == null) {
return;
}
List<Departure> cur = getDeparturesFromExternal(context, station.getId());
MVVCard card = new MVVCard(context);
card.setStation(station);
card.setDepartures(cur);
card.apply();
}
use of de.tum.in.tumcampusapp.component.ui.transportation.model.efa.Departure in project TumCampusApp by TCA-Team.
the class TransportationDetailsActivity method onLoadFinished.
/**
* Adds a new {@link DepartureView} for each departure entry
*
* @param result List of departures
*/
@Override
protected void onLoadFinished(List<Departure> result) {
showLoadingEnded();
if (result == null) {
return;
}
mViewResults.removeAllViews();
for (Departure d : result) {
DepartureView view = new DepartureView(this, true);
view.setOnClickListener(v -> {
DepartureView departureView = (DepartureView) v;
String symbol = departureView.getSymbol();
boolean highlight;
if (transportManager.isFavorite(symbol)) {
transportManager.deleteFavorite(symbol);
highlight = false;
} else {
transportManager.addFavorite(symbol);
highlight = true;
}
// Update the other views with the same symbol
for (int i = 0; i < mViewResults.getChildCount(); i++) {
DepartureView child = (DepartureView) mViewResults.getChildAt(i);
if (child.getSymbol().equals(symbol)) {
child.setSymbol(symbol, highlight);
}
}
});
if (transportManager.isFavorite(d.getSymbol())) {
view.setSymbol(d.getSymbol(), true);
} else {
view.setSymbol(d.getSymbol(), false);
}
view.setLine(d.getDirection());
view.setTime(d.getDepartureTime());
mViewResults.addView(view);
}
}
Aggregations