Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated places SDK and removed experimental annotations #216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import com.google.android.libraries.places.ktx.widget.PlaceSelectionError
import com.google.android.libraries.places.ktx.widget.PlaceSelectionSuccess
import com.google.android.libraries.places.ktx.widget.placeSelectionEvents
import com.google.android.libraries.places.widget.AutocompleteSupportFragment
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch

class AutocompleteDemoActivity : AppCompatActivity() {

@OptIn(ExperimentalCoroutinesApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_autocomplete)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ import com.google.android.gms.maps.model.LatLng
import com.google.android.libraries.places.api.model.AutocompletePrediction
import com.google.android.libraries.places.api.model.LocationBias
import com.google.android.libraries.places.api.model.Place
import com.google.android.libraries.places.api.model.PlaceTypes
import com.google.android.libraries.places.api.model.RectangularBounds
import com.google.android.libraries.places.api.model.TypeFilter
import com.google.android.libraries.places.api.net.PlacesClient
import com.google.android.libraries.places.ktx.api.net.awaitFetchPlace
import com.google.android.libraries.places.ktx.api.net.awaitFindAutocompletePredictions
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.lang.Exception
import javax.inject.Inject

@HiltViewModel
Expand All @@ -46,7 +44,6 @@ class PlacesSearchViewModel @Inject constructor(

private var searchJob: Job? = null

@OptIn(ExperimentalCoroutinesApi::class)
fun onSearchQueryChanged(query: String) {
searchJob?.cancel()

Expand All @@ -69,7 +66,7 @@ class PlacesSearchViewModel @Inject constructor(
val response = placesClient
.awaitFindAutocompletePredictions {
locationBias = bias
typeFilter = TypeFilter.ESTABLISHMENT
typesFilter = listOf(PlaceTypes.ESTABLISHMENT)
this.query = query
countries = listOf("US")
}
Expand All @@ -78,7 +75,6 @@ class PlacesSearchViewModel @Inject constructor(
}
}

@OptIn(ExperimentalCoroutinesApi::class)
fun onAutocompletePredictionClicked(prediction: AutocompletePrediction) {
val handler = CoroutineExceptionHandler { _, e ->
e.printStackTrace()
Expand Down
2 changes: 1 addition & 1 deletion places-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies {
implementation "com.android.volley:volley:1.2.1"
implementation 'androidx.multidex:multidex:2.0.1'
api "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.7.3"
api "com.google.android.libraries.places:places:3.2.0"
api "com.google.android.libraries.places:places:3.3.0"

// Tests
testImplementation "androidx.test.ext:junit:1.1.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ import com.google.android.libraries.places.api.net.FindAutocompletePredictionsRe
import com.google.android.libraries.places.api.net.FindCurrentPlaceRequest
import com.google.android.libraries.places.api.net.FindCurrentPlaceResponse
import com.google.android.libraries.places.api.net.PlacesClient
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.tasks.await

/**
* Wraps [PlacesClient.fetchPhoto] in a suspending function.
*
* Fetches a photo. If an error occurred, an [ApiException] will be thrown.
*/
@ExperimentalCoroutinesApi
public suspend fun PlacesClient.awaitFetchPhoto(
photoMetadata: PhotoMetadata,
actions: FetchPhotoRequest.Builder.() -> Unit = {}
Expand All @@ -55,7 +53,6 @@ public suspend fun PlacesClient.awaitFetchPhoto(
*
* Fetches the details of a place. If an error occurred, an [ApiException] will be thrown.
*/
@ExperimentalCoroutinesApi
public suspend fun PlacesClient.awaitFetchPlace(
placeId: String,
placeFields: List<Place.Field>,
Expand All @@ -72,7 +69,6 @@ public suspend fun PlacesClient.awaitFetchPlace(
*
* Fetches autocomplete predictions. If an error occurred, an [ApiException] will be thrown.
*/
@ExperimentalCoroutinesApi
public suspend fun PlacesClient.awaitFindAutocompletePredictions(
actions: FindAutocompletePredictionsRequest.Builder.() -> Unit
): FindAutocompletePredictionsResponse {
Expand All @@ -94,7 +90,6 @@ public suspend fun PlacesClient.awaitFindAutocompletePredictions(
@RequiresPermission(
allOf = ["android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_WIFI_STATE"]
)
@ExperimentalCoroutinesApi
public suspend fun PlacesClient.awaitFindCurrentPlace(
placeFields: List<Place.Field>
): FindCurrentPlaceResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.google.android.gms.common.api.Status
import com.google.android.libraries.places.api.model.Place
import com.google.android.libraries.places.widget.AutocompleteSupportFragment
import com.google.android.libraries.places.widget.listener.PlaceSelectionListener
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
Expand All @@ -29,7 +28,6 @@ public data class PlaceSelectionSuccess(val place: Place) : PlaceSelectionResult

public data class PlaceSelectionError(val status: Status) : PlaceSelectionResult()

@ExperimentalCoroutinesApi
public fun AutocompleteSupportFragment.placeSelectionEvents() : Flow<PlaceSelectionResult> =
callbackFlow {
this@placeSelectionEvents.setOnPlaceSelectedListener(object : PlaceSelectionListener {
Expand Down
Loading