Skip to content

Commit

Permalink
Merge pull request #7 from baato/gitorigin/instrution
Browse files Browse the repository at this point in the history
refactored code.
  • Loading branch information
Bhawak authored Jul 9, 2020
2 parents 9ca4417 + 1cf2437 commit 7b743fa
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation project(':libandroid-navigation-ui')
implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.github.baato:java-client:1.1.0'
implementation 'com.github.baato:java-client:1.1.2'

implementation 'com.google.android.material:material:1.1.0'
testImplementation 'junit:junit:4.12'
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/bhawak/osmnavigation/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ private void getRoute(Point origin, Point destination) {
// }
// });

//Debug version
/*
Call<DirectionAPIResponse> call = getApiInterface().getRoutes(Constants.token, points, "car", false, true);
call.enqueue(new Callback<DirectionAPIResponse>() {
@Override
Expand Down Expand Up @@ -684,6 +686,7 @@ public void onFailure(Call<DirectionAPIResponse> call, Throwable t) {
Log.d(TAG, "Request:" + call.request());
}
});
*/
}

// @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.graphhopper.util.PointList;
import com.graphhopper.util.RoundaboutInstruction;
import com.graphhopper.util.TranslationMap;
//import com.baato.baatolibrary.models.NavResponse;
import com.baato.baatolibrary.models.NavResponse;
//import com.mapbox.api.directions.v5.models.StepIntersection;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.transition.TransitionManager;

import com.baato.baatolibrary.models.DirectionsAPIResponse;
import com.baato.baatolibrary.models.NavResponse;
import com.baato.baatolibrary.services.BaatoRouting;
import com.bhawak.osmnavigation.MainActivity;
import com.bhawak.osmnavigation.R;
import com.bhawak.osmnavigation.navigation.DirectionAPIResponse;
import com.bhawak.osmnavigation.navigation.DistanceConfig;
import com.bhawak.osmnavigation.navigation.DistanceUtils;
import com.bhawak.osmnavigation.navigation.NavResponse;
import com.bhawak.osmnavigation.navigation.NavigateResponseConverter;
import com.bhawak.osmnavigation.navigation.NavigateResponseConverterTranslationMap;
import com.bhawak.osmnavigation.navigation.view.notification.CustomNavigationNotification;
Expand Down Expand Up @@ -573,33 +575,37 @@ private void getRoute(Point origin, Point destination, boolean isOffRoute) {
// points[0] = "27.713042695157757,85.2703857421875";
points[1] = destination.latitude() + "," + destination.longitude();

// new BaatoRouting(this)
// .setPoints(points)
// .setAccessToken(Constants.token)
// .setMode("car") //eg bike, car, foot
// .setAlternatives(false) //optional parameter
// .setInstructions(true) //optional parameter
// .withListener(new BaatoRouting.BaatoRoutingRequestListener() {
// @Override
// public void onSuccess(DirectionsAPIResponse directionResponse) {
// NavResponse navResponse = directionResponse.getData().get(0);
// double distanceInKm = navResponse.getDistanceInMeters() / 1000;
// long time = navResponse.getTimeInMs() / 1000;
// ObjectNode parsedNavigationResponse = NavigateResponseConverter.convertFromGHResponse(directionResponse.getData().get(0), "car");
//
// DirectionsResponse directionsResponse = DirectionsResponse.fromJson(String.valueOf(parsedNavigationResponse));
// route = directionsResponse.routes().get(0);
// handleRoute(directionsResponse, isOffRoute);
// }
//
// @Override
// public void onFailed(Throwable t) {
// if (t.getMessage() != null && t.getMessage().contains("Failed to connect"))
// Toast.makeText(getApplicationContext(), "Please connect to internet to get the routes!", Toast.LENGTH_SHORT).show();
//
// }
// })
// .doRequest();
new BaatoRouting(this)
.setPoints(points)
.setAccessToken(Constants.token)
.setMode("car") //eg bike, car, foot
.setAlternatives(false) //optional parameter
.setInstructions(true)
.setAPIBaseURL("http://api-staging.baato.io/api/")//optional parameter
.setAPIVersion("1")
.withListener(new BaatoRouting.BaatoRoutingRequestListener() {
@Override
public void onSuccess(DirectionsAPIResponse directionResponse) {
Log.d("debug:", String.valueOf(directionResponse.getData().size()));
NavResponse navResponse = directionResponse.getData().get(0);
double distanceInKm = navResponse.getDistanceInMeters() / 1000;
long time = navResponse.getTimeInMs() / 1000;
ObjectNode parsedNavigationResponse = NavigateResponseConverter.convertFromGHResponse(directionResponse.getData().get(0), "car");

DirectionsResponse directionsResponse = DirectionsResponse.fromJson(String.valueOf(parsedNavigationResponse));
route = directionsResponse.routes().get(0);
handleRoute(directionsResponse, isOffRoute);
}

@Override
public void onFailed(Throwable t) {
if (t.getMessage() != null && t.getMessage().contains("Failed to connect"))
Toast.makeText(getApplicationContext(), "Please connect to internet to get the routes!", Toast.LENGTH_SHORT).show();

}
})
.doRequest();
/*
Call<DirectionAPIResponse> call = MainActivity.getApiInterface().getRoutes(Constants.token, points, "car", false, true);
call.enqueue(new Callback<DirectionAPIResponse>() {
@Override
Expand All @@ -626,6 +632,7 @@ public void onFailure(Call<DirectionAPIResponse> call, Throwable t) {
Timber.d("Request:%s", call.request());
}
});
*/
}

private void handleRoute(DirectionsResponse response, boolean isOffRoute) {
Expand Down

0 comments on commit 7b743fa

Please sign in to comment.