Skip to content

Commit

Permalink
Set up initial contract to autocomplete places (#1)
Browse files Browse the repository at this point in the history
* improve demo sample to test textView observable

* define contract for api and implement initial unit tests with mocks

* creating entities to deserialize json data into domain objects

* add google maps api with retrofit implementation

* create unit tests to cover query window behavior

* add requested changes

* add .travis.yml

* simplify travis.yml

* add jdk to travis.yml

* handle local.properties absece

* solve lint problems

* fix travis.yml to accept all licenses

* fix travis.yml again

* remove constraint layout from dependencies
  • Loading branch information
rodrigohenriques authored and rsicarelli committed Jun 9, 2017
1 parent aa96c7e commit 7df3230
Show file tree
Hide file tree
Showing 23 changed files with 636 additions and 132 deletions.
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: android

android:
components:
# Uncomment the lines below if you want to
# use the latest revision of Android SDK Tools
- tools
- build-tools-25.0.3
- platform-tools
- extra-android-m2repository
- extra-google-android-support

- android-25

licenses:
- android-sdk-license-.+
- '.+'

cache:
directories:
- $HOME/.gradle/caches/2.8
- $HOME/.gradle/caches/jars-1
- $HOME/.gradle/daemon
- $HOME/.gradle/native
- $HOME/.gradle/wrapper

jdk:
- oraclejdk8

script:
- ./gradlew test
14 changes: 12 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.1.2-4'
ext.kotlin_version = '1.1.2-3'
ext.rxjava_version = '1.3.0'
ext.rxandroid_version = '1.2.1'
ext.retrofit_version = "2.2.0"
ext.okhttp_ersion = "3.6.0"
ext.support_version = "25.3.1"
ext.junit_version = "4.12"
ext.hamcrest_version = "1.3"
ext.mockito_kotlin_version = "1.5.0"
ext.espresso_version = "2.2.2"
ext.constraintlayout_version = "1.0.2"

repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
31 changes: 26 additions & 5 deletions demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

String getApiKey() {
try {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
return properties.getProperty('api.key')
} catch (Exception ignored) {}

return "empty"
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.a99.rxplaces"
applicationId "com.a99.rxplaces.demo"
minSdkVersion 15
//noinspection OldTargetApi
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

buildConfigField "String", "GOOGLE_MAPS_API_KEY", "\"${getApiKey()}\""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

lintOptions {
abortOnError false
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(":library")

compile "io.reactivex:rxandroid:$rxandroid_version"
compile "com.android.support:appcompat-v7:$support_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

testCompile 'junit:junit:4.12'

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

repositories {
Expand Down

This file was deleted.

8 changes: 6 additions & 2 deletions demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.a99.rxplaces">
xmlns:tools="http://schemas.android.com/tools"
package="com.a99.rxplaces.demo">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".DemoActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
13 changes: 0 additions & 13 deletions demo/src/main/java/com/a99/rxplaces/DemoActivity.java

This file was deleted.

55 changes: 55 additions & 0 deletions demo/src/main/java/com/a99/rxplaces/demo/DemoActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.a99.rxplaces.demo

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import com.a99.rxplaces.AutocompleteState
import com.a99.rxplaces.Prediction
import com.a99.rxplaces.RxAutocomplete
import rx.android.schedulers.AndroidSchedulers

class DemoActivity : AppCompatActivity() {

val editText by lazy { findViewById(R.id.input) as EditText }
val loading: View by lazy { findViewById(R.id.loading) }
val outputContainer by lazy { findViewById(R.id.outputContainer) as LinearLayout }

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

val rxAutocomplete = RxAutocomplete.create(BuildConfig.GOOGLE_MAPS_API_KEY)

rxAutocomplete.stateStream()
.observeOn(AndroidSchedulers.mainThread())
.subscribe { autocompleteState ->
loading.visibility = when (autocompleteState) {
AutocompleteState.QUERYING -> VISIBLE
else -> GONE
}
}

rxAutocomplete.observe(editText)
.observeOn(AndroidSchedulers.mainThread())
.subscribe { showData(it) }
}

private fun showData(predictions: List<Prediction>) {
outputContainer.removeAllViews()

predictions
.map { createTextView(it) }
.forEach { outputContainer.addView(it) }
}

private fun createTextView(it: Prediction): TextView {
val textView = TextView(this)
textView.text = it.description
return textView
}
}
31 changes: 19 additions & 12 deletions demo/src/main/res/layout/activity_demo.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.a99.rxplaces.DemoActivity">
android:orientation="vertical">

<TextView
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint"/>

<ProgressBar
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
android:visibility="gone"/>

<LinearLayout
android:id="@+id/outputContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />

</LinearLayout>
1 change: 1 addition & 0 deletions demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">RxPlaces</string>
<string name="hint">Where do you want to go?</string>
</resources>
17 changes: 0 additions & 17 deletions demo/src/test/java/com/a99/rxplaces/ExampleUnitTest.java

This file was deleted.

20 changes: 20 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ android {

defaultConfig {
minSdkVersion 15
//noinspection OldTargetApi
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand All @@ -26,12 +27,31 @@ android {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-annotations:$support_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "io.reactivex:rxjava:$rxjava_version"
compile "io.reactivex:rxandroid:$rxandroid_version"
compile "com.squareup.okhttp3:logging-interceptor:$okhttp_ersion"
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"

androidTestCompile("com.android.support.test.espresso:espresso-core:$espresso_version", {
exclude group: 'com.android.support', module: 'support-annotations'
})

testCompile "junit:junit:$junit_version"
testCompile "org.hamcrest:hamcrest-core:$hamcrest_version"
testCompile "org.hamcrest:hamcrest-library:$hamcrest_version"
testCompile "com.nhaarman:mockito-kotlin-kt1.1:$mockito_kotlin_version"
}
repositories {
mavenCentral()
Expand Down

This file was deleted.

Loading

0 comments on commit 7df3230

Please sign in to comment.