Skip to content

Commit

Permalink
feature complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Drabu committed May 6, 2019
1 parent 3121f2f commit 244248e
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ import com.oneclickaway.opensource.placeautocomplete.ui.SearchPlaceActivity

class ExampleLocationSearch : AppCompatActivity() {

lateinit var searchLocationBtn : Button
lateinit var searchLocationBtn : Button

var API_KEY = "AIzaSyBuVzsoP0X5Tp_7t9HwgYtnNotioUGPb3Q"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_example_location_search)

searchLocationBtn = findViewById(R.id.searchLocationBTN)

val intent = Intent(this, SearchPlaceActivity::class.java)
intent.putExtra(StatusCodes.GOOGLE_API_KEY, API_KEY)
// intent.putExtra(StatusCodes.SEARCH_TITLE, "Enter pickup location")
// intent.putExtra(StatusCodes.CURRENT_LOCATION, "12.885970,77.656181")
// intent.putExtra(StatusCodes.ENCLOSE_RADIUS, "10000")

searchLocationBtn.setOnClickListener{
startActivityForResult(Intent(this, SearchPlaceActivity::class.java), 700)
startActivityForResult(intent, 700)
overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out)
}

}


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ext{
rxBindingVersion = '2.1.1'
rxJava = '2.2.8'
rxAndroid = '2.1.1'
carviewVersion = '28.0.0'



Expand Down
6 changes: 5 additions & 1 deletion place_autocomplete/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'


implementation "com.android.support:recyclerview-v7:$rootProject.recyclerViewVersion"
implementation "com.android.support:cardview-v7:$rootProject.carviewVersion"


/*REST Api Libraries*/
implementation "com.squareup.okhttp3:okhttp:$rootProject.okhttp3Version"
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"

implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.loggingInterceptor"
implementation "com.squareup.retrofit2:converter-gson:$rootProject.gsonVersion"
implementation "com.android.support:recyclerview-v7:$rootProject.recyclerViewVersion"


/*RXAndroid and RXJava*/
Expand Down
4 changes: 3 additions & 1 deletion place_autocomplete/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
package="com.oneclickaway.opensource.placeautocomplete">

<application>
<activity android:name=".ui.SearchPlaceActivity"/>
<activity
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:name=".ui.SearchPlaceActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import java.util.concurrent.TimeUnit
object RESTAPIManager {


var API_KEY = "AIzaSyBuVzsoP0X5Tp_7t9HwgYtnNotioUGPb3Q"
// https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJrTLr-GyuEmsRBfy61i59si0&key=YOUR_API_KEY
var BASE_URL = "https://maps.googleapis.com/maps/api/place/"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package com.oneclickaway.opensource.placeautocomplete.api.base
import com.oneclickaway.opensource.placeautocomplete.api.bean.place_details.PlacesDetailsResponse
import com.oneclickaway.opensource.placeautocomplete.api.bean.places_response.SearchResponse
import io.reactivex.Observable
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Query
import java.util.*

interface SearchPlaceApi {



@GET("details/json")
fun getPlaceDetailsFromPlaceId(@Query("placeid") placeId : String, @Query("key") apiKey : String = RESTAPIManager.API_KEY) : Observable<PlacesDetailsResponse>
fun getPlaceDetailsFromPlaceId(
@Query("placeid") placeId: String, @Query("key") apiKey: String
): Observable<PlacesDetailsResponse>

@GET("autocomplete/json")
fun getPlaceResults(@Query("input") placeHint : String, @Query("key") apiKey : String = RESTAPIManager.API_KEY) : Observable<SearchResponse>
fun getPlaceResults(
@Query("input") placeHint: String, @Query("key") apiKey: String, @Query("location") location: String, @Query(
"radius"
) radius: String
): Observable<SearchResponse>

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class SearchPlacesRepo {
private var listOfSearchResults: MutableLiveData<List<PredictionsItem?>> = MutableLiveData()

/** @author @buren ---> {this microservice gets autocomplete results}*/
fun requestListOfSearchResults(placeHint: String) {
fun requestListOfSearchResults(placeHint: String, apiKey: String, location : String, radius : String) {
compositeDisposable.add(

RESTAPIManager.getInstance().getPlaceResults(placeHint)
RESTAPIManager.getInstance().getPlaceResults(placeHint = placeHint, apiKey = apiKey, location = location, radius = radius)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.map {
Expand Down Expand Up @@ -54,12 +54,12 @@ class SearchPlacesRepo {

private var placeDetails: MutableLiveData<PlaceDetails?> = MutableLiveData()

fun requestPlaceDetails(placeId: String) {
fun requestPlaceDetails(placeId: String, apiKey: String) {


compositeDisposable.add(

RESTAPIManager.getInstance().getPlaceDetailsFromPlaceId(placeId = placeId)
RESTAPIManager.getInstance().getPlaceDetailsFromPlaceId(placeId = placeId, apiKey = apiKey)
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.io())
.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class SearchPlacesViewModel(application: Application) : AndroidViewModel(applica

var searchPlacesRepo = SearchPlacesRepo()

fun requestListOfSearchResults(placeHint: String) {
searchPlacesRepo.requestListOfSearchResults(placeHint)
fun requestListOfSearchResults(placeHint: String, apiKey : String, location : String, radius : String) {
searchPlacesRepo.requestListOfSearchResults(placeHint = placeHint, apiKey = apiKey, location = location, radius = radius )
}

fun getLiveListOfSearchResultsStream() = searchPlacesRepo.getLiveListOfSearchResultsStream()

fun requestPlaceDetails(placeId : String){
searchPlacesRepo.requestPlaceDetails(placeId = placeId)
fun requestPlaceDetails(placeId : String, apiKey : String){
searchPlacesRepo.requestPlaceDetails(placeId = placeId, apiKey = apiKey)
}

fun getPlaceDetailsLiveDataStream() = searchPlacesRepo.getPlaceDetailsLiveDataStream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.oneclickaway.opensource.placeautocomplete.components

object StatusCodes {
val SEARCH_TITLE: String? = "searchTitle"
val ENCLOSE_RADIUS: String? ="enclosingRadius"
val CURRENT_LOCATION: String? = "location"
val GOOGLE_API_KEY: String? = "apiKey"
val PLACE_DATA: String? = "PLACE_DETAILS"
val GOOGLE_SEARCH_RESULT_OK = "OK"

Expand Down
Loading

0 comments on commit 244248e

Please sign in to comment.