Skip to content

Commit

Permalink
Seemingly fixed the stale info bug by making sure to carry over the d…
Browse files Browse the repository at this point in the history
…b Id when saving fav routes.
  • Loading branch information
andrewvora committed Apr 20, 2017
1 parent ec705da commit 70203db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,18 @@ else if(FavoriteRoute.TYPE_TRAIN.equals(route.getType())) {
}
}

private void loadBusInformation(@NonNull FavoriteRoute favoriteRoute) {
private void loadBusInformation(@NonNull final FavoriteRoute favoriteRoute) {
Bus bus = new Bus();
bus.setRouteId(favoriteRoute.getRouteId());

BusesDataSource busesRepo = mView.getBusesDataSource();
busesRepo.getBus(bus, new BusesDataSource.GetBusCallback() {
@Override
public void onFinished(Bus bus) {
updateRouteOnDatabase(new FavoriteRoute(bus));
FavoriteRoute routeToSave = new FavoriteRoute(bus);
routeToSave.setId(favoriteRoute.getId());

updateRouteOnDatabase(routeToSave);
mView.onRouteInformationLoaded(bus);
}

Expand All @@ -130,7 +133,7 @@ public void onError(Object error) {
});
}

private void loadTrainInformation(@NonNull FavoriteRoute favoriteRoute) {
private void loadTrainInformation(@NonNull final FavoriteRoute favoriteRoute) {
Train train = new Train();
train.setTrainId(Long.parseLong(favoriteRoute.getRouteId()));
train.setLine(favoriteRoute.getName());
Expand All @@ -140,7 +143,10 @@ private void loadTrainInformation(@NonNull FavoriteRoute favoriteRoute) {
trainsRepo.getTrain(train, new TrainsDataSource.GetTrainRouteCallback() {
@Override
public void onFinished(Train train) {
updateRouteOnDatabase(new FavoriteRoute(train));
FavoriteRoute routeToSave = new FavoriteRoute(train);
routeToSave.setId(favoriteRoute.getId());

updateRouteOnDatabase(routeToSave);
mView.onRouteInformationLoaded(train);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,17 @@ public void onError(Object error) { }
});
}

private void loadUpdatedBusInformation(@NonNull FavoriteRoute route) {
private void loadUpdatedBusInformation(@NonNull final FavoriteRoute route) {
Bus bus = new Bus();
bus.setRouteId(route.getRouteId());

mBusRepo.getBus(bus, new BusesDataSource.GetBusCallback() {
@Override
public void onFinished(Bus bus) {
updateRouteOnView(new FavoriteRoute(bus));
FavoriteRoute routeToSave = new FavoriteRoute(bus);
routeToSave.setId(route.getId());

updateRouteOnView(routeToSave);
}

@Override
Expand All @@ -175,7 +178,7 @@ public void onError(Object error) {
});
}

private void loadUpdatedTrainInformation(@NonNull FavoriteRoute route) {
private void loadUpdatedTrainInformation(@NonNull final FavoriteRoute route) {
Train train = new Train();
train.setTrainId(Long.parseLong(route.getRouteId()));
train.setLine(route.getName());
Expand All @@ -184,7 +187,10 @@ private void loadUpdatedTrainInformation(@NonNull FavoriteRoute route) {
mTrainRepo.getTrain(train, new TrainsDataSource.GetTrainRouteCallback() {
@Override
public void onFinished(Train train) {
updateRouteOnView(new FavoriteRoute(train));
FavoriteRoute routeToSave = new FavoriteRoute(train);
routeToSave.setId(route.getId());

updateRouteOnView(routeToSave);
}

@Override
Expand Down

0 comments on commit 70203db

Please sign in to comment.