Skip to content

Commit

Permalink
Merge pull request #33 from urmichm/issue-32-proper-refactor
Browse files Browse the repository at this point in the history
Issue 32 proper refactor
  • Loading branch information
urmichm committed Jun 7, 2022
2 parents 14b0cc1 + 4597fc9 commit dfedb02
Show file tree
Hide file tree
Showing 18 changed files with 246 additions and 421 deletions.
9 changes: 9 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
Expand Down Expand Up @@ -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'
}
12 changes: 9 additions & 3 deletions app/src/main/java/com/github/urmichm/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package com.github.urmichm.demo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.github.urmichm.placesearchktx.Diana
import android.util.Log
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()
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions local.defaults.properties
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 10 additions & 1 deletion placesearch-ktx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -75,4 +76,12 @@ afterEvaluate {
}
}
}
}
}

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'
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.urmichm.placesearchktx.containers.common

import android.os.Build
import com.github.urmichm.placesearchktx.Diana
import com.google.android.libraries.places.api.model.Place
import com.squareup.moshi.Json

Expand Down Expand Up @@ -50,7 +48,6 @@ data class PlaceDetailsContainer(

/**
* Converts [PlaceDetailsContainer] into [Place] object
* @warning Requires API [Build.VERSION_CODES.N]
* */
fun asPlace() : Place{
val placeBuilder = Place.builder()
Expand All @@ -67,8 +64,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 */
Expand All @@ -80,8 +75,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) {
println("WARN: Vicinity is used as address")
placeBuilder.setAddress(this.vicinity)
}

return placeBuilder.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.urmichm.placesearchktx.network

import com.github.urmichm.placesearchktx.Diana.Companion.OUTPUT_FORMAT
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
Expand All @@ -14,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
Expand All @@ -23,6 +27,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
Expand Down Expand Up @@ -55,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?,
Expand Down Expand Up @@ -95,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?,
Expand Down Expand Up @@ -133,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,
Expand All @@ -157,7 +165,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
Expand All @@ -167,6 +175,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
}

0 comments on commit dfedb02

Please sign in to comment.