Skip to content

Commit

Permalink
Merge pull request #1 from Ichchhie/version-2
Browse files Browse the repository at this point in the history
Version 2
  • Loading branch information
Ichchhie authored Mar 17, 2020
2 parents 9d6e20a + 51704ee commit 50f2e3c
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 37 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//toaster library
implementation 'com.github.Ichchhie:Toaster-Library:0.8.0'
// baato library
implementation project(':baatolibrary')


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import androidx.appcompat.app.AppCompatActivity;

import com.kathmandulivinglabs.navigationlibrary.models.Geocode;
import com.kathmandulivinglabs.navigationlibrary.models.Geometry;
import com.kathmandulivinglabs.navigationlibrary.models.Place;
import com.kathmandulivinglabs.navigationlibrary.services.BaatoReverseGeoCodeService;
import com.kathmandulivinglabs.navigationlibrary.services.ToasterMessage;
import com.kathmandulivinglabs.navigationlibrary.utilities.BaatoUtil;
import com.kathmandulivinglabs.baatolibrary.models.Geocode;
import com.kathmandulivinglabs.baatolibrary.models.Geometry;

import java.util.List;
import com.kathmandulivinglabs.baatolibrary.models.SearchAPIResponse;
import com.kathmandulivinglabs.baatolibrary.services.BaatoReverseGeoCode;
import com.kathmandulivinglabs.baatolibrary.services.BaatoSearch;
import com.kathmandulivinglabs.baatolibrary.services.ToasterMessage;
import com.kathmandulivinglabs.baatolibrary.utilities.BaatoUtil;

public class MainActivity extends AppCompatActivity {

Expand All @@ -27,27 +27,47 @@ protected void onCreate(Bundle savedInstanceState) {
Geometry geometry = BaatoUtil.getGeoJsonFromEncodedPolyLine(encoded);

performReverseGeoCoding();
performSearch();
}

private void performReverseGeoCoding() {
new BaatoReverseGeoCodeService(this)
new BaatoReverseGeoCode(this)
.setGeoCode(new Geocode(27.73405, 85.33685))
.setAccessToken(Constants.TOKEN)
.setRadius(2)
.withListener(new BaatoReverseGeoCodeService.BaatoReverseGeoCodeRequestListener() {
.withListener(new BaatoReverseGeoCode.BaatoReverseGeoCodeRequestListener() {
@Override
public void onSuccess(List<Place> places) {
Log.d(TAG, "onSuccess: " + places.size());
for (Place place : places)
Log.d(TAG, "onSuccess:reverse " + place);
public void onSuccess(SearchAPIResponse places) {
// success response here
Log.d(TAG, "onSuccess: reverse " + places.toString());
}

@Override
public void onFailed(Throwable error) {
// failure response here
Log.d(TAG, "onFailed:reverse " + error.getMessage());
}
})
.doReverseGeoCode();
}

private void performSearch() {
new BaatoSearch(this)
.setAccessToken(Constants.TOKEN)
.setQuery("Kathmandu Living Labs")
.withListener(new BaatoSearch.BaatoSearchRequestListener() {
@Override
public void onSuccess(SearchAPIResponse places) {
// get the list of search results here
Log.d(TAG, "onSuccess:search " + places.toString());
}

@Override
public void onFailed(Throwable error) {
// get the error messages here
Log.d(TAG, "onFailed:search " + error.getMessage());
}
})
.doSearch();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public void onCreate() {
tinyDB = new TinyDB(getApplicationContext());
}


public static TinyDB db() {
return tinyDB;
}
Expand Down Expand Up @@ -52,6 +51,16 @@ public Response intercept(Chain chain) throws IOException {
return retrofit;
}

public static Retrofit retrofitV2() {
Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl("http://192.168.1.71:8080/api/v2/")
.addConverterFactory(GsonConverterFactory.create());


Retrofit retrofitV2 = builder.build();
return retrofitV2;
}

public static boolean isConnectedToNetwork(Context context) {
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.kathmandulivinglabs.baatolibrary.models;

import androidx.annotation.NonNull;

import java.util.List;

public class SearchAPIResponse {

private String timestamp;
private Integer status;
private String message;
private List<Place> data;

public String getTimestamp() {
return timestamp;
}

public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}

public Integer getStatus() {
return status;
}

public void setStatus(Integer status) {
this.status = status;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public List<Place> getData() {
return data;
}

public void setData(List<Place> data) {
this.data = data;
}

@Override
public String toString() {
return "SearchAPIResponse{" +
"timestamp='" + timestamp + '\'' +
", status=" + status +
", message='" + message + '\'' +
", data=" + data +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kathmandulivinglabs.baatolibrary.requests;

import com.kathmandulivinglabs.baatolibrary.models.Place;
import com.kathmandulivinglabs.baatolibrary.models.SearchAPIResponse;

import java.util.List;

Expand All @@ -10,12 +11,19 @@

public interface QueryAPI {

@GET("search")
Call<List<Place>> searchQuery(@Query("q") String query);
// @GET("search")
// Call<SearchAPIResponse> searchQuery(@Query("q") String query);

@GET("reverse")
Call<List<Place>> performReverseGeoCode(@Query("lat") double lat, @Query("lon") double lon, @Query("radius") int radius);
// @GET("reverse")
// Call<SearchAPIResponse> performReverseGeoCode(@Query("lat") double lat, @Query("lon") double lon, @Query("radius") int radius);

@GET("routes")
Call<List<Place>> searchQuery(@Query("origin") String origin,@Query("destination") String destination,@Query("mode") String mode);

//API version 2
@GET("search")
Call<SearchAPIResponse> searchQuery(@Query("key") String key, @Query("q") String query);

@GET("reverse")
Call<SearchAPIResponse> performReverseGeoCode(@Query("key") String key, @Query("lat") double lat, @Query("lon") double lon);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.kathmandulivinglabs.baatolibrary.application.App;
import com.kathmandulivinglabs.baatolibrary.models.Place;
import com.kathmandulivinglabs.baatolibrary.models.SearchAPIResponse;
import com.kathmandulivinglabs.baatolibrary.requests.QueryAPI;

import java.io.IOException;
Expand All @@ -25,7 +26,7 @@ public interface BaatoRouteRequestListener {
* onSuccess method called after it is successful
* onFailed method called if it can't places
*/
void onSuccess(List<Place> places);
void onSuccess(SearchAPIResponse places);

void onFailed(Throwable error);
}
Expand Down Expand Up @@ -63,9 +64,9 @@ public BaatoNavigationRoute withListener(BaatoRouteRequestListener baatoRouteReq

public void giveMeRoutes() {
QueryAPI queryAPI = App.retrofit(accessToken).create(QueryAPI.class);
queryAPI.searchQuery(query).enqueue(new Callback<List<Place>>() {
queryAPI.searchQuery(accessToken, query).enqueue(new Callback<SearchAPIResponse>() {
@Override
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
public void onResponse(Call<SearchAPIResponse> call, Response<SearchAPIResponse> response) {
if (response.isSuccessful() && response.body() != null)
baatoRouteRequestListener.onSuccess(response.body());
else{
Expand All @@ -78,7 +79,7 @@ public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
}

@Override
public void onFailure(Call<List<Place>> call, Throwable throwable) {
public void onFailure(Call<SearchAPIResponse> call, Throwable throwable) {
baatoRouteRequestListener.onFailed(throwable);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.kathmandulivinglabs.baatolibrary.services;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;

import com.kathmandulivinglabs.baatolibrary.application.App;
import com.kathmandulivinglabs.baatolibrary.models.Geocode;
import com.kathmandulivinglabs.baatolibrary.models.Place;
import com.kathmandulivinglabs.baatolibrary.models.SearchAPIResponse;
import com.kathmandulivinglabs.baatolibrary.requests.QueryAPI;

import java.io.IOException;
Expand All @@ -17,6 +19,8 @@
import retrofit2.Response;

public class BaatoReverseGeoCode {

private static final String TAG = "BaatoReverseGeoCode";
private Context context;
private BaatoReverseGeoCodeRequestListener baatoSearchRequestListener;
private String accessToken;
Expand All @@ -26,9 +30,9 @@ public class BaatoReverseGeoCode {
public interface BaatoReverseGeoCodeRequestListener {
/**
* onSuccess method called after it is successful
* onFailed method called if it can't places
* onFailed method called if it can't search places
*/
void onSuccess(List<Place> places);
void onSuccess(SearchAPIResponse places);

void onFailed(Throwable error);
}
Expand Down Expand Up @@ -73,23 +77,24 @@ public BaatoReverseGeoCode withListener(BaatoReverseGeoCodeRequestListener baato
}

public void doReverseGeoCode() {
QueryAPI queryAPI = App.retrofit(accessToken).create(QueryAPI.class);
queryAPI.performReverseGeoCode(geocode.lat, geocode.lon, radius).enqueue(new Callback<List<Place>>() {
QueryAPI queryAPI = App.retrofitV2().create(QueryAPI.class);
queryAPI.performReverseGeoCode(accessToken, geocode.lat, geocode.lon).enqueue(new Callback<SearchAPIResponse>() {
@Override
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
public void onResponse(Call<SearchAPIResponse> call, Response<SearchAPIResponse> response) {
if (response.isSuccessful() && response.body() != null)
baatoSearchRequestListener.onSuccess(response.body());
else {
try {
baatoSearchRequestListener.onFailed(new Throwable(response.errorBody().string()));
} catch (IOException e) {
Log.d(TAG, "onResponse: ");
} catch (Exception e) {
e.printStackTrace();
}
}
}

@Override
public void onFailure(Call<List<Place>> call, Throwable throwable) {
public void onFailure(Call<SearchAPIResponse> call, Throwable throwable) {
baatoSearchRequestListener.onFailed(throwable);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.kathmandulivinglabs.baatolibrary.application.App;
import com.kathmandulivinglabs.baatolibrary.models.Place;
import com.kathmandulivinglabs.baatolibrary.models.SearchAPIResponse;
import com.kathmandulivinglabs.baatolibrary.requests.QueryAPI;

import java.io.IOException;
Expand All @@ -25,7 +26,7 @@ public interface BaatoSearchRequestListener {
* onSuccess method called after it is successful
* onFailed method called if it can't places
*/
void onSuccess(List<Place> places);
void onSuccess(SearchAPIResponse places);

void onFailed(Throwable error);
}
Expand Down Expand Up @@ -62,10 +63,10 @@ public BaatoSearch withListener(BaatoSearchRequestListener baatoSearchRequestLis
}

public void doSearch() {
QueryAPI queryAPI = App.retrofit(accessToken).create(QueryAPI.class);
queryAPI.searchQuery(query).enqueue(new Callback<List<Place>>() {
QueryAPI queryAPI = App.retrofitV2().create(QueryAPI.class);
queryAPI.searchQuery(accessToken, query).enqueue(new Callback<SearchAPIResponse>() {
@Override
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
public void onResponse(Call<SearchAPIResponse> call, Response<SearchAPIResponse> response) {
if (response.isSuccessful() && response.body() != null)
baatoSearchRequestListener.onSuccess(response.body());
else{
Expand All @@ -78,7 +79,7 @@ public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
}

@Override
public void onFailure(Call<List<Place>> call, Throwable throwable) {
public void onFailure(Call<SearchAPIResponse> call, Throwable throwable) {
baatoSearchRequestListener.onFailed(throwable);
}
});
Expand Down
1 change: 1 addition & 0 deletions baatolibrary/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">178.128.59.143</domain>
<domain includeSubdomains="true">192.168.1.71:8080</domain>
</domain-config>
</network-security-config>

0 comments on commit 50f2e3c

Please sign in to comment.