update trip query, onclick for possible trips
This commit is contained in:
parent
596be1cb2d
commit
4faa85d07e
|
@ -1,5 +1,6 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/gradle.properties
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
|
|
|
@ -11,6 +11,8 @@ android {
|
|||
targetSdkVersion 23
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
resValue "string", "GOOGLE_MAPS_API_KEY", GOOGLE_MAPS_API_KEY
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
@ -31,6 +33,9 @@ dependencies {
|
|||
compile 'com.android.support:recyclerview-v7:23.4.0'
|
||||
compile "com.android.support:design:23.4.0"
|
||||
|
||||
// google maps library
|
||||
compile 'com.google.android.gms:play-services:10.0.1'
|
||||
|
||||
// time library
|
||||
compile 'joda-time:joda-time:2.9.7'
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</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" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,6 +1,7 @@
|
|||
package com.eleith.calchoochoo;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -10,17 +11,23 @@ import com.eleith.calchoochoo.data.PossibleTrip;
|
|||
import com.eleith.calchoochoo.data.Queries;
|
||||
import com.eleith.calchoochoo.data.Routes;
|
||||
import com.eleith.calchoochoo.utils.RxBus;
|
||||
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageKeys;
|
||||
import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageString;
|
||||
|
||||
import org.joda.time.Minutes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class RouteViewAdapter extends RecyclerView.Adapter<RouteViewAdapter.RouteViewHolder> {
|
||||
private ArrayList<PossibleTrip> possibleTrips;
|
||||
private RxBus rxBus;
|
||||
|
||||
public RouteViewAdapter(RxBus rxBus) {
|
||||
|
||||
this.rxBus = rxBus;
|
||||
}
|
||||
|
||||
public void setPossibleTrips(ArrayList<PossibleTrip> possibleTrips) {
|
||||
|
@ -65,8 +72,16 @@ public class RouteViewAdapter extends RecyclerView.Adapter<RouteViewAdapter.Rout
|
|||
TextView tripRouteName;
|
||||
TextView tripNumber;
|
||||
|
||||
@OnClick(R.id.trip_summary_detail)
|
||||
void onClickTripSummary() {
|
||||
rxBus.send(new RxMessageString(RxMessageKeys.TRIP_SELECTED, possibleTrips.get(getAdapterPosition()).getTripId()));
|
||||
}
|
||||
|
||||
private RouteViewHolder(View v) {
|
||||
super(v);
|
||||
|
||||
ButterKnife.bind(this, v);
|
||||
|
||||
arrivalTime = (TextView) v.findViewById(R.id.trip_stop_start_time);
|
||||
departureTime = (TextView) v.findViewById(R.id.trip_stop_end_time);
|
||||
tripPrice = (TextView) v.findViewById(R.id.trip_price);
|
||||
|
|
|
@ -23,6 +23,9 @@ import com.eleith.calchoochoo.fragments.FragmentRouteStops;
|
|||
import com.eleith.calchoochoo.fragments.HomeFragment;
|
||||
import com.eleith.calchoochoo.fragments.SearchInputFragment;
|
||||
import com.eleith.calchoochoo.fragments.SearchResultsFragment;
|
||||
import com.eleith.calchoochoo.fragments.StopSummaryFragment;
|
||||
import com.eleith.calchoochoo.fragments.TripDetailFragment;
|
||||
import com.eleith.calchoochoo.fragments.TripSummaryFragment;
|
||||
import com.eleith.calchoochoo.utils.BundleKeys;
|
||||
import com.eleith.calchoochoo.utils.Permissions;
|
||||
import com.eleith.calchoochoo.utils.RxBus;
|
||||
|
@ -105,6 +108,15 @@ public class ScheduleExplorerActivity extends AppCompatActivity {
|
|||
stopDateTime = pair.second;
|
||||
updateDestinationSourceFragment();
|
||||
updateRouteFragment();
|
||||
} else if(rxMessage.isMessageValidFor(RxMessageKeys.DATE_TIME_SELECTED)) {
|
||||
Pair<Integer, LocalDateTime> pair = ((RxMessageArrivalOrDepartDateTime) rxMessage).getMessage();
|
||||
stopMethod = pair.first;
|
||||
stopDateTime = pair.second;
|
||||
updateDestinationSourceFragment();
|
||||
updateRouteFragment();
|
||||
} else if (rxMessage.isMessageValidFor(RxMessageKeys.TRIP_SELECTED)) {
|
||||
String tripId = ((RxMessageString) rxMessage).getMessage();
|
||||
showTripDetailsFragments(tripId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -144,6 +156,22 @@ public class ScheduleExplorerActivity extends AppCompatActivity {
|
|||
updateTopBottomFragments(searchInputFragment, searchResultsFragment);
|
||||
}
|
||||
|
||||
private void showTripDetailsFragments(String tripId) {
|
||||
Bundle tripSummaryArgs = new Bundle();
|
||||
|
||||
TripSummaryFragment tripSummaryFragment = new TripSummaryFragment();
|
||||
TripDetailFragment tripDetailFragment = new TripDetailFragment();
|
||||
|
||||
tripSummaryArgs.putString(BundleKeys.TRIP_ID, tripId);
|
||||
tripSummaryArgs.putParcelable(BundleKeys.STOP_DESTINATION, Parcels.wrap(stopDestination));
|
||||
tripSummaryArgs.putParcelable(BundleKeys.STOP_SOURCE, Parcels.wrap(stopSource));
|
||||
|
||||
tripSummaryFragment.setArguments(tripSummaryArgs);
|
||||
tripDetailFragment.setArguments(tripSummaryArgs);
|
||||
|
||||
updateTopBottomFragments(tripSummaryFragment, tripDetailFragment);
|
||||
}
|
||||
|
||||
private void updateDestinationSourceFragment() {
|
||||
Bundle destinationSourceArgs = new Bundle();
|
||||
DestinationSourceFragment destinationSourceFragment = new DestinationSourceFragment();
|
||||
|
|
|
@ -6,6 +6,9 @@ import com.eleith.calchoochoo.fragments.DestinationSourceFragment;
|
|||
import com.eleith.calchoochoo.fragments.FragmentRouteStops;
|
||||
import com.eleith.calchoochoo.fragments.SearchInputFragment;
|
||||
import com.eleith.calchoochoo.fragments.SearchResultsFragment;
|
||||
import com.eleith.calchoochoo.fragments.StopSummaryFragment;
|
||||
import com.eleith.calchoochoo.fragments.TripDetailFragment;
|
||||
import com.eleith.calchoochoo.fragments.TripSummaryFragment;
|
||||
|
||||
import dagger.Subcomponent;
|
||||
|
||||
|
@ -21,4 +24,7 @@ public interface ScheduleExplorerActivityComponent {
|
|||
void inject(SearchInputFragment searchInputFragment);
|
||||
void inject(DestinationSourceFragment destinationSourceFragment);
|
||||
void inject(DepartingArrivingDialogFragment departingArrivingDialogFragment);
|
||||
void inject(StopSummaryFragment stopSummaryFragment);
|
||||
void inject(TripSummaryFragment tripSummaryFragment);
|
||||
void inject(TripDetailFragment tripDetailFragment);
|
||||
}
|
||||
|
|
|
@ -180,14 +180,14 @@ public class Queries {
|
|||
public static ArrayList<Pair<Stop, StopTimes>> findTripDetails(String trip_id) {
|
||||
ArrayList<Pair<Stop, StopTimes>> stopAndTimes = new ArrayList<>();
|
||||
|
||||
String query = "SELECT * " +
|
||||
String query = "SELECT " +
|
||||
" st.trip_id as st__trip_id, st.arrival_time as st__arrival_time, st.departure_time as st__departure_time, " +
|
||||
" st.stop_id as st__stop_id, st.stop_sequence as st__stop_sequence, st.pickup_time as st__pickup_time, st.drop_off_type as st__drop_off_type, " +
|
||||
" s.stop_id as s__stop_id, s.stop_name as s__stop_name, s.stop_lat as s__stop_lat, s.stop_lon as s__stop_lon, " +
|
||||
" s.stop_url as s__stop_url, s.platform_code as s__platform_code, s.stop_code as s__stop_code " +
|
||||
"FROM stops as s, stop_times as st " +
|
||||
"WHERE stop_times.trip_id = ? " +
|
||||
" AND stops.stop_id = stop_times.stop_id " +
|
||||
"WHERE st.trip_id = ? " +
|
||||
" AND s.stop_id = st.stop_id " +
|
||||
" ORDER BY st.stop_sequence";
|
||||
|
||||
String[] args = {trip_id};
|
||||
|
|
|
@ -96,17 +96,17 @@ public class DestinationSourceFragment extends Fragment {
|
|||
}
|
||||
|
||||
@OnClick(R.id.destinationEdit)
|
||||
public void destinationClick() {
|
||||
void destinationClick() {
|
||||
rxBus.send(new RxMessage(RxMessageKeys.DESTINATION_SELECTED));
|
||||
}
|
||||
|
||||
@OnClick(R.id.sourceEdit)
|
||||
public void sourceClick() {
|
||||
void sourceClick() {
|
||||
rxBus.send(new RxMessage(RxMessageKeys.SOURCE_SELECTED));
|
||||
}
|
||||
|
||||
@OnClick(R.id.timeEdit)
|
||||
public void timeClick() {
|
||||
void timeClick() {
|
||||
DepartingArrivingDialogFragment dialog = new DepartingArrivingDialogFragment();
|
||||
dialog.show(getFragmentManager(), "dialog");
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import javax.inject.Inject;
|
|||
import rx.Subscription;
|
||||
|
||||
public class FragmentRouteStops extends Fragment {
|
||||
private Subscription subscription;
|
||||
private ArrayList<PossibleTrip> possibleTrips;
|
||||
|
||||
@Inject RxBus rxBus;
|
||||
|
@ -44,7 +43,6 @@ public class FragmentRouteStops extends Fragment {
|
|||
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.searchResults);
|
||||
|
||||
if (recyclerView != null) {
|
||||
//subscription = rxBus.observeEvents(RxMessage.class).subscribe(handleScheduleExplorerRxMessages());
|
||||
routeViewAdapter.setPossibleTrips(possibleTrips);
|
||||
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
|
||||
|
@ -57,24 +55,8 @@ public class FragmentRouteStops extends Fragment {
|
|||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
|
||||
/*
|
||||
private Action1<RxMessage> handleScheduleExplorerRxMessages() {
|
||||
return new Action1<RxMessage>() {
|
||||
@Override
|
||||
public void call(RxMessage rxMessage) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
private void unPackBundle(Bundle bundle) {
|
||||
if (bundle != null) {
|
||||
possibleTrips = Parcels.unwrap(bundle.getParcelable(BundleKeys.ROUTE_STOPS));
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
package com.eleith.calchoochoo.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.eleith.calchoochoo.R;
|
||||
import com.eleith.calchoochoo.ScheduleExplorerActivity;
|
||||
import com.eleith.calchoochoo.data.Queries;
|
||||
import com.eleith.calchoochoo.data.Stop;
|
||||
import com.eleith.calchoochoo.data.StopTimes;
|
||||
import com.eleith.calchoochoo.utils.BundleKeys;
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.MapView;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.model.CameraPosition;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.LatLngBounds;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
import org.parceler.Parcels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class StopSummaryFragment extends Fragment implements OnMapReadyCallback {
|
||||
private GoogleMap googleMap;
|
||||
private MapView googleMapView;
|
||||
private Stop stopDestination;
|
||||
private Stop stopSource;
|
||||
private String tripId;
|
||||
private ArrayList<Pair<Stop, StopTimes>> tripStops;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
((ScheduleExplorerActivity) getActivity()).getComponent().inject(this);
|
||||
unWrapBundle(getArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_stop_summary, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
unWrapBundle(savedInstanceState);
|
||||
|
||||
// initialize the map!
|
||||
googleMapView = ((MapView) view.findViewById(R.id.trip_google_maps));
|
||||
googleMapView.onCreate(savedInstanceState);
|
||||
googleMapView.getMapAsync(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(GoogleMap googleMap) {
|
||||
this.googleMap = googleMap;
|
||||
|
||||
LatLng sourceLatLng = new LatLng(stopSource.stop_lat, stopSource.stop_lon);
|
||||
LatLng destinationLatLng = new LatLng(stopDestination.stop_lat, stopDestination.stop_lon);
|
||||
LatLngBounds latLngBounds = new LatLngBounds(sourceLatLng, destinationLatLng);
|
||||
googleMap.addMarker(new MarkerOptions().position(sourceLatLng).title(stopSource.stop_name));
|
||||
googleMap.addMarker(new MarkerOptions().position(destinationLatLng).title(stopDestination.stop_name));
|
||||
|
||||
CameraPosition cameraPosition = new CameraPosition.Builder().zoom(10).bearing(90).target(latLngBounds.getCenter()).build();
|
||||
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
|
||||
}
|
||||
|
||||
private void unWrapBundle(Bundle savedInstanceState) {
|
||||
if (savedInstanceState != null) {
|
||||
Log.d("poop", "unwrapping bundle");
|
||||
stopDestination = Parcels.unwrap(savedInstanceState.getParcelable(BundleKeys.STOP_DESTINATION));
|
||||
stopSource = Parcels.unwrap(savedInstanceState.getParcelable(BundleKeys.STOP_SOURCE));
|
||||
tripId = savedInstanceState.getString(BundleKeys.TRIP_ID);
|
||||
tripStops = Queries.findTripDetails(tripId);
|
||||
Log.d("poop", stopSource.stop_name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
googleMapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
googleMapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
googleMapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
googleMapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
googleMapView.onLowMemory();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.eleith.calchoochoo.fragments;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
public class TripDetailFragment extends Fragment {
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.eleith.calchoochoo.fragments;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
public class TripSummaryFragment extends Fragment{
|
||||
}
|
|
@ -9,4 +9,5 @@ public class BundleKeys {
|
|||
public static final String STOP_METHOD = "stop_method";
|
||||
public static final String STOP_DATETIME = "stop_datetime";
|
||||
public static final String ROUTE_STOPS = "route_stops";
|
||||
public static final String TRIP_ID = "trip_id";
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public class RxMessageKeys {
|
|||
public static final String DESTINATION_SELECTED = "destinationSelected";
|
||||
public static final String SOURCE_SELECTED = "arrivalSelected";
|
||||
public static final String DATE_TIME_SELECTED = "dateTimeSelected";
|
||||
public static final String TRIP_SELECTED = "tripSelected";
|
||||
|
||||
private static final Map<String, Class> keyToClassMap = createKeyMap();
|
||||
|
||||
|
@ -23,6 +24,7 @@ public class RxMessageKeys {
|
|||
map.put(DESTINATION_SELECTED, RxMessage.class);
|
||||
map.put(SOURCE_SELECTED, RxMessage.class);
|
||||
map.put(DATE_TIME_SELECTED, RxMessageArrivalOrDepartDateTime.class);
|
||||
map.put(TRIP_SELECTED, RxMessageString.class);
|
||||
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="100dp"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.gms.maps.MapView
|
||||
android:id="@+id/trip_google_maps"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
|
@ -2,6 +2,7 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/trip_summary_detail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:orientation="horizontal">
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="100dp"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="100dp"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
</LinearLayout>
|
Reference in New Issue