From 2bc08ecf11e383181063150004560ece7a7460cd Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 16:06:47 +0200 Subject: [PATCH 01/16] redundant comments removed --- .../placesearchktx/placesearch/FindPlace.kt | 34 --------------- .../placesearch/NearbySearch.kt | 42 ------------------- 2 files changed, 76 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt index 9e81b8c..e6d6cda 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt @@ -16,50 +16,16 @@ import kotlinx.coroutines.Deferred * */ class FindPlace private constructor(private val builder :Builder) { - /** - * [Diana] object with general settings - * */ private val diana : Diana = builder.diana; - /** - * The required parameter. - * The text string on which to search, for example: "restaurant" or "123 Main Street". - * This must be a place name, address, or category of establishments. - * Any other types of input can generate errors and are not guaranteed to return valid results. - * The Places API will return candidate matches based on this string and order the results based - * on their perceived relevance. - * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#input - * */ private val input :String = builder.getInput() - /** - * The required parameter. - * The type of input. This can be one of either [textquery] or [phonenumber]. - * Phone numbers must be in international format (prefixed by a plus sign ("+"), - * followed by the country code, then the phone number itself). - * See E.164 ITU recommendation for more information. - * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#inputtype - * */ private val inputtype :String = builder.getInputType().toString() - /** - * Use the fields parameter to specify a comma-separated list of place data types to return. - * For example: fields=formatted_address,name,geometry. - * Use a forward slash when specifying compound values. For example: opening_hours/open_now. - * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#fields - * */ private var fields :String? = builder.getFields() - /** - * The language in which to return results. - * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#language - * */ private var language :String? = builder.getLanguage() - /** - * Prefer results in a specified area, by specifying either a radius plus lat/lng, or two lat/lng pairs representing the points of a rectangle. If this parameter is not specified, the API uses IP address biasing by default. - * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#locationbias - * */ private var locationbias :String? = builder.getLocationBias() diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt index 1d35e71..7848fa8 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt @@ -17,68 +17,26 @@ import kotlin.Exception * */ class NearbySearch private constructor(private val builder : Builder){ - /** - * [Diana] object with general settings - * */ private val diana : Diana = builder.diana - /** - * The required parameter. - * The [LatLng] object describing latitude/longitude around which to retrieve place information. - * */ private val location :String = builder.getLocation() - /** - * The text string on which to search, for example: "restaurant" or "123 Main Street". - * This must be a place name, address, or category of establishments. - * If this parameter is omitted, places with a business_status of CLOSED_TEMPORARILY or CLOSED_PERMANENTLY will not be returned. - * */ private val keyword :String? = builder.getKeyword() - /** - * The language in which to return results. - * */ private val language :String? = builder.getLanguage() - /** - * Restricts results to only those places within the specified range. - * Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. - * */ private val maxPrice :Int? = builder.getMaxPrice() - /** - * Restricts results to only those places within the specified range. - * Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. - * */ private val minPrice :Int? = builder.getMinPrice() - /** - * Returns only those places that are open for business at the time the query is sent. - * Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query. - * */ private val openNow :Boolean? = builder.getOpenNow() - /** - * Returns up to 20 results from a previously run search. - * Setting a pagetoken parameter will execute a search with the same parameters used previously — all parameters other than pagetoken will be ignored. - * */ private val pageToken :String? = builder.getPageToken() - /** - * Defines the distance (in meters) within which to return place results. - * Note that radius must not be included if [rankBy]=distance (described under Optional parameters below) is specified. - * */ private val radius :Int? = builder.getRadius() - /** - * Specifies the order in which results are listed - * */ private val rankBy : Rankby? = builder.getRankBy() - /** - * Restricts the results to places matching the specified type. Only one type may be specified. - * If more than one type is provided, all types following the first entry are ignored. - * */ private val type : Place.Type? = builder.getType() /** From b36bd422dcf052eb6a06498614ef03a7030d9a31 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 16:23:00 +0200 Subject: [PATCH 02/16] NearbySearch Updated --- .../github/urmichm/placesearchktx/Message.kt | 8 --- .../placesearch/NearbySearch.kt | 68 +++++++++---------- .../placesearch/NearbySearchTest.kt | 37 ++++------ 3 files changed, 46 insertions(+), 67 deletions(-) delete mode 100644 placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Message.kt diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Message.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Message.kt deleted file mode 100644 index 8510090..0000000 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Message.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.urmichm.placesearchktx - -/** - * Message class to be return after validation of the request parameters. - * @param message Message of the validation - * @param isValid true if the validation was successful; false otherwise - * */ -class Message(val message : String, val isValid : Boolean ) \ No newline at end of file diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt index 7848fa8..37c780c 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt @@ -250,8 +250,39 @@ class NearbySearch private constructor(private val builder : Builder){ * @return [NearbySearch] object created according to the builder settings. * */ fun build() : NearbySearch { + validate() return NearbySearch(this) } + + /** + * Validate parameters before calling the server + * @throws IllegalArgumentException if NearbySearch object is not valid + * */ + private fun validate(){ + minPrice?.apply { + if( priceNotInRange(this) ) + throw IllegalArgumentException("minPrice is out of possible range.") + } + maxPrice?.apply { + if( priceNotInRange(this) ) + throw IllegalArgumentException("maxPrice is out of possible range.") + } + + when(rankBy){ + Rankby.PROMINENCE -> { + if(radius == null) + throw IllegalArgumentException( + "When prominence is specified, the radius parameter is required.") + + } + Rankby.DISTANCE -> { + if(radius != null) + throw IllegalArgumentException( + "When using rankBy=distance, the radius parameter will not be accepted, and will result in an INVALID_REQUEST.") + } + } + + } } /** @@ -260,10 +291,6 @@ class NearbySearch private constructor(private val builder : Builder){ * */ suspend fun call() : NearbySearchContainer? { - // TODO: validate on build, not on call! - val message = validate() - if(!message.isValid) throw Exception(message.message) - val nearby: Deferred = Network.diana.nearbySearch( key = diana.key, @@ -288,39 +315,6 @@ class NearbySearch private constructor(private val builder : Builder){ } } - /** - * Validate parameters before calling the server - * @return The [Message] object based onn the validation. - * */ - fun validate() :Message{ - minPrice?.apply { - if( priceNotInRange(this) ) - return Message("minPrice is out of possible range.", false) - } - maxPrice?.apply { - if( priceNotInRange(this) ) - return Message("maxPrice is out of possible range.", false) - } - - when(rankBy){ - Rankby.PROMINENCE -> { - if(radius == null) - return Message( - "When prominence is specified, the radius parameter is required.", - false) - - } - Rankby.DISTANCE -> { - if(radius != null) - return Message( - "When using rankBy=distance, the radius parameter will not be accepted, and will result in an INVALID_REQUEST.", - false) - } - } - - return Message("OK", true) - } - /** * Rankby enumeration for [rankBy] parameter * */ diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt index 72edd5c..4d487c4 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt @@ -4,6 +4,7 @@ import com.github.urmichm.placesearchktx.Diana import com.google.android.gms.maps.model.LatLng import org.junit.Assert.* import org.junit.Test +import kotlin.IllegalArgumentException class NearbySearchTest{ @@ -12,11 +13,10 @@ class NearbySearchTest{ val nearbySearch = NearbySearch.Builder(Diana.Builder("").build()) .setMinPrice(6) .setLocation(LatLng(0.0,0.0)) - .build() - val m = nearbySearch.validate() - assertFalse(m.isValid) - assertEquals("minPrice is out of possible range.", m.message) + assertThrows("minPrice is out of possible range.", IllegalArgumentException::class.java) { + nearbySearch.build() + } } @Test @@ -25,11 +25,10 @@ class NearbySearchTest{ .setMinPrice(2) .setMaxPrice(5) .setLocation(LatLng(0.0,0.0)) - .build() - val m = nearbySearch.validate() - assertFalse(m.isValid) - assertEquals("maxPrice is out of possible range.", m.message) + assertThrows("maxPrice is out of possible range.", IllegalArgumentException::class.java) { + nearbySearch.build() + } } @Test @@ -38,11 +37,10 @@ class NearbySearchTest{ .setMinPrice(2) .setMaxPrice(4) .setLocation(LatLng(0.0,0.0)) - .build() - val m = nearbySearch.validate() - assertFalse(m.isValid) - assertEquals("When prominence is specified, the radius parameter is required.", m.message) + assertThrows("When prominence is specified, the radius parameter is required.", IllegalArgumentException::class.java) { + nearbySearch.build() + } } @Test @@ -53,11 +51,10 @@ class NearbySearchTest{ .setMinPrice(2) .setMaxPrice(4) .setLocation(LatLng(0.0,0.0)) - .build() - val m = nearbySearch.validate() - assertFalse(m.isValid) - assertEquals("When using rankBy=distance, the radius parameter will not be accepted, and will result in an INVALID_REQUEST.", m.message) + assertThrows("When using rankBy=distance, the radius parameter will not be accepted, and will result in an INVALID_REQUEST.", IllegalArgumentException::class.java) { + nearbySearch.build() + } } @Test @@ -68,10 +65,8 @@ class NearbySearchTest{ .setMaxPrice(4) .setLocation(LatLng(0.0,0.0)) .build() - val m = nearbySearch.validate() - assertTrue(m.isValid) - assertEquals("OK", m.message) + assertNotNull(nearbySearch) } @Test @@ -82,10 +77,8 @@ class NearbySearchTest{ .setMaxPrice(4) .setLocation(LatLng(0.0,0.0)) .build() - val m = nearbySearch.validate() - assertTrue(m.isValid) - assertEquals("OK", m.message) + assertNotNull(nearbySearch) } @Test From b645ac7433ddab2c42dce2783fa02ffad45caad9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 16:30:31 +0200 Subject: [PATCH 03/16] FindPlace minor update --- .../placesearchktx/placesearch/FindPlace.kt | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt index e6d6cda..1b8cd89 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt @@ -33,7 +33,7 @@ class FindPlace private constructor(private val builder :Builder) { * The builder class for [FindPlace] class * @param builder The [Builder] object * */ - class Builder(val diana : Diana){ + class Builder(val diana: Diana) { /** * The required parameter. @@ -44,7 +44,7 @@ class FindPlace private constructor(private val builder :Builder) { * on their perceived relevance. * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#input * */ - private lateinit var input :String + private lateinit var input: String /** * Getter for [input] @@ -56,7 +56,7 @@ class FindPlace private constructor(private val builder :Builder) { * Getter for [input] * @param input The text string on which to search, for example: "restaurant" or "123 Main Street". * */ - fun setInput(input :String) :Builder = apply { + fun setInput(input: String): Builder = apply { this.input = input } @@ -68,7 +68,7 @@ class FindPlace private constructor(private val builder :Builder) { * See E.164 ITU recommendation for more information. * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#inputtype * */ - private lateinit var inputtype :InputType + private lateinit var inputtype: InputType /** * Getter for [inputtype] @@ -80,7 +80,7 @@ class FindPlace private constructor(private val builder :Builder) { * Setter for [inputtype] * @param inputType The type of input. This can be one of either [InputType.TEXTQUERY] or [InputType.PHONENUMBER]. * */ - fun setInputType(inputType: InputType) :Builder = apply { + fun setInputType(inputType: InputType): Builder = apply { this.inputtype = inputType } @@ -90,7 +90,7 @@ class FindPlace private constructor(private val builder :Builder) { * Uses a forward slash when specifying compound values. For example: opening_hours/open_now. * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#fields * */ - private var fields :String? = null + private var fields: String? = null /** * Getter for [fields] @@ -102,7 +102,7 @@ class FindPlace private constructor(private val builder :Builder) { * Setter for [fields] * @param fields List of [FindPlace.Field] enums to specify a list of place data types to return. * */ - fun setFields(fields : List): Builder = apply { + fun setFields(fields: List): Builder = apply { this.fields = fields.joinToString(separator = ",") } @@ -111,7 +111,7 @@ class FindPlace private constructor(private val builder :Builder) { * @param fields List of [Place.Field] enums to specify a list of place data types to return. * */ @JvmName("googleSetFields") - fun setFields(fields : List) : Builder = apply { + fun setFields(fields: List): Builder = apply { this.fields = fields.joinToString(separator = ",", transform = { it.toRequestString() }) @@ -122,7 +122,7 @@ class FindPlace private constructor(private val builder :Builder) { * The language in which to return results. * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#language * */ - private var language :String? = null + private var language: String? = null /** * Getter for [language] @@ -134,7 +134,7 @@ class FindPlace private constructor(private val builder :Builder) { * Setter for [language] * @param language value to be set * */ - fun setLanguage(language :String) :Builder = apply { + fun setLanguage(language: String): Builder = apply { this.language = language } @@ -142,7 +142,7 @@ class FindPlace private constructor(private val builder :Builder) { * Prefer results in a specified area, by specifying either a radius plus lat/lng, or two lat/lng pairs representing the points of a rectangle. If this parameter is not specified, the API uses IP address biasing by default. * @details https://developers.google.com/maps/documentation/places/web-service/search-find-place#locationbias * */ - private var locationbias : String? = null + private var locationbias: String? = null /** * Getter for [locationbias] @@ -156,7 +156,7 @@ class FindPlace private constructor(private val builder :Builder) { * @param radius A string specifying radius in meters * @param center The center of the circle, lat/lng in decimal degrees. */ - fun setLocationBias(radius : Double, center : LatLng) :Builder = apply { + fun setLocationBias(radius: Double, center: LatLng): Builder = apply { locationbias = "circle:${radius}@${center.latitude},${center.longitude}" } @@ -166,7 +166,7 @@ class FindPlace private constructor(private val builder :Builder) { * Uses the following format: point:lat,lng. * @param point - A single lat/lng coordinate. */ - fun setLocationBias(point : LatLng) :Builder = apply { + fun setLocationBias(point: LatLng): Builder = apply { locationbias = "point:${point.latitude},${point.longitude}" } @@ -177,7 +177,7 @@ class FindPlace private constructor(private val builder :Builder) { * Uses the following format:rectangle:south,west|north,east. * Note that east/west values are wrapped to the range -180, 180, and north/south values are clamped to the range -90, 90. */ - fun setLocationBias(southwest : LatLng, northeast : LatLng) :Builder = apply{ + fun setLocationBias(southwest: LatLng, northeast: LatLng): Builder = apply { locationbias = "rectangle:${southwest.latitude},${southwest.longitude}|${northeast.latitude},${northeast.longitude}" } @@ -188,7 +188,7 @@ class FindPlace private constructor(private val builder :Builder) { * Uses the following format:rectangle:south,west|north,east. * Note that east/west values are wrapped to the range -180, 180, and north/south values are clamped to the range -90, 90. */ - fun setLocationBias(bounds : RectangularBounds) :Builder = apply{ + fun setLocationBias(bounds: RectangularBounds): Builder = apply { locationbias = "rectangle:${bounds.southwest.latitude},${bounds.southwest.longitude}" + "|${bounds.northeast.latitude},${bounds.northeast.longitude}" @@ -199,7 +199,18 @@ class FindPlace private constructor(private val builder :Builder) { * The build method to create a [FindPlace] object * @return [FindPlace] object created according to the builder settings. * */ - fun build() : FindPlace = FindPlace(this) + fun build(): FindPlace { + validate() + return FindPlace(this) + } + + /** + * Validate parameters before calling the server + * @throws IllegalArgumentException if NearbySearch object is not valid + * */ + private fun validate() { + + } } /** From e54a650e7d3a4a5417f7ad41a828d6d4204685a9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 16:45:10 +0200 Subject: [PATCH 04/16] TextSearch minor update --- .../placesearchktx/placesearch/TextSearch.kt | 67 ++++++++++++------- .../placesearch/TextSearchTest.kt | 33 +++++++++ 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt index 9f2a1f4..1c2fb5f 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt @@ -3,6 +3,7 @@ package com.github.urmichm.placesearchktx.placesearch import com.github.urmichm.placesearchktx.Diana import com.github.urmichm.placesearchktx.containers.TextSearchContainer import com.github.urmichm.placesearchktx.network.Network +import com.github.urmichm.placesearchktx.priceNotInRange import com.github.urmichm.placesearchktx.toRequestString import com.google.android.gms.maps.model.LatLng import com.google.android.libraries.places.api.model.Place @@ -38,7 +39,7 @@ class TextSearch private constructor(private val builder: Builder){ private var type : Place.Type? = builder.getType() - class Builder(val diana : Diana){ + class Builder(val diana : Diana) { /** * The text string on which to search, for example: "restaurant" or "123 Main Street". @@ -47,7 +48,7 @@ class TextSearch private constructor(private val builder: Builder){ * The Google Places service will return candidate matches based on this string and order the results based on * their perceived relevance. */ - private lateinit var query :String + private lateinit var query: String /** * Getter for [query] @@ -59,14 +60,14 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [query] * @param query The text string on which to search * */ - fun setQuery(query : String): Builder = apply{ + fun setQuery(query: String): Builder = apply { this.query = query } /** * The language in which to return results. * */ - private var language :String? = null + private var language: String? = null /** * Getter for [language] @@ -78,7 +79,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [language] * @param language New value for [language] * */ - fun setLanguage(language :String) : Builder = apply { + fun setLanguage(language: String): Builder = apply { this.language = language } @@ -86,7 +87,7 @@ class TextSearch private constructor(private val builder: Builder){ /** * The [LatLng] object describing latitude/longitude around which to retrieve place information. * */ - private var location : String? = null + private var location: String? = null /** * Getter for [location] in string format. @@ -98,7 +99,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [location] * @param location Location provided in form of [LatLng] object * */ - fun setLocation(location : LatLng): Builder = apply{ + fun setLocation(location: LatLng): Builder = apply { this.location = location.toRequestString() } @@ -107,7 +108,7 @@ class TextSearch private constructor(private val builder: Builder){ * Restricts results to only those places within the specified range. * Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. * */ - private var maxPrice :Int? = null + private var maxPrice: Int? = null /** * Getter for [maxPrice] @@ -119,7 +120,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [maxPrice] * @param maxPrice The new value for [maxPrice] * */ - fun setMaxPrice(maxPrice :Int) :Builder = apply{ + fun setMaxPrice(maxPrice: Int): Builder = apply { this.maxPrice = maxPrice } @@ -128,7 +129,7 @@ class TextSearch private constructor(private val builder: Builder){ * Restricts results to only those places within the specified range. * Valid values range between 0 (most affordable) to 4 (most expensive), inclusive. * */ - private var minPrice :Int? = null + private var minPrice: Int? = null /** * Getter for [minPrice] @@ -140,7 +141,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [minPrice] * @param minPrice The new value for [minPrice] * */ - fun setMinPrice(minPrice :Int) :Builder = apply{ + fun setMinPrice(minPrice: Int): Builder = apply { this.minPrice = minPrice } @@ -149,7 +150,7 @@ class TextSearch private constructor(private val builder: Builder){ * Returns only those places that are open for business at the time the query is sent. * Places that do not specify opening hours in the Google Places database will not be returned if you include this parameter in your query. * */ - private var openNow :Boolean? = null + private var openNow: Boolean? = null /** * Getter for [openNow] @@ -161,7 +162,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [openNow] * @param openNow The new value for [openNow] * */ - fun setOpenNow(openNow :Boolean) :Builder = apply{ + fun setOpenNow(openNow: Boolean): Builder = apply { this.openNow = openNow } @@ -170,7 +171,7 @@ class TextSearch private constructor(private val builder: Builder){ * Returns up to 20 results from a previously run search. * Setting a page token parameter will execute a search with the same parameters used previously — all parameters other than pagetoken will be ignored. * */ - private var pageToken :String? = null + private var pageToken: String? = null /** * Getter for [pageToken] @@ -182,17 +183,16 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [pageToken] * @param pageToken The new value for [pageToken] * */ - fun setPageToken(pageToken :String) :Builder = apply{ + fun setPageToken(pageToken: String): Builder = apply { this.pageToken = pageToken } - /** * Defines the distance (in meters) within which to return place results. * Note that radius must not be included if [rankBy]=distance (described under Optional parameters below) is specified. * */ - private var radius :Int? = null + private var radius: Int? = null /** * Getter for [radius] @@ -204,7 +204,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [radius] * @param radius The new value for [radius] * */ - fun setRadius(radius :Int) :Builder = apply{ + fun setRadius(radius: Int): Builder = apply { this.radius = radius } @@ -212,7 +212,7 @@ class TextSearch private constructor(private val builder: Builder){ /** * The region code, specified as a ccTLD ("top-level domain") two-character value. * */ - private var region :String? = null + private var region: String? = null /** * Getter for [region] @@ -224,7 +224,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [region] * @param region The new value for [region] * */ - fun setRegion(region :String) :Builder = apply { + fun setRegion(region: String): Builder = apply { this.region = region } @@ -233,7 +233,7 @@ class TextSearch private constructor(private val builder: Builder){ * Restricts the results to places matching the specified type. Only one type may be specified. * If more than one type is provided, all types following the first entry are ignored. * */ - private var type : Place.Type? = null + private var type: Place.Type? = null /** * Getter for [type] @@ -245,7 +245,7 @@ class TextSearch private constructor(private val builder: Builder){ * Setter for [type] * @param type The new value for [type] * */ - fun setType(type : Place.Type) :Builder = apply{ + fun setType(type: Place.Type): Builder = apply { this.type = type } @@ -254,10 +254,29 @@ class TextSearch private constructor(private val builder: Builder){ * The build method to create a [TextSearch] object * @return [TextSearch] object created according to the builder settings. * */ - fun build() :TextSearch{ - // validate first! + fun build(): TextSearch { + validate() return TextSearch(this) } + + /** + * Validate parameters before calling the server + * @throws IllegalArgumentException if NearbySearch object is not valid + * */ + private fun validate(){ + minPrice?.apply { + if( priceNotInRange(this) ) + throw IllegalArgumentException("minPrice is out of possible range.") + } + maxPrice?.apply { + if( priceNotInRange(this) ) + throw IllegalArgumentException("maxPrice is out of possible range.") + } + region?.apply { + if(this.length > 2) + throw IllegalArgumentException("The region code, must be specified as a ccTLD (\"top-level domain\") TWO-character value.") + } + } } /** diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt index 4b9529e..7fc6d8f 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt @@ -30,4 +30,37 @@ class TextSearchTest { assertNotNull(textSearch) } + @Test + fun maxPriceOutOfRange(){ + val textSearch = TextSearch.Builder(d) + .setQuery("query") + .setMaxPrice(6) + + assertThrows("maxPrice is out of possible range.", IllegalArgumentException::class.java) { + textSearch.build() + } + } + + @Test + fun minPriceOutOfRange(){ + val textSearch = TextSearch.Builder(d) + .setQuery("query") + .setMinPrice(-1) + + assertThrows("minPrice is out of possible range.", IllegalArgumentException::class.java) { + textSearch.build() + } + } + + @Test + fun regionIsIncorrect(){ + val textSearch = TextSearch.Builder(d) + .setQuery("query") + .setRegion("pll") + + assertThrows("The region code, must be specified as a ccTLD (\"top-level domain\") TWO-character value.", IllegalArgumentException::class.java) { + textSearch.build() + } + } + } \ No newline at end of file From 8ebaa379225c84efab040968c5f1641edccb9108 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 16:56:42 +0200 Subject: [PATCH 05/16] Diana class simplified --- .../github/urmichm/placesearchktx/Diana.kt | 22 ------------------- .../common/PlaceDetailsContainer.kt | 9 ++++---- .../urmichm/placesearchktx/network/Service.kt | 5 ++++- .../urmichm/placesearchktx/DianaTest.kt | 20 ----------------- .../containers/PlaceDetailsContainerTest.kt | 2 +- 5 files changed, 9 insertions(+), 49 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt index b2b6e8f..e11a9f4 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt @@ -15,23 +15,10 @@ class Diana private constructor( internal val key: String ){ - init{ - vicinityAsAddress = builder.getVicinityAsAddress() - } companion object { private const val TAG = "PlaceSearch-KTX" - /** - * Output format; indicates output in JavaScript Object Notation (JSON) - * */ - const val OUTPUT_FORMAT = "json" - - /** - * Convert vicinity data into Address data when converting Container objects into Google's Place object - * */ - var vicinityAsAddress = true - fun hello(){ Log.i(TAG, "Hello Diana!") } @@ -47,15 +34,6 @@ class Diana private constructor( * */ class Builder(private val key : String){ - /** - * Convert vicinity data into Address data when converting Container objects into Google's Place object - * */ - private var vicinityAsAddress = true - /** Getter for [vicinityAsAddress] */ - fun getVicinityAsAddress() = this.vicinityAsAddress - /** Setter for [vicinityAsAddress] */ - fun setVicinityAsAddress(vicinity2Address : Boolean) = apply{this.vicinityAsAddress = vicinity2Address} - /** * The build method to create a [Diana] object * @return [Diana] object created according to the builder settings. diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt index 3fd0909..3d7862f 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt @@ -1,6 +1,7 @@ package com.github.urmichm.placesearchktx.containers.common import android.os.Build +import android.util.Log import com.github.urmichm.placesearchktx.Diana import com.google.android.libraries.places.api.model.Place import com.squareup.moshi.Json @@ -50,7 +51,6 @@ data class PlaceDetailsContainer( /** * Converts [PlaceDetailsContainer] into [Place] object - * @warning Requires API [Build.VERSION_CODES.N] * */ fun asPlace() : Place{ val placeBuilder = Place.builder() @@ -67,8 +67,6 @@ data class PlaceDetailsContainer( .setIconUrl(this.iconUrl) // .setPhotoMetadatas(this.photos?.stream()?.map { it.toPhotoMetadata() }?.toList()) .setPlusCode(this.plusCode?.toPlusCode()) - - // TODO: deal with formattedAddress vs vicinity .setAddress(this.formattedAddress) /* The Following fields are not returned by Place Search, Nearby Search, and Text Search */ @@ -80,8 +78,9 @@ data class PlaceDetailsContainer( // .setUtcOffsetMinutes(@Nullable Integer var1); // .setWebsiteUri(@Nullable Uri var1); - if(null == placeBuilder.address && Diana.vicinityAsAddress) { - placeBuilder.address = this.vicinity + if(null == placeBuilder.address && null != this.vicinity) { + Log.w("PlaceDetailsContainer", "Vicinity is used as address") + placeBuilder.setAddress(this.vicinity) } return placeBuilder.build() diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt index 097e4f8..d3b9e48 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt @@ -1,6 +1,5 @@ package com.github.urmichm.placesearchktx.network -import com.github.urmichm.placesearchktx.Diana.Companion.OUTPUT_FORMAT import com.github.urmichm.placesearchktx.containers.FindPlaceContainer import com.github.urmichm.placesearchktx.containers.NearbySearchContainer import com.github.urmichm.placesearchktx.containers.TextSearchContainer @@ -23,6 +22,10 @@ import retrofit2.http.Query * */ private val URL = "https://maps.googleapis.com/maps/api/place/" +/** + * Output format; indicates output in JavaScript Object Notation (JSON) + * */ +private const val OUTPUT_FORMAT = "json" /** * @details https://developers.google.com/maps/documentation/places/web-service/search#PlaceSearchRequests diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt index 4b667bb..22721b9 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt @@ -6,8 +6,6 @@ import org.junit.Test class DianaTest { - private val JsonFormat = "json" - @Test fun testDianaKey(){ val key = "my-key" @@ -15,24 +13,6 @@ class DianaTest { assertEquals(key,d.key) } - @Test - fun testVicinityAsAddress(){ - // given default value - assertTrue(Diana.vicinityAsAddress) - - // override default value - Diana.vicinityAsAddress = false - assertFalse(Diana.vicinityAsAddress) - - // restore the default value - Diana.vicinityAsAddress = true - assertTrue(Diana.vicinityAsAddress) - } - - @Test - fun defaultOutputFormat(){ - assertEquals(JsonFormat, Diana.OUTPUT_FORMAT) - } // @Test // fun nearbySearch() { diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt index 4057c02..a2325fc 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt @@ -64,7 +64,7 @@ class PlaceDetailsContainerTest { assertEquals(container.businessStatus, place.businessStatus.name) assertEquals(container.rating, place.rating) - assertEquals( Diana.vicinityAsAddress, container.vicinity == place.address) + assertEquals( container.vicinity, place.address) assertEquals(container.placeId, place.id) assertEquals(container.userRatingsTotal, place.userRatingsTotal) From aa8c7baeaadccfcbe3c5ff6e8e35a8161bcb4ec2 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 17:11:31 +0200 Subject: [PATCH 06/16] Diana class simplified II --- .../github/urmichm/placesearchktx/Diana.kt | 20 +---------------- .../common/PlaceDetailsContainer.kt | 2 +- .../urmichm/placesearchktx/DianaTest.kt | 2 +- .../placesearch/FindPlaceTest.kt | 2 +- .../placesearch/NearbySearchTest.kt | 22 +++++++++++++------ .../placesearch/TextSearchTest.kt | 2 +- 6 files changed, 20 insertions(+), 30 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt index e11a9f4..41c81cb 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt @@ -10,12 +10,10 @@ import android.util.Log * If the field you want is not returned by Place Search, you can use Place Search to get a place_id, * then use that Place ID to make a Place Details request. * */ -class Diana private constructor( - builder : Builder, +class Diana ( internal val key: String ){ - companion object { private const val TAG = "PlaceSearch-KTX" @@ -28,20 +26,4 @@ class Diana private constructor( } } - /** - * The builder class for [Diana] class - * @param key Your application's API key. This key identifies your application. - * */ - class Builder(private val key : String){ - - /** - * The build method to create a [Diana] object - * @return [Diana] object created according to the builder settings. - * */ - fun build() : Diana{ - return Diana(this, key) - } - } - - } \ No newline at end of file diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt index 3d7862f..89cef18 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt @@ -79,7 +79,7 @@ data class PlaceDetailsContainer( // .setWebsiteUri(@Nullable Uri var1); if(null == placeBuilder.address && null != this.vicinity) { - Log.w("PlaceDetailsContainer", "Vicinity is used as address") + println("WARN: Vicinity is used as address") placeBuilder.setAddress(this.vicinity) } diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt index 22721b9..84f41b0 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt @@ -9,7 +9,7 @@ class DianaTest { @Test fun testDianaKey(){ val key = "my-key" - val d = Diana.Builder(key).build() + val d = Diana(key) assertEquals(key,d.key) } diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt index 39a8e66..62a31b2 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt @@ -15,7 +15,7 @@ class FindPlaceTest { @Before fun initDiana(){ - d = Diana.Builder("YOUR_API_KEY").build() + d = Diana("YOUR_API_KEY") } @Test diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt index 4d487c4..064eafe 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt @@ -3,14 +3,22 @@ package com.github.urmichm.placesearchktx.placesearch import com.github.urmichm.placesearchktx.Diana import com.google.android.gms.maps.model.LatLng import org.junit.Assert.* +import org.junit.Before import org.junit.Test import kotlin.IllegalArgumentException class NearbySearchTest{ + private lateinit var d :Diana + @Before + fun initDiana(){ + d = Diana("YOUR_API_KEY") + } + + @Test fun minPriceIsOutOfRange(){ - val nearbySearch = NearbySearch.Builder(Diana.Builder("").build()) + val nearbySearch = NearbySearch.Builder(d) .setMinPrice(6) .setLocation(LatLng(0.0,0.0)) @@ -21,7 +29,7 @@ class NearbySearchTest{ @Test fun maxPriceIsOutOfRange(){ - val nearbySearch = NearbySearch.Builder(Diana.Builder("").build()) + val nearbySearch = NearbySearch.Builder(d) .setMinPrice(2) .setMaxPrice(5) .setLocation(LatLng(0.0,0.0)) @@ -33,7 +41,7 @@ class NearbySearchTest{ @Test fun radiusParameterIsOmittedWhenRankedByProminence(){ - val nearbySearch = NearbySearch.Builder(Diana.Builder("").build()) + val nearbySearch = NearbySearch.Builder(d) .setMinPrice(2) .setMaxPrice(4) .setLocation(LatLng(0.0,0.0)) @@ -45,7 +53,7 @@ class NearbySearchTest{ @Test fun radiusParameterIsGivenWhenRankedByDistance(){ - val nearbySearch = NearbySearch.Builder(Diana.Builder("").build()) + val nearbySearch = NearbySearch.Builder(d) .setRankBy(NearbySearch.Rankby.DISTANCE) .setRadius(5000) .setMinPrice(2) @@ -59,7 +67,7 @@ class NearbySearchTest{ @Test fun validWhenRankedByDistanceAndRadiusOmitted(){ - val nearbySearch = NearbySearch.Builder(Diana.Builder("").build()) + val nearbySearch = NearbySearch.Builder(d) .setRankBy(NearbySearch.Rankby.DISTANCE) .setMinPrice(2) .setMaxPrice(4) @@ -71,7 +79,7 @@ class NearbySearchTest{ @Test fun validWhenRankedByProminenceAndRadiusGiven(){ - val nearbySearch = NearbySearch.Builder(Diana.Builder("").build()) + val nearbySearch = NearbySearch.Builder(d) .setRadius(1000) .setMinPrice(2) .setMaxPrice(4) @@ -84,7 +92,7 @@ class NearbySearchTest{ @Test fun locationNotProvided() { - val diana = Diana.Builder("").build() + val diana = d val builder = NearbySearch.Builder(diana) diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt index 7fc6d8f..91e5eb5 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt @@ -11,7 +11,7 @@ class TextSearchTest { @Before fun initDiana(){ - d = Diana.Builder("YOUR_API_KEY").build() + d = Diana("YOUR_API_KEY") } @Test From 709fb52ffdfdfcd4fe918efd964bf0c24a590086 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 18:19:50 +0200 Subject: [PATCH 07/16] Diana class simplified III --- .../java/com/github/urmichm/placesearchktx/network/Service.kt | 4 ++-- .../github/urmichm/placesearchktx/placesearch/FindPlace.kt | 2 +- .../github/urmichm/placesearchktx/placesearch/NearbySearch.kt | 2 +- .../github/urmichm/placesearchktx/placesearch/TextSearch.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt index d3b9e48..1b33703 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt @@ -160,7 +160,7 @@ private val moshi = Moshi.Builder() /** * Main entry point for network access. - * [Network.diana].nearbySearch(..) + * [Network.service].nearbySearch(..) */ internal object Network { // Configure retrofit to parse JSON and use coroutines @@ -170,6 +170,6 @@ internal object Network { .addCallAdapterFactory(CoroutineCallAdapterFactory()) .build() - val diana = retrofit.create(DianaService::class.java) as DianaService + val service = retrofit.create(DianaService::class.java) as DianaService } diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt index 1b8cd89..82595e8 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt @@ -279,7 +279,7 @@ class FindPlace private constructor(private val builder :Builder) { suspend fun call(): FindPlaceContainer?{ val find : Deferred = - Network.diana.findPlace( + Network.service.findPlace( key = diana.key, input = input, inputtype = inputtype, diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt index 37c780c..3a39296 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt @@ -292,7 +292,7 @@ class NearbySearch private constructor(private val builder : Builder){ suspend fun call() : NearbySearchContainer? { val nearby: Deferred = - Network.diana.nearbySearch( + Network.service.nearbySearch( key = diana.key, location = location, keyword = keyword, diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt index 1c2fb5f..87d4ae4 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt @@ -285,7 +285,7 @@ class TextSearch private constructor(private val builder: Builder){ * */ suspend fun call() : TextSearchContainer?{ val textSearch : Deferred = - Network.diana.textSearch( + Network.service.textSearch( key = diana.key, query = query, language = language, From 06b8d29a515278f65a1c0ca3947ae65d85852461 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 18:26:39 +0200 Subject: [PATCH 08/16] Diana class simplified IV --- .../java/com/github/urmichm/demo/MainActivity.kt | 11 +++++++++-- .../com/github/urmichm/placesearchktx/Diana.kt | 16 +--------------- .../placesearchktx/placesearch/FindPlace.kt | 6 ++++++ .../placesearchktx/placesearch/NearbySearch.kt | 4 ++++ .../placesearchktx/placesearch/TextSearch.kt | 5 +++++ 5 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/github/urmichm/demo/MainActivity.kt b/app/src/main/java/com/github/urmichm/demo/MainActivity.kt index 865a052..9241110 100644 --- a/app/src/main/java/com/github/urmichm/demo/MainActivity.kt +++ b/app/src/main/java/com/github/urmichm/demo/MainActivity.kt @@ -2,13 +2,20 @@ package com.github.urmichm.demo import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.util.Log import com.github.urmichm.placesearchktx.Diana +import com.github.urmichm.placesearchktx.placesearch.FindPlace +import com.github.urmichm.placesearchktx.placesearch.NearbySearch +import com.github.urmichm.placesearchktx.placesearch.TextSearch class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - Diana.hello() + + Log.i("MainActivity" ,FindPlace.TAG) + Log.i("MainActivity" ,NearbySearch.TAG) + Log.i("MainActivity" , TextSearch.TAG) + setContentView(R.layout.activity_main) - Diana.bye() } } \ No newline at end of file diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt index 41c81cb..71472de 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt @@ -12,18 +12,4 @@ import android.util.Log * */ class Diana ( internal val key: String -){ - - companion object { - private const val TAG = "PlaceSearch-KTX" - - fun hello(){ - Log.i(TAG, "Hello Diana!") - } - - fun bye(){ - Log.i(TAG, "Bye Diana!") - } - } - -} \ No newline at end of file +) \ No newline at end of file diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt index 82595e8..e800fb8 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt @@ -296,4 +296,10 @@ class FindPlace private constructor(private val builder :Builder) { } } + + companion object{ + public const val TAG = "FindPlace" + } + + } \ No newline at end of file diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt index 3a39296..006be64 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt @@ -327,5 +327,9 @@ class NearbySearch private constructor(private val builder : Builder){ } } + companion object{ + public const val TAG = "NearbySearch" + } + } \ No newline at end of file diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt index 87d4ae4..33bb387 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt @@ -306,4 +306,9 @@ class TextSearch private constructor(private val builder: Builder){ null } } + + companion object{ + public const val TAG = "TextSearch" + } + } \ No newline at end of file From 718e426a0fbb8238f2c48261884f9ea92a6432e5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Jun 2022 18:29:05 +0200 Subject: [PATCH 09/16] Builder classes cosmetic updates --- .../github/urmichm/placesearchktx/placesearch/FindPlace.kt | 4 ---- .../urmichm/placesearchktx/placesearch/NearbySearch.kt | 5 +---- .../github/urmichm/placesearchktx/placesearch/TextSearch.kt | 1 + 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt index e800fb8..8786494 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt @@ -29,10 +29,6 @@ class FindPlace private constructor(private val builder :Builder) { private var locationbias :String? = builder.getLocationBias() - /** - * The builder class for [FindPlace] class - * @param builder The [Builder] object - * */ class Builder(val diana: Diana) { /** diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt index 006be64..8b8b341 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt @@ -39,10 +39,7 @@ class NearbySearch private constructor(private val builder : Builder){ private val type : Place.Type? = builder.getType() - /** - * The builder class for [NearbySearch] class - * @param diana [Diana] object with general settings - * */ + class Builder(val diana : Diana){ /** diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt index 33bb387..fce976e 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt @@ -39,6 +39,7 @@ class TextSearch private constructor(private val builder: Builder){ private var type : Place.Type? = builder.getType() + class Builder(val diana : Diana) { /** From dd0a24df1f5982360fccdf0729c24ae314a6500f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Jun 2022 20:16:30 +0200 Subject: [PATCH 10/16] secrets added --- app/build.gradle | 9 +++++++++ build.gradle | 1 + local.defaults.properties | 4 ++++ placesearch-ktx/build.gradle | 11 ++++++++++- settings.gradle | 7 +++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 local.defaults.properties diff --git a/app/build.gradle b/app/build.gradle index 5d78971..9c8f6b3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.application' id 'kotlin-android' + id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' } android { @@ -42,4 +43,12 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} + +secrets { + // To add your Places API key to this project: + // 1. Update a file in your root project called `local.properties` and add this line, + // where YOUR_API_KEY is your API key: + // PLACES_API_KEY=YOUR_API_KEY + defaultPropertiesFileName 'local.defaults.properties' } \ No newline at end of file diff --git a/build.gradle b/build.gradle index eea3e48..71f7952 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31" + classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/local.defaults.properties b/local.defaults.properties new file mode 100644 index 0000000..7825929 --- /dev/null +++ b/local.defaults.properties @@ -0,0 +1,4 @@ +# This file contains a default value for your GMP API Key. +# To provide your actual GMP API Key, update the local.properties file using the PLACES_API_KEY +# as demonstrated below. +PLACES_API_KEY="YOUR_API_KEY" diff --git a/placesearch-ktx/build.gradle b/placesearch-ktx/build.gradle index d40777f..196c071 100644 --- a/placesearch-ktx/build.gradle +++ b/placesearch-ktx/build.gradle @@ -2,6 +2,7 @@ plugins { id 'com.android.library' id 'kotlin-android' id 'maven-publish' + id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' } android { @@ -75,4 +76,12 @@ afterEvaluate { } } } -} \ No newline at end of file +} + +secrets { + // To add your Places API key to this project: + // 1. Update a file in your root project called `local.properties` and add this line, + // where YOUR_API_KEY is your API key: + // PLACES_API_KEY=YOUR_API_KEY + defaultPropertiesFileName 'local.defaults.properties' +} diff --git a/settings.gradle b/settings.gradle index 7a41e71..cfbf008 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,10 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { From c9e21b31a00037fd313f70eb82e778f6398ed54b Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Jun 2022 21:31:17 +0200 Subject: [PATCH 11/16] diana removed I --- .../urmichm/placesearchktx/network/Service.kt | 11 ++++++++--- .../placesearchktx/placesearch/TextSearch.kt | 6 +----- .../placesearch/TextSearchTest.kt | 18 +++++------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt index 1b33703..9f88c92 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/network/Service.kt @@ -1,5 +1,6 @@ package com.github.urmichm.placesearchktx.network +import com.github.urmichm.placesearchktx.BuildConfig import com.github.urmichm.placesearchktx.containers.FindPlaceContainer import com.github.urmichm.placesearchktx.containers.NearbySearchContainer import com.github.urmichm.placesearchktx.containers.TextSearchContainer @@ -13,6 +14,10 @@ import retrofit2.converter.moshi.MoshiConverterFactory import retrofit2.http.GET import retrofit2.http.Query +/** + * API key + * */ +private val PLACES_API_KEY : String = BuildConfig.PLACES_API_KEY /** * Nearby search requests @@ -58,7 +63,7 @@ internal interface DianaService{ * */ @GET("textsearch/${OUTPUT_FORMAT}") fun textSearch( - @Query("key") key : String, + @Query("key") key : String = PLACES_API_KEY, @Query("query") query : String, @Query("language") language :String?, @@ -98,7 +103,7 @@ internal interface DianaService{ * */ @GET("nearbysearch/${OUTPUT_FORMAT}") fun nearbySearch( - @Query("key") key : String, + @Query("key") key : String = PLACES_API_KEY, @Query("location") location : String, @Query("keyword") keyword :String?, @Query("language") language :String?, @@ -136,7 +141,7 @@ internal interface DianaService{ * */ @GET("findplacefromtext/${OUTPUT_FORMAT}") fun findPlace( - @Query("key") key : String, + @Query("key") key : String = PLACES_API_KEY, @Query("input") input : String, @Query("inputtype") inputtype :String, diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt index fce976e..e22d831 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt @@ -1,6 +1,5 @@ package com.github.urmichm.placesearchktx.placesearch -import com.github.urmichm.placesearchktx.Diana import com.github.urmichm.placesearchktx.containers.TextSearchContainer import com.github.urmichm.placesearchktx.network.Network import com.github.urmichm.placesearchktx.priceNotInRange @@ -17,8 +16,6 @@ import kotlin.Exception * */ class TextSearch private constructor(private val builder: Builder){ - private val diana : Diana = builder.diana - private val query :String = builder.getQuery() private val language :String? = builder.getLanguage() @@ -40,7 +37,7 @@ class TextSearch private constructor(private val builder: Builder){ private var type : Place.Type? = builder.getType() - class Builder(val diana : Diana) { + class Builder() { /** * The text string on which to search, for example: "restaurant" or "123 Main Street". @@ -287,7 +284,6 @@ class TextSearch private constructor(private val builder: Builder){ suspend fun call() : TextSearchContainer?{ val textSearch : Deferred = Network.service.textSearch( - key = diana.key, query = query, language = language, location = location, diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt index 91e5eb5..3d9c8e6 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/TextSearchTest.kt @@ -1,30 +1,22 @@ package com.github.urmichm.placesearchktx.placesearch -import com.github.urmichm.placesearchktx.Diana import org.junit.Assert.* -import org.junit.Before import org.junit.Test class TextSearchTest { - private lateinit var d : Diana - - @Before - fun initDiana(){ - d = Diana("YOUR_API_KEY") - } @Test fun queryParamNotSpecified(){ assertThrows(UninitializedPropertyAccessException::class.java) { - TextSearch.Builder(d) + TextSearch.Builder() .build() } } @Test fun queryParamSpecified(){ - val textSearch = TextSearch.Builder(d) + val textSearch = TextSearch.Builder() .setQuery("query") .build() assertNotNull(textSearch) @@ -32,7 +24,7 @@ class TextSearchTest { @Test fun maxPriceOutOfRange(){ - val textSearch = TextSearch.Builder(d) + val textSearch = TextSearch.Builder() .setQuery("query") .setMaxPrice(6) @@ -43,7 +35,7 @@ class TextSearchTest { @Test fun minPriceOutOfRange(){ - val textSearch = TextSearch.Builder(d) + val textSearch = TextSearch.Builder() .setQuery("query") .setMinPrice(-1) @@ -54,7 +46,7 @@ class TextSearchTest { @Test fun regionIsIncorrect(){ - val textSearch = TextSearch.Builder(d) + val textSearch = TextSearch.Builder() .setQuery("query") .setRegion("pll") From a90ed25c8dd9525993eef7c42e131027808b2125 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Jun 2022 21:38:22 +0200 Subject: [PATCH 12/16] diana removed II --- .../placesearch/NearbySearch.kt | 5 +--- .../placesearch/NearbySearchTest.kt | 25 ++++++------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt index 8b8b341..879a6b6 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt @@ -17,8 +17,6 @@ import kotlin.Exception * */ class NearbySearch private constructor(private val builder : Builder){ - private val diana : Diana = builder.diana - private val location :String = builder.getLocation() private val keyword :String? = builder.getKeyword() @@ -40,7 +38,7 @@ class NearbySearch private constructor(private val builder : Builder){ private val type : Place.Type? = builder.getType() - class Builder(val diana : Diana){ + class Builder(){ /** * The required parameter. @@ -290,7 +288,6 @@ class NearbySearch private constructor(private val builder : Builder){ val nearby: Deferred = Network.service.nearbySearch( - key = diana.key, location = location, keyword = keyword, language = language, diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt index 064eafe..9becd92 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/NearbySearchTest.kt @@ -1,24 +1,15 @@ package com.github.urmichm.placesearchktx.placesearch -import com.github.urmichm.placesearchktx.Diana import com.google.android.gms.maps.model.LatLng import org.junit.Assert.* -import org.junit.Before import org.junit.Test import kotlin.IllegalArgumentException class NearbySearchTest{ - private lateinit var d :Diana - @Before - fun initDiana(){ - d = Diana("YOUR_API_KEY") - } - - @Test fun minPriceIsOutOfRange(){ - val nearbySearch = NearbySearch.Builder(d) + val nearbySearch = NearbySearch.Builder() .setMinPrice(6) .setLocation(LatLng(0.0,0.0)) @@ -29,7 +20,7 @@ class NearbySearchTest{ @Test fun maxPriceIsOutOfRange(){ - val nearbySearch = NearbySearch.Builder(d) + val nearbySearch = NearbySearch.Builder() .setMinPrice(2) .setMaxPrice(5) .setLocation(LatLng(0.0,0.0)) @@ -41,7 +32,7 @@ class NearbySearchTest{ @Test fun radiusParameterIsOmittedWhenRankedByProminence(){ - val nearbySearch = NearbySearch.Builder(d) + val nearbySearch = NearbySearch.Builder() .setMinPrice(2) .setMaxPrice(4) .setLocation(LatLng(0.0,0.0)) @@ -53,7 +44,7 @@ class NearbySearchTest{ @Test fun radiusParameterIsGivenWhenRankedByDistance(){ - val nearbySearch = NearbySearch.Builder(d) + val nearbySearch = NearbySearch.Builder() .setRankBy(NearbySearch.Rankby.DISTANCE) .setRadius(5000) .setMinPrice(2) @@ -67,7 +58,7 @@ class NearbySearchTest{ @Test fun validWhenRankedByDistanceAndRadiusOmitted(){ - val nearbySearch = NearbySearch.Builder(d) + val nearbySearch = NearbySearch.Builder() .setRankBy(NearbySearch.Rankby.DISTANCE) .setMinPrice(2) .setMaxPrice(4) @@ -79,7 +70,7 @@ class NearbySearchTest{ @Test fun validWhenRankedByProminenceAndRadiusGiven(){ - val nearbySearch = NearbySearch.Builder(d) + val nearbySearch = NearbySearch.Builder() .setRadius(1000) .setMinPrice(2) .setMaxPrice(4) @@ -92,9 +83,7 @@ class NearbySearchTest{ @Test fun locationNotProvided() { - val diana = d - - val builder = NearbySearch.Builder(diana) + val builder = NearbySearch.Builder() assertThrows(Exception::class.java) { builder.build() From 05749ac3294b95ac9d134c720b1ebb8b9f8fb8f6 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Jun 2022 21:42:48 +0200 Subject: [PATCH 13/16] diana removed III --- .../placesearchktx/placesearch/FindPlace.kt | 6 +---- .../placesearch/FindPlaceTest.kt | 27 +++++++------------ 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt index 8786494..3752b4d 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt @@ -1,6 +1,5 @@ package com.github.urmichm.placesearchktx.placesearch -import com.github.urmichm.placesearchktx.Diana import com.github.urmichm.placesearchktx.containers.FindPlaceContainer import com.github.urmichm.placesearchktx.network.Network import com.github.urmichm.placesearchktx.toRequestString @@ -16,8 +15,6 @@ import kotlinx.coroutines.Deferred * */ class FindPlace private constructor(private val builder :Builder) { - private val diana : Diana = builder.diana; - private val input :String = builder.getInput() private val inputtype :String = builder.getInputType().toString() @@ -29,7 +26,7 @@ class FindPlace private constructor(private val builder :Builder) { private var locationbias :String? = builder.getLocationBias() - class Builder(val diana: Diana) { + class Builder() { /** * The required parameter. @@ -276,7 +273,6 @@ class FindPlace private constructor(private val builder :Builder) { val find : Deferred = Network.service.findPlace( - key = diana.key, input = input, inputtype = inputtype, fields = fields, diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt index 62a31b2..35aa13c 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/placesearch/FindPlaceTest.kt @@ -1,26 +1,17 @@ package com.github.urmichm.placesearchktx.placesearch -import com.github.urmichm.placesearchktx.Diana import com.google.android.gms.maps.model.LatLng import com.google.android.libraries.places.api.model.Place import com.google.android.libraries.places.api.model.RectangularBounds import org.junit.Assert.* -import org.junit.Before import org.junit.Test class FindPlaceTest { - private lateinit var d : Diana - - @Before - fun initDiana(){ - d = Diana("YOUR_API_KEY") - } - @Test fun findPlaceBuiltSuccessfully() { - val findPlace = FindPlace.Builder(d) + val findPlace = FindPlace.Builder() .setInput("input") .setInputType(FindPlace.InputType.TEXTQUERY) .build() @@ -31,7 +22,7 @@ class FindPlaceTest { @Test fun findPlaceBuildFailedInputNotProvided() { assertThrows(UninitializedPropertyAccessException::class.java) { - FindPlace.Builder(d) + FindPlace.Builder() .setInputType(FindPlace.InputType.TEXTQUERY) .build() } @@ -40,7 +31,7 @@ class FindPlaceTest { @Test fun findPlaceBuildFailedInputTypeNotProvided() { assertThrows(UninitializedPropertyAccessException::class.java) { - FindPlace.Builder(d) + FindPlace.Builder() .setInput("input") .build() } @@ -49,14 +40,14 @@ class FindPlaceTest { @Test fun findPlaceBuildFailed() { assertThrows(UninitializedPropertyAccessException::class.java) { - FindPlace.Builder(d) + FindPlace.Builder() .build() } } @Test fun settersAndGettersRequiredFields() { - val findPlaceBuilder = FindPlace.Builder(d) + val findPlaceBuilder = FindPlace.Builder() .setInput("input") .setInputType(FindPlace.InputType.TEXTQUERY) @@ -72,7 +63,7 @@ class FindPlaceTest { @Test fun settersGettersLanguage(){ - val findPlaceBuilder = FindPlace.Builder(d) + val findPlaceBuilder = FindPlace.Builder() .setInput("input") .setInputType(FindPlace.InputType.TEXTQUERY) .setLanguage("en") @@ -100,7 +91,7 @@ class FindPlaceTest { Place.Field.WEBSITE_URI, Place.Field.RATING ) - val findPlaceBuilder = FindPlace.Builder(d) + val findPlaceBuilder = FindPlace.Builder() .setInput("input") .setInputType(FindPlace.InputType.TEXTQUERY) .setFields(fieldsAsPlaceField) @@ -141,7 +132,7 @@ class FindPlaceTest { FindPlace.Field.OPEN_NOW, FindPlace.Field.RATING ) - val findPlaceBuilder = FindPlace.Builder(d) + val findPlaceBuilder = FindPlace.Builder() .setInput("input") .setInputType(FindPlace.InputType.TEXTQUERY) .setFields(fieldsAsFindPlaceField) @@ -179,7 +170,7 @@ class FindPlaceTest { val lng :Double = 45.12 val radius :Double = 350.0 - val findPlaceBuilder = FindPlace.Builder(d) + val findPlaceBuilder = FindPlace.Builder() .setInput("input") .setInputType(FindPlace.InputType.TEXTQUERY) From 844f98e065417735608cc870348ce08980d2425d Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Jun 2022 21:49:54 +0200 Subject: [PATCH 14/16] diana removed IV --- .../com/github/urmichm/demo/MainActivity.kt | 1 - .../github/urmichm/placesearchktx/Diana.kt | 15 ------ .../common/PlaceDetailsContainer.kt | 1 - .../urmichm/placesearchktx/DianaTest.kt | 47 ------------------- .../containers/PlaceDetailsContainerTest.kt | 1 - 5 files changed, 65 deletions(-) delete mode 100644 placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt delete mode 100644 placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt diff --git a/app/src/main/java/com/github/urmichm/demo/MainActivity.kt b/app/src/main/java/com/github/urmichm/demo/MainActivity.kt index 9241110..b8ba202 100644 --- a/app/src/main/java/com/github/urmichm/demo/MainActivity.kt +++ b/app/src/main/java/com/github/urmichm/demo/MainActivity.kt @@ -3,7 +3,6 @@ package com.github.urmichm.demo import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log -import com.github.urmichm.placesearchktx.Diana import com.github.urmichm.placesearchktx.placesearch.FindPlace import com.github.urmichm.placesearchktx.placesearch.NearbySearch import com.github.urmichm.placesearchktx.placesearch.TextSearch diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt deleted file mode 100644 index 71472de..0000000 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/Diana.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.urmichm.placesearchktx - -import android.util.Log - -/** - * Main class where all intialization takes place - * - * - * Place Search requests return a subset of the fields that are returned by Place Details requests. - * If the field you want is not returned by Place Search, you can use Place Search to get a place_id, - * then use that Place ID to make a Place Details request. - * */ -class Diana ( - internal val key: String -) \ No newline at end of file diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt index 89cef18..337b05d 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt @@ -2,7 +2,6 @@ package com.github.urmichm.placesearchktx.containers.common import android.os.Build import android.util.Log -import com.github.urmichm.placesearchktx.Diana import com.google.android.libraries.places.api.model.Place import com.squareup.moshi.Json diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt deleted file mode 100644 index 84f41b0..0000000 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/DianaTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.github.urmichm.placesearchktx - -import org.junit.Assert.* - -import org.junit.Test - -class DianaTest { - - @Test - fun testDianaKey(){ - val key = "my-key" - val d = Diana(key) - assertEquals(key,d.key) - } - - -// @Test -// fun nearbySearch() { -// val PLACES_API_KEY : String = YOUR_KEY -// var complete = false -// -// val type = "tourist_attraction" -// val latLng = "52.249787,21.012575" -// val rankby = "distance" -// -// val diana = Diana.Builder(PLACES_API_KEY) -// .setVicinity2Address(true) -// .build() -// -// CoroutineScope(Dispatchers.IO).launch{ -// val response = diana.nearbySearch(type, latLng, rankby) -// response?.let { -// assertEquals("OK", response.status) -// val p = response.results[0].asPlace() -// -//// println("All results:\n${response.results}") -//// println(p) -// -// assertEquals(response.results[0].name, p.name) -// complete = true -// } -// } -// -// Thread.sleep(5_000) -// assertTrue(complete) -// } -} \ No newline at end of file diff --git a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt index a2325fc..88f3d12 100644 --- a/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt +++ b/placesearch-ktx/src/test/java/com/github/urmichm/placesearchktx/containers/PlaceDetailsContainerTest.kt @@ -1,6 +1,5 @@ package com.github.urmichm.placesearchktx.containers -import com.github.urmichm.placesearchktx.Diana import com.github.urmichm.placesearchktx.containers.common.* import com.google.android.libraries.places.api.model.Place import org.junit.Assert.* From 26fdf2bddfb8d42f46decc687be2c42c1f546c6f Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Jun 2022 21:52:19 +0200 Subject: [PATCH 15/16] cosmetic changes --- .../placesearchktx/containers/common/PlaceDetailsContainer.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt index 337b05d..9dd982d 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/containers/common/PlaceDetailsContainer.kt @@ -1,7 +1,5 @@ package com.github.urmichm.placesearchktx.containers.common -import android.os.Build -import android.util.Log import com.google.android.libraries.places.api.model.Place import com.squareup.moshi.Json From 4597fc9a0ccae452cda7dcde6a25bc6c4beaa09d Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 7 Jun 2022 21:45:13 +0200 Subject: [PATCH 16/16] empty lines removed --- .../urmichm/placesearchktx/placesearch/FindPlace.kt | 4 ---- .../urmichm/placesearchktx/placesearch/NearbySearch.kt | 9 --------- .../urmichm/placesearchktx/placesearch/TextSearch.kt | 9 --------- 3 files changed, 22 deletions(-) diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt index 3752b4d..62539dd 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/FindPlace.kt @@ -16,13 +16,9 @@ import kotlinx.coroutines.Deferred class FindPlace private constructor(private val builder :Builder) { private val input :String = builder.getInput() - private val inputtype :String = builder.getInputType().toString() - private var fields :String? = builder.getFields() - private var language :String? = builder.getLanguage() - private var locationbias :String? = builder.getLocationBias() diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt index 879a6b6..cf3350f 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/NearbySearch.kt @@ -18,23 +18,14 @@ import kotlin.Exception class NearbySearch private constructor(private val builder : Builder){ private val location :String = builder.getLocation() - private val keyword :String? = builder.getKeyword() - private val language :String? = builder.getLanguage() - private val maxPrice :Int? = builder.getMaxPrice() - private val minPrice :Int? = builder.getMinPrice() - private val openNow :Boolean? = builder.getOpenNow() - private val pageToken :String? = builder.getPageToken() - private val radius :Int? = builder.getRadius() - private val rankBy : Rankby? = builder.getRankBy() - private val type : Place.Type? = builder.getType() diff --git a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt index e22d831..01f545d 100644 --- a/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt +++ b/placesearch-ktx/src/main/java/com/github/urmichm/placesearchktx/placesearch/TextSearch.kt @@ -17,23 +17,14 @@ import kotlin.Exception class TextSearch private constructor(private val builder: Builder){ private val query :String = builder.getQuery() - private val language :String? = builder.getLanguage() - private val location : String? = builder.getLocation() - private var maxPrice :Int? = builder.getMaxPrice() - private var minPrice :Int? = builder.getMinPrice() - private var openNow :Boolean? = builder.getOpenNow() - private var pageToken :String? = builder.getPageToken() - private var radius :Int? = builder.getRadius() - private var region :String? = builder.getRegion() - private var type : Place.Type? = builder.getType()