style up widget and get intent initialized

This commit is contained in:
eleith 2017-03-04 00:16:00 -08:00
parent cc1a127acd
commit 6f498e7d36
12 changed files with 397 additions and 105 deletions

View File

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.eleith.calchoochoo">
package="com.eleith.calchoochoo">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application
android:name=".ChooChooApplication"
@ -14,9 +14,11 @@
android:theme="@style/CalChooChooTheme">
<activity android:name=".ChooChooActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
</intent-filter>
</activity>
<activity android:name=".ChooChooWidgetConfigure">
@ -24,19 +26,25 @@
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/GOOGLE_MAPS_API_KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/GOOGLE_MAPS_API_KEY"/>
<receiver
android:name="ChooChooWidgetProvider"
android:icon="@drawable/ic_cal_choo_choo"
android:label="Example Widget"
android:name="ChooChooWidgetProvider" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
android:label="Example Widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget" />
android:resource="@xml/widget"/>
</receiver>
</application>

View File

@ -1,13 +1,17 @@
package com.eleith.calchoochoo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.util.Pair;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.eleith.calchoochoo.dagger.ChooChooComponent;
import com.eleith.calchoochoo.dagger.ChooChooModule;
import com.eleith.calchoochoo.data.PossibleTrip;
import com.eleith.calchoochoo.data.Stop;
import com.eleith.calchoochoo.data.Trips;
import com.eleith.calchoochoo.utils.BundleKeys;
import com.eleith.calchoochoo.utils.DeviceLocation;
import com.eleith.calchoochoo.utils.RxBus;
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessage;
@ -19,6 +23,7 @@ import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageStop;
import com.google.android.gms.common.api.GoogleApiClient;
import org.joda.time.LocalDateTime;
import org.parceler.Parcels;
import javax.inject.Inject;
@ -44,6 +49,7 @@ public class ChooChooActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
chooChooComponent = ChooChooApplication.from(this).getAppComponent()
.activityComponent(new ChooChooModule(this));
chooChooComponent.inject(this);
@ -54,6 +60,21 @@ public class ChooChooActivity extends AppCompatActivity {
subscription = rxBus.observeEvents(RxMessage.class).subscribe(handleScheduleExplorerRxMessages());
if (intent != null) {
String action = intent.getAction();
Bundle bundle = intent.getExtras();
if (bundle != null) {
Trips trip = Parcels.unwrap(bundle.getParcelable(BundleKeys.TRIP));
Stop stop = Parcels.unwrap(bundle.getParcelable(BundleKeys.STOP));
int reason = bundle.getInt(BundleKeys.SEARCH_REASON);
if (action.equals(Intent.ACTION_VIEW) && trip != null && stop != null) {
chooChooFragmentManager.loadSearchForSpotFragment(reason, stop, trip);
return;
}
}
}
if (savedInstanceState == null) {
chooChooFragmentManager.loadMapSearchFragment();
}
@ -92,6 +113,7 @@ public class ChooChooActivity extends AppCompatActivity {
return new Action1<RxMessage>() {
@Override
public void call(RxMessage rxMessage) {
/*
if (rxMessage.isMessageValidFor(RxMessageKeys.SEARCH_RESULT_PAIR)) {
Pair<Stop, Integer> pair = ((RxMessagePairStopReason) rxMessage).getMessage();
if (pair.second.equals(RxMessagePairStopReason.SEARCH_REASON_DESTINATION)) {
@ -100,10 +122,10 @@ public class ChooChooActivity extends AppCompatActivity {
stopSource = pair.first;
}
chooChooFragmentManager.loadTripFilterFragment(stopMethod, stopDateTime, stopDestination, stopSource);
} else if (rxMessage.isMessageValidFor(RxMessageKeys.DESTINATION_SELECTED)) {
chooChooFragmentManager.loadSearchForSpotFragment(RxMessagePairStopReason.SEARCH_REASON_DESTINATION);
} else*/ if (rxMessage.isMessageValidFor(RxMessageKeys.DESTINATION_SELECTED)) {
chooChooFragmentManager.loadSearchForSpotFragment(RxMessagePairStopReason.SEARCH_REASON_DESTINATION, stopSource, stopDateTime);
} else if (rxMessage.isMessageValidFor(RxMessageKeys.SOURCE_SELECTED)) {
chooChooFragmentManager.loadSearchForSpotFragment(RxMessagePairStopReason.SEARCH_REASON_SOURCE);
chooChooFragmentManager.loadSearchForSpotFragment(RxMessagePairStopReason.SEARCH_REASON_SOURCE, stopDestination, stopDateTime);
} else if (rxMessage.isMessageValidFor(RxMessageKeys.SWITCH_SOURCE_DESTINATION_SELECTED)) {
Stop tempStop = stopDestination;
stopDestination = stopSource;

View File

@ -8,6 +8,7 @@ import android.support.v4.app.FragmentTransaction;
import com.eleith.calchoochoo.data.PossibleTrip;
import com.eleith.calchoochoo.data.Queries;
import com.eleith.calchoochoo.data.Stop;
import com.eleith.calchoochoo.data.Trips;
import com.eleith.calchoochoo.fragments.MapSearchFragment;
import com.eleith.calchoochoo.fragments.RouteStopsFragment;
import com.eleith.calchoochoo.fragments.SearchInputConfigureWidgetFragment;
@ -169,10 +170,18 @@ public class ChooChooFragmentManager {
}
}
public void loadSearchForSpotFragment(int reason) {
public void loadSearchForSpotFragment(int reason, Stop stop, LocalDateTime localDateTime) {
Bundle arguments = new Bundle();
ArrayList<Stop> stops = Queries.getAllStops();
arguments.putParcelable(BundleKeys.STOPS, Parcels.wrap(stops));
arguments.putInt(BundleKeys.SEARCH_REASON, reason);
arguments.putParcelable(BundleKeys.STOP, Parcels.wrap(stop));
arguments.putLong(BundleKeys.STOP_DATETIME, localDateTime.toDate().getTime());
setNextState(ChooChooFragmentManager.STATE_SEARCH_FOR_STOPS, arguments);
}
public void loadSearchForSpotFragment(int reason, Stop stop, Trips trip) {
Bundle arguments = new Bundle();
arguments.putParcelable(BundleKeys.STOP, Parcels.wrap(stop));
arguments.putParcelable(BundleKeys.TRIP, Parcels.wrap(trip));
arguments.putInt(BundleKeys.SEARCH_REASON, reason);
setNextState(ChooChooFragmentManager.STATE_SEARCH_FOR_STOPS, arguments);
}
@ -218,7 +227,7 @@ public class ChooChooFragmentManager {
}
if (stopSource != null && stopDestination != null && stopDateTime != null) {
ArrayList<PossibleTrip> possibleTrips = Queries.findTrips(stopSource, stopDestination, stopDateTime, stopMethod == RxMessageArrivalOrDepartDateTime.ARRIVING);
ArrayList<PossibleTrip> possibleTrips = Queries.findPossibleTrips(stopSource, stopDestination, stopDateTime, stopMethod == RxMessageArrivalOrDepartDateTime.ARRIVING);
arguments.putParcelable(BundleKeys.ROUTE_STOPS, Parcels.wrap(possibleTrips));
setNextState(ChooChooFragmentManager.STATE_SHOW_TRIP_FILTER_RESULTS, arguments);

View File

@ -8,7 +8,20 @@ import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews;
import com.eleith.calchoochoo.data.PossibleTrain;
import com.eleith.calchoochoo.data.Queries;
import com.eleith.calchoochoo.data.Routes;
import com.eleith.calchoochoo.data.Stop;
import com.eleith.calchoochoo.data.Trips;
import com.eleith.calchoochoo.utils.BundleKeys;
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessagePairStopReason;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.parceler.Parcels;
import java.util.ArrayList;
public class ChooChooWidgetProvider extends AppWidgetProvider {
@ -40,15 +53,52 @@ public class ChooChooWidgetProvider extends AppWidgetProvider {
}
public static void updateOneWidget(Context context, int appWidgetId, AppWidgetManager appWidgetManager) {
//Intent intent = new Intent(context, ChooChooActivity.class);
//PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Stop stop = ChooChooWidgetConfigure.getStopFromPreferences(context, appWidgetId);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.fragment_stop_card_widget);
appWidgetManager.updateAppWidget(appWidgetId, views);
if (stop != null) {
views.setTextViewText(R.id.stop_card_stop_name, stop.stop_name);
views.setTextViewText(R.id.stop_card_zone, Integer.toString(stop.zone_id));
ArrayList<PossibleTrain> possibleTrains = Queries.findNextTrain(stop, new LocalDateTime());
for (int i = 0; i < 3 && i < possibleTrains.size(); i++) {
PossibleTrain possibleTrain = possibleTrains.get(i);
Trips trip = Queries.getTripById(possibleTrain.getTripId());
Routes route = Queries.getRouteById(possibleTrain.getRouteId());
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("h:mma");
RemoteViews item = new RemoteViews(context.getPackageName(), R.layout.fragment_stop_card_widget_trainitem);
Intent intent = new Intent(context, ChooChooActivity.class);
Bundle bundle = new Bundle();
bundle.putParcelable(BundleKeys.TRIP, Parcels.wrap(trip));
bundle.putParcelable(BundleKeys.STOP, Parcels.wrap(stop));
bundle.putInt(BundleKeys.SEARCH_REASON, RxMessagePairStopReason.SEARCH_REASON_DESTINATION);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtras(bundle);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
if (trip != null) {
item.setTextViewText(R.id.stop_card_widget_trainitem_number, trip.trip_id);
if (trip.direction_id == 1) {
item.setTextViewText(R.id.stop_card_widget_direction, context.getString(R.string.south_bound));
} else {
item.setTextViewText(R.id.stop_card_widget_direction, context.getString(R.string.north_bound));
}
}
if (route != null && route.route_long_name.contains("Bullet")) {
item.setImageViewResource(R.id.stop_card_widget_trainitem_image, R.drawable.ic_train_bullet);
} else {
item.setImageViewResource(R.id.stop_card_widget_trainitem_image, R.drawable.ic_train_local);
}
item.setOnClickPendingIntent(R.id.stop_card_widget_train_item, pendingIntent);
item.setTextViewText(R.id.stop_card_widget_trainitem_time, dateTimeFormatter.print(possibleTrain.getDepartureTime()));
views.addView(R.id.stop_card_widget_train_items, item);
}
}
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}

View File

@ -0,0 +1,53 @@
package com.eleith.calchoochoo.data;
import org.joda.time.LocalTime;
import org.parceler.Parcel;
@Parcel
public class PossibleTrain {
private String stopId;
private LocalTime arrivalTime;
private LocalTime departureTime;
private String routeId;
private String tripId;
public String getTripId() {
return tripId;
}
public void setTripId(String tripId) {
this.tripId = tripId;
}
public String getStopId() {
return stopId;
}
public LocalTime getArrivalTime() {
return arrivalTime;
}
public String getRouteId() {
return routeId;
}
public void setStopId(String stopId) {
this.stopId = stopId;
}
public void setArrivalTime(LocalTime arrivalTime) {
this.arrivalTime = arrivalTime;
}
public void setRouteId(String routeId) {
this.routeId = routeId;
}
public LocalTime getDepartureTime() {
return departureTime;
}
public void setDepartureTime(LocalTime departureTime) {
this.departureTime = departureTime;
}
}

View File

@ -2,12 +2,14 @@ package com.eleith.calchoochoo.data;
import android.database.Cursor;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.raizlabs.android.dbflow.sql.language.SQLite;
import org.joda.time.DateTime;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
@ -62,6 +64,16 @@ public class Queries {
return null;
}
@Nullable
public static Trips getTripById(String trip_id) {
for (Trips trip : allTrips) {
if (trip.trip_id.equals(trip_id)) {
return trip;
}
}
return null;
}
@Nullable
public static Integer getZoneOfParentStop(String stop_id) {
for (Stop stop : allDirectionalStops) {
@ -124,8 +136,7 @@ public class Queries {
return exceptions.size() > 0;
}
public static ArrayList<PossibleTrip> findTrips(Stop source, Stop destination, LocalDateTime dateTime, Boolean arriving) {
ArrayList<PossibleTrip> possibleTrips = new ArrayList<>();
private static String getCalendarFilter(LocalDateTime dateTime) {
String calendarFilter;
int dayOfWeek = isExceptionDate(dateTime) ? 0 : dateTime.getDayOfWeek();
@ -153,6 +164,126 @@ public class Queries {
break;
}
return calendarFilter;
}
public static ArrayList<PossibleTrain> findNextTrain(Stop stop, LocalDateTime dateTime) {
ArrayList<PossibleTrain> possibleTrains = new ArrayList<>();
String calendarFilter = getCalendarFilter(dateTime);
String query = "SELECT " +
"routes.route_id as route_id, " +
"st1.platform_code as st1__platform_code, st1.trip_id as st1__trip_id, st1.arrival_time as st1__arrival_time, st1.departure_time as st1__departure_time, " +
"st1.stop_id as st1__stop_id, st1.stop_sequence as st1__stop_sequence " +
"FROM " +
" (SELECT * " +
" FROM stops, stop_times " +
" WHERE " +
" stop_times.stop_id = stops.stop_id " +
" AND stops.parent_station = ?) AS st1, " +
" trips, " +
" routes, " +
" calendar " +
"WHERE trips.trip_id = st1.trip_id " +
" AND trips.route_id = routes.route_id " +
" AND calendar.service_id = trips.service_id " +
calendarFilter +
"ORDER BY st1__departure_time DESC ";
String[] args = {stop.stop_id};
Cursor cursor = FlowManager.getDatabase(CaltrainDatabase.class).getWritableDatabase().rawQuery(query, args);
while (cursor.moveToNext()) {
PossibleTrain possibleTrain = new PossibleTrain();
String routeId = cursor.getString(cursor.getColumnIndex("route_id"));
String tripId = cursor.getString(cursor.getColumnIndex("st1__trip_id"));
String stopId = cursor.getString(cursor.getColumnIndex("st1__stop_id"));
LocalTime departureTime = new LocalTime(cursor.getString(cursor.getColumnIndex("st1__departure_time")).replaceFirst("^24:", "01:"));
LocalTime arrivalTime = new LocalTime(cursor.getString(cursor.getColumnIndex("st1__arrival_time")).replaceFirst("^24:", "01:"));
if (departureTime.isBefore(dateTime.toLocalTime()) && departureTime.plusHours(3).isAfter(dateTime.toLocalTime())) {
possibleTrain.setRouteId(routeId);
possibleTrain.setTripId(tripId);
possibleTrain.setStopId(stopId);
possibleTrain.setDepartureTime(departureTime);
possibleTrain.setArrivalTime(arrivalTime);
possibleTrains.add(possibleTrain);
}
}
return possibleTrains;
}
@Nullable
public static PossibleTrip findPossibleTrip(Stop source, Stop destination, String trip_id) {
PossibleTrip possibleTrip = new PossibleTrip();
String query = "SELECT " +
"routes.route_id as route_id, " +
"fare_attributes.price as price, " +
"st1.platform_code as st1__platform_code, st1.trip_id as st1__trip_id, st1.arrival_time as st1__arrival_time, st1.departure_time as st1__departure_time, " +
"st1.stop_id as st1__stop_id, st1.stop_sequence as st1__stop_sequence, " +
"st2.platform_code as st2__platform_code, st2.trip_id as st2__trip_id, st2.arrival_time as st2__arrival_time, st2.departure_time as st2__departure_time, " +
"st2.stop_id as st2__stop_id, st2.stop_sequence as st2__stop_sequence " +
"FROM " +
" (SELECT * " +
" FROM stop_times " +
" WHERE " +
" stop_times.stop_id = ?) AS st1, " +
" (Select * " +
" FROM stop_times " +
" WHERE " +
" stop_times.stop_id = ?) AS st2, " +
" trips, " +
" routes, " +
" calendar, " +
" fare_rules, " +
" fare_attributes " +
"WHERE st1.trip_id = st2.trip_id " +
" AND st1.platform_code = st2.platform_code " +
" AND trips.trip_id = ? " +
" AND trips.route_id = routes.route_id " +
" AND calendar.service_id = trips.service_id " +
" AND fare_rules.origin_id = st1.zone_id " +
" AND fare_rules.destination_id = st2.zone_id " +
" AND fare_rules.route_id = routes.route_id " +
" AND fare_rules.fare_id = fare_attributes.fare_id ";
String[] args = {source.stop_id, destination.stop_id, trip_id};
Cursor cursor = FlowManager.getDatabase(CaltrainDatabase.class).getWritableDatabase().rawQuery(query, args);
if (cursor.moveToFirst()) {
Float price = cursor.getFloat(cursor.getColumnIndex("price"));
String routeId = cursor.getString(cursor.getColumnIndex("route_id"));
String tripId = cursor.getString(cursor.getColumnIndex("st1__trip_id"));
String firstStopId = cursor.getString(cursor.getColumnIndex("st1__stop_id"));
String lastStopId = cursor.getString(cursor.getColumnIndex("st2__stop_id"));
Integer firstStopSequence = cursor.getInt(cursor.getColumnIndex("st1__stop_sequence"));
Integer secondStopSequence = cursor.getInt(cursor.getColumnIndex("st2__stop_sequence"));
LocalTime arrivalTime = new LocalTime(cursor.getString(cursor.getColumnIndex("st1__departure_time")).replaceFirst("^24:", "01:"));
LocalTime departureTime = new LocalTime(cursor.getString(cursor.getColumnIndex("st2__arrival_time")).replaceFirst("^24:", "01:"));
possibleTrip.setArrivalTime(arrivalTime);
possibleTrip.setDepartureTime(departureTime);
possibleTrip.setPrice(price);
possibleTrip.setFirstStopId(firstStopId);
possibleTrip.setLastStopId(lastStopId);
possibleTrip.setFirstStopSequence(firstStopSequence);
possibleTrip.setLastStopSequence(secondStopSequence);
possibleTrip.setTripId(tripId);
possibleTrip.setRouteId(routeId);
return possibleTrip;
}
return null;
}
public static ArrayList<PossibleTrip> findPossibleTrips(Stop source, Stop destination, LocalDateTime dateTime, Boolean arriving) {
ArrayList<PossibleTrip> possibleTrips = new ArrayList<>();
String calendarFilter = getCalendarFilter(dateTime);
String query = "SELECT " +
"routes.route_id as route_id, " +
"fare_attributes.price as price, " +
@ -186,7 +317,7 @@ public class Queries {
" AND fare_rules.destination_id = st2.zone_id " +
" AND fare_rules.route_id = routes.route_id " +
" AND fare_rules.fare_id = fare_attributes.fare_id " +
calendarFilter; // AND calendar.sunday = 1
calendarFilter;
String[] args = {source.stop_id, destination.stop_id};
Cursor cursor = FlowManager.getDatabase(CaltrainDatabase.class).getWritableDatabase().rawQuery(query, args);

View File

@ -14,18 +14,24 @@ import android.view.ViewGroup;
import android.widget.TextView;
import com.eleith.calchoochoo.ChooChooActivity;
import com.eleith.calchoochoo.ChooChooFragmentManager;
import com.eleith.calchoochoo.ChooChooWidgetConfigure;
import com.eleith.calchoochoo.R;
import com.eleith.calchoochoo.adapters.SearchResultsViewAdapter;
import com.eleith.calchoochoo.data.PossibleTrip;
import com.eleith.calchoochoo.data.Queries;
import com.eleith.calchoochoo.data.Stop;
import com.eleith.calchoochoo.data.Trips;
import com.eleith.calchoochoo.utils.BundleKeys;
import com.eleith.calchoochoo.utils.DeviceLocation;
import com.eleith.calchoochoo.utils.RxBus;
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessage;
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageKeys;
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessagePairStopReason;
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessagePossibleTrip;
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageString;
import org.joda.time.LocalDateTime;
import org.parceler.Parcels;
import java.util.ArrayList;
@ -41,6 +47,9 @@ import static com.eleith.calchoochoo.utils.StopUtils.filterByFuzzySearch;
public class SearchResultsFragment extends Fragment {
private ArrayList<Stop> stops;
private Stop otherStop;
private Long localDateTime;
private Trips trip;
private Subscription subscription;
private int searchReason;
@ -55,6 +64,8 @@ public class SearchResultsFragment extends Fragment {
SearchResultsViewAdapter searchResultsViewAdapter;
@Inject
DeviceLocation deviceLocation;
@Inject
ChooChooFragmentManager chooChooFragmentManager;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -63,6 +74,7 @@ public class SearchResultsFragment extends Fragment {
if (activity instanceof ChooChooActivity) {
((ChooChooActivity) activity).getComponent().inject(this);
}
stops = Queries.getAllStops();
unPackBundle(savedInstanceState != null ? savedInstanceState : getArguments());
}
@ -103,7 +115,9 @@ public class SearchResultsFragment extends Fragment {
private void unPackBundle(Bundle bundle) {
if (bundle != null) {
stops = Parcels.unwrap(bundle.getParcelable(BundleKeys.STOPS));
localDateTime = bundle.getLong(BundleKeys.STOP_DATETIME);
otherStop = Parcels.unwrap(bundle.getParcelable(BundleKeys.STOP));
trip = Parcels.unwrap(bundle.getParcelable(BundleKeys.TRIP));
searchReason = bundle.getInt(BundleKeys.SEARCH_REASON);
}
}
@ -115,7 +129,22 @@ public class SearchResultsFragment extends Fragment {
if (rxMessage.isMessageValidFor(RxMessageKeys.SEARCH_RESULT_STOP)) {
Stop stop = (Stop) rxMessage.getMessage();
Pair<Stop, Integer> pair = new Pair<>(stop, searchReason);
rxBus.send(new RxMessagePairStopReason(RxMessageKeys.SEARCH_RESULT_PAIR, pair));
if (trip != null) {
if (searchReason == RxMessagePairStopReason.SEARCH_REASON_DESTINATION) {
PossibleTrip possibleTrip = Queries.findPossibleTrip(otherStop, stop, trip.trip_id);
chooChooFragmentManager.loadTripDetailsFragments(possibleTrip, stop, otherStop);
} else {
PossibleTrip possibleTrip = Queries.findPossibleTrip(stop, otherStop, trip.trip_id);
chooChooFragmentManager.loadTripDetailsFragments(possibleTrip, otherStop, stop);
}
} else {
//rxBus.send(new RxMessagePairStopReason(RxMessageKeys.SEARCH_RESULT_PAIR, pair));
if (searchReason == RxMessagePairStopReason.SEARCH_REASON_DESTINATION) {
chooChooFragmentManager.loadTripFilterFragment(searchReason, new LocalDateTime(localDateTime), stop, otherStop);
} else {
chooChooFragmentManager.loadTripFilterFragment(searchReason, new LocalDateTime(localDateTime), otherStop, stop);
}
}
} else if (rxMessage.isMessageValidFor(RxMessageKeys.SEARCH_INPUT_STRING)) {
String filterString = ((RxMessageString) rxMessage).getMessage();
filterResultsBy(filterString);

View File

@ -11,4 +11,5 @@ public class BundleKeys {
public static final String STOP_DATETIME = "stop_datetime";
public static final String ROUTE_STOPS = "route_stops";
public static final String POSSIBLE_TRIP = "possible_trip";
public static final String TRIP = "trip";
}

View File

@ -4,93 +4,26 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#aa0000"
android:background="@color/primary_material_light"
android:orientation="vertical">
<TextView
android:id="@+id/stop_card_stop_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="38dp"
android:gravity="center|start"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:paddingTop="10dp"
android:textColor="@color/cardview_light_background"
android:textSize="22sp"
android:textColor="#ffffff"
tools:text="name"
tools:text="Mountain View Caltrain"
/>
<LinearLayout
android:id="@+id/stop_card_widget_train_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:paddingTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/zone"
android:textSize="14sp"
android:textColor="#ffffff"
/>
<TextView
android:id="@+id/stop_card_zone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="#ffffff"
tools:text="5"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:padding="10dp">
<TextView
android:id="@+id/stop_card_go_to"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_marginEnd="20dp"
android:text="@string/go_to"
android:textColor="#ffffff"
android:textSize="16sp"
/>
<TextView
android:id="@+id/stop_card_leave_from"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_toEndOf="@id/stop_card_go_to"
android:layout_toStartOf="@id/stop_card_map_to"
android:text="@string/leave_from"
android:textColor="#ffffff"
android:textSize="16sp"
/>
<ImageView
android:id="@+id/stop_card_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:contentDescription="@string/link"
android:src="@drawable/ic_link_black_24dp"/>
<ImageView
android:id="@+id/stop_card_map_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:layout_toStartOf="@id/stop_card_link"
android:contentDescription="@string/map_link"
android:src="@drawable/ic_room_black_24dp"/>
</RelativeLayout>
android:layout_height="match_parent"
android:background="@color/cardview_light_background"
android:orientation="vertical"/>
</LinearLayout>

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/stop_card_widget_train_item"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/stop_card_widget_trainitem_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginEnd="5dp"
android:layout_marginStart="10dp"
android:contentDescription="@string/local_train"
android:src="@drawable/ic_train_bullet"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center|start"
android:text="@string/number_sign"
android:textSize="18sp"/>
<TextView
android:id="@+id/stop_card_widget_trainitem_number"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center|start"
android:layout_marginEnd="3dp"
android:textSize="18sp"
tools:text="123"/>
<TextView
android:id="@+id/stop_card_widget_direction"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="3dp"
android:gravity="center|start"
android:textSize="18sp"
tools:text="(South)"/>
<TextView
android:id="@+id/stop_card_widget_trainitem_time"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:gravity="center|end"
android:textSize="18sp"
tools:text="8:00 pm"/>
</LinearLayout>

View File

@ -25,4 +25,7 @@
<string name="local_train">Local Train</string>
<string name="train_number">Train #</string>
<string name="no_more_trains">Sorry, there are no more trips at this time.</string>
<string name="south_bound">(South)</string>
<string name="north_bound">(North)</string>
<string name="number_sign">#</string>
</resources>