eleith
/
calchoochoo
Archived
1
0
Fork 0

get intents working from widget

This commit is contained in:
eleith 2017-03-04 09:29:26 -08:00
parent 6f498e7d36
commit d59f8b8b99
12 changed files with 62 additions and 39 deletions

View File

@ -3,7 +3,7 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" />
<option name="modules">

View File

@ -3,7 +3,7 @@ apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.eleith.calchoochoo"

View File

@ -204,7 +204,7 @@ public class ChooChooFragmentManager {
public void loadMapSearchFragment() {
Bundle mapSearchArgs = new Bundle();
ArrayList<Stop> stops = Queries.getAllStops();
ArrayList<Stop> stops = Queries.getAllParentStops();
mapSearchArgs.putParcelable(BundleKeys.STOPS, Parcels.wrap(stops));
setNextState(ChooChooFragmentManager.STATE_SHOW_MAP, mapSearchArgs);
@ -238,7 +238,7 @@ public class ChooChooFragmentManager {
public void loadSearchWidgetConfigureFragment() {
Bundle arguments = new Bundle();
ArrayList<Stop> stops = Queries.getAllStops();
ArrayList<Stop> stops = Queries.getAllParentStops();
arguments.putParcelable(BundleKeys.STOPS, Parcels.wrap(stops));
setNextState(ChooChooFragmentManager.STATE_CONFIGURE_WIDGET, arguments);
}

View File

@ -14,9 +14,6 @@ import com.eleith.calchoochoo.dagger.ChooChooWidgetConfigureModule;
import com.eleith.calchoochoo.data.Queries;
import com.eleith.calchoochoo.data.Stop;
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.RxMessageStop;
import javax.inject.Inject;
@ -112,7 +109,7 @@ public class ChooChooWidgetConfigure extends AppCompatActivity {
static Stop getStopFromPreferences(Context context, int appWidgetId) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
String stopId = prefs.getString(PREF_PREFIX_KEY + appWidgetId, null);
return Queries.getStopById(stopId);
return Queries.getParentStopById(stopId);
}
public ChooChooWidgetConfigureComponent getComponent() {

View File

@ -36,7 +36,7 @@ public class StopCardAdapter extends RecyclerView.Adapter<StopCardAdapter.StopCa
@Inject
public StopCardAdapter(RxBus rxBus) {
stops = Queries.getAllStops();
stops = Queries.getAllParentStops();
this.rxBus = rxBus;
}

View File

@ -94,7 +94,7 @@ public class TripStopsAdapter extends RecyclerView.Adapter<TripStopsAdapter.OneT
@OnClick(R.id.one_trip_stop_details)
void onClickTripSummary() {
Stop directionalStop = tripStops.get(getAdapterPosition()).first;
Stop stop = Queries.getStopById(directionalStop.parent_station);
Stop stop = Queries.getParentStopById(directionalStop.parent_station);
rxBus.send(new RxMessageStop(RxMessageKeys.STOP_SELECTED, stop));
}

View File

@ -2,21 +2,21 @@ 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;
import java.util.ArrayList;
public class Queries {
private static final ArrayList<Stop> allStops = new ArrayList<>(SQLite.select().from(Stop.class)
private static final ArrayList<Stop> allStops = new ArrayList<>(SQLite.select().from(Stop.class).queryList());
private static final ArrayList<Stop> allParentStops = new ArrayList<>(SQLite.select().from(Stop.class)
.where(Stop_Table.stop_code.is(""))
.and(Stop_Table.platform_code.is(""))
.queryList());
@ -34,8 +34,8 @@ public class Queries {
private static final ArrayList<Trips> allTrips = new ArrayList<>(SQLite.select().from(Trips.class).queryList());
public static ArrayList<Stop> getAllStops() {
return allStops;
public static ArrayList<Stop> getAllParentStops() {
return allParentStops;
}
public static ArrayList<Routes> getAllRoutes() {
@ -55,8 +55,18 @@ public class Queries {
}
@Nullable
public static Stop getStopById(String stop_id) {
for (Stop stop : allStops) {
public static Stop getParentStopById(String stop_id) {
for (Stop stop : allParentStops) {
if (stop.stop_id.equals(stop_id)) {
return stop;
}
}
return null;
}
@Nullable
public static Stop getDirectionalStopById(String stop_id) {
for (Stop stop : allDirectionalStops) {
if (stop.stop_id.equals(stop_id)) {
return stop;
}
@ -89,7 +99,7 @@ public class Queries {
Float smallestDistance = null;
Stop nearestStop = null;
for (Stop stop : allStops) {
for (Stop stop : allParentStops) {
Float distance = Math.abs(location.distanceTo(stop.getLocation()));
if (smallestDistance == null || distance < smallestDistance) {
smallestDistance = distance;
@ -172,7 +182,7 @@ public class Queries {
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.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 * " +
@ -214,33 +224,34 @@ public class Queries {
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.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.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 " +
" FROM stops, stop_times " +
" WHERE " +
" stop_times.stop_id = ?) AS st1, " +
" stops.stop_id = stop_times.stop_id " +
" AND stops.parent_station = ?) AS st1, " +
" (Select * " +
" FROM stop_times " +
" FROM stops, stop_times " +
" WHERE " +
" stop_times.stop_id = ?) AS st2, " +
" stops.stop_id = stop_times.stop_id " +
" AND stops.parent_station = ?) 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 " +
@ -360,6 +371,20 @@ public class Queries {
return possibleTrips;
}
public static ArrayList<Stop> findStopsOnTrip(String trip_id) {
ArrayList<StopTimes> stopTimes = new ArrayList<StopTimes>(SQLite.select().from(StopTimes.class).where(StopTimes_Table.trip_id.eq(trip_id)).queryList());
ArrayList<Stop> stops = new ArrayList<>();
for (StopTimes stopTime : stopTimes) {
Stop stop = Queries.getDirectionalStopById(stopTime.stop_id);
if (stop != null) {
stops.add(Queries.getParentStopById(stop.parent_station));
}
}
return stops;
}
public static ArrayList<Pair<Stop, StopTimes>> findTripDetails(String trip_id, Integer first_stop_sequence, Integer second_stop_sequence) {
ArrayList<Pair<Stop, StopTimes>> stopAndTimes = new ArrayList<>();

View File

@ -11,7 +11,6 @@ import android.view.View;
import android.view.ViewGroup;
import com.eleith.calchoochoo.ChooChooActivity;
import com.eleith.calchoochoo.ChooChooApplication;
import com.eleith.calchoochoo.R;
import com.eleith.calchoochoo.data.Queries;
import com.eleith.calchoochoo.data.Stop;
@ -122,7 +121,7 @@ public class MapSearchFragment extends Fragment implements OnMapReadyCallback {
@Override
public boolean onMarkerClick(Marker marker) {
String stopId = (String) marker.getTag();
Stop touchedStop = Queries.getStopById(stopId);
Stop touchedStop = Queries.getParentStopById(stopId);
if (touchedStop != null) {
rxBus.send(new RxMessageStop(RxMessageKeys.STOP_SELECTED, touchedStop));
}

View File

@ -15,7 +15,6 @@ 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;
@ -28,7 +27,6 @@ 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;
@ -74,13 +72,13 @@ public class SearchResultsFragment extends Fragment {
if (activity instanceof ChooChooActivity) {
((ChooChooActivity) activity).getComponent().inject(this);
}
stops = Queries.getAllStops();
unPackBundle(savedInstanceState != null ? savedInstanceState : getArguments());
stops = Queries.getAllParentStops();
unWrapBundle(savedInstanceState != null ? savedInstanceState : getArguments());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
unPackBundle(savedInstanceState);
unWrapBundle(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_search_results, container, false);
ButterKnife.bind(this, view);
@ -113,12 +111,16 @@ public class SearchResultsFragment extends Fragment {
super.onSaveInstanceState(outState);
}
private void unPackBundle(Bundle bundle) {
private void unWrapBundle(Bundle bundle) {
if (bundle != null) {
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);
if (trip != null) {
stops = Queries.findStopsOnTrip(trip.trip_id);
}
}
}

View File

@ -37,7 +37,7 @@ public class StopCardsFragment extends Fragment {
unPackBundle(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_stop_cards, container, false);
int position = Queries.getAllStops().indexOf(currentStop);
int position = Queries.getAllParentStops().indexOf(currentStop);
stopCardAdapter.setHighlightedStop(position);

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Mon Dec 26 18:15:29 PST 2016
#Sat Mar 04 08:34:27 PST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip