Skip to content

Commit

Permalink
refact: library revamp (#23)
Browse files Browse the repository at this point in the history
- Update Kotlin version to `1.4.31`
- Replace deprecated plugin `kotlin-android-extension`
- Migrate from android support to androidx
- Disable stop listening button click for Android 9 and 10
- Replace deprecated release process
  • Loading branch information
aallam committed Mar 12, 2021
2 parents 404c844 + 1e0594e commit 96e7d9c
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 188 deletions.
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion sdkCompile
Expand All @@ -10,7 +9,7 @@ android {
targetSdkVersion sdkTarget
versionCode versioningCode
versionName versioningName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
Expand All @@ -21,6 +20,9 @@ android {
sourceSets {
main.java.srcDirs += "src/main/kotlin"
}
buildFeatures {
viewBinding true
}
}

dependencies {
Expand All @@ -30,10 +32,13 @@ dependencies {
implementation dependency_android.design
implementation dependency_android.constraint_layout

implementation dependency_android.voice
implementation project(":voice")

androidTestImplementation dependency_android.junit
androidTestImplementation dependency_android.test_rules
androidTestImplementation dependency_android.test_runner
androidTestImplementation dependency_android.test_ext_junit
androidTestImplementation dependency_android.espresso

debugImplementation dependency_android.leakcanary
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package com.algolia.instantsearch.voice.demo;


import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

/**
* Tests the behavior of the application when no permission are set.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package com.algolia.instantsearch.voice.demo;

import android.Manifest;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.rule.GrantPermissionRule;
import android.support.test.runner.AndroidJUnit4;
import android.os.Build;
import androidx.test.espresso.ViewInteraction;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.filters.LargeTest;
import androidx.test.filters.SdkSuppress;
import androidx.test.rule.ActivityTestRule;
import androidx.test.rule.GrantPermissionRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import junit.framework.AssertionFailedError;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

@RunWith(AndroidJUnit4.class)
@LargeTest
Expand Down Expand Up @@ -52,13 +55,16 @@ public void clickInputButton_displaysInputOverlay() {
check_displaysListeningOrError();
}

// This test fails for Android 9 and 10. `stopListening()` is not behaving as expected.
// @see: https://issuetracker.google.com/issues/158198432
@SdkSuppress(maxSdkVersion = Build.VERSION_CODES.P)
@Test
public void clickInput_thenCancel_displaysError() {
when_clickButtonVoice();

// Then clicking on the mic button
onView(withId(R.id.microphone))
.perform(click());
ViewInteraction viewInteraction = onView(withId(R.id.microphone));
viewInteraction.perform(click());

check_displaysError();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.algolia.instantsearch.voice.demo

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import androidx.appcompat.app.AppCompatActivity
import android.view.View
import com.algolia.instantsearch.voice.VoiceSpeechRecognizer
import com.algolia.instantsearch.voice.demo.databinding.MainBinding
import com.algolia.instantsearch.voice.ui.Voice
import com.algolia.instantsearch.voice.ui.Voice.isRecordAudioPermissionGranted
import com.algolia.instantsearch.voice.ui.Voice.shouldExplainPermission
import com.algolia.instantsearch.voice.ui.Voice.showPermissionRationale
import com.algolia.instantsearch.voice.ui.VoiceInputDialogFragment
import com.algolia.instantsearch.voice.ui.VoicePermissionDialogFragment
import kotlinx.android.synthetic.main.main.*
import kotlinx.android.synthetic.main.main.view.*


class MainActivity : AppCompatActivity(), VoiceSpeechRecognizer.ResultsListener {

Expand All @@ -21,28 +19,36 @@ class MainActivity : AppCompatActivity(), VoiceSpeechRecognizer.ResultsListener
Voice
}

private lateinit var binding: MainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
binding = MainBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)

main.buttonVoice.setOnClickListener { _ ->
binding.buttonVoice.setOnClickListener { _ ->
if (!isRecordAudioPermissionGranted()) {
VoicePermissionDialogFragment().show(supportFragmentManager, Tag.Permission.name)
} else {
showVoiceDialog()
}
}

main.buttonPermission.setOnClickListener {
binding.buttonPermission.setOnClickListener {
VoicePermissionDialogFragment().show(supportFragmentManager, Tag.Permission.name)
}
}

override fun onResults(possibleTexts: Array<out String>) {
main.results.text = possibleTexts.firstOrNull()?.capitalize()
binding.results.text = possibleTexts.firstOrNull()?.capitalize()
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (Voice.isRecordPermissionWithResults(requestCode, grantResults)) {
when {
Expand All @@ -64,10 +70,12 @@ class MainActivity : AppCompatActivity(), VoiceSpeechRecognizer.ResultsListener
}
}

private fun getVoiceDialog() = (supportFragmentManager.findFragmentByTag(Tag.Voice.name) as? VoiceInputDialogFragment)

private fun getPermissionDialog() = (supportFragmentManager.findFragmentByTag(Tag.Permission.name) as? VoicePermissionDialogFragment)
private fun getVoiceDialog() =
(supportFragmentManager.findFragmentByTag(Tag.Voice.name) as? VoiceInputDialogFragment)

private fun getPermissionView(): View = getPermissionDialog()!!.view!!.findViewById(R.id.positive)
private fun getPermissionDialog() =
(supportFragmentManager.findFragmentByTag(Tag.Permission.name) as? VoicePermissionDialogFragment)

private fun getPermissionView(): View =
getPermissionDialog()!!.view!!.findViewById(R.id.positive)
}
8 changes: 4 additions & 4 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
<androidx.constraintlayout.widget.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"
Expand All @@ -20,7 +20,7 @@
app:layout_constraintBottom_toTopOf="@id/buttonVoice"
android:layout_height="wrap_content"/>

<android.support.design.button.MaterialButton
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonVoice"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -40,7 +40,7 @@
android:layout_width="0dp"
android:layout_height="56dp"/>

<android.support.design.button.MaterialButton
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonPermission"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
app:layout_constraintEnd_toEndOf="@id/buttonVoice"
Expand All @@ -56,4 +56,4 @@
android:layout_width="0dp"
android:layout_height="56dp"/>

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ buildscript {

repositories {
google()
jcenter()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "com.github.ben-manes:gradle-versions-plugin:$benManes"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlins"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray"
classpath "com.github.dcendents:android-maven-gradle-plugin:$maven"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin"
classpath "com.vanniktech:gradle-maven-publish-plugin:$mavenpublish"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka"
}
}

allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
buildscript {
Expand Down
45 changes: 23 additions & 22 deletions dependency.gradle
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
ext.with {
sdkCompile = 28
sdkCompile = 30
sdkMin = 16
sdkTarget = 28
sdkTarget = 30

versioningName = '1.0'
versioningCode = 1

benManes = '0.20.0'
jvm = '1.8'

appcompat = '28.0.0'
design = '28.0.0'
constraintLayout = '1.1.2'
espresso = '3.0.2'
appcompat = '1.2.0'
design = '1.3.0'
constraintLayout = '2.0.4'
espresso = '3.3.0'

kotlins = '1.3.11'
dokka = '0.9.17'
kotlin = '1.4.31'
dokka = '1.4.20'

bintray = '1.8.4'
maven = '2.1'
mavenpublish = '0.14.2'

junit = '4.12'
test = '1.0.2'
test = '1.3.0'
testExt = '1.1.2'

voice = '1.+'
leakcanary = '2.6'

dependency_jvm = [
kotlin_stdlib : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlins",
kotlin_test : "org.jetbrains.kotlin:kotlin-test:$kotlins",
kotlin_test_junit: "org.jetbrains.kotlin:kotlin-test-junit:$kotlins"
kotlin_stdlib : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin",
kotlin_test : "org.jetbrains.kotlin:kotlin-test:$kotlin",
kotlin_test_junit: "org.jetbrains.kotlin:kotlin-test-junit:$kotlin"
]
dependency_android = [
appcompat : "com.android.support:appcompat-v7:$appcompat",
constraint_layout: "com.android.support.constraint:constraint-layout:$constraintLayout",
espresso : "com.android.support.test.espresso:espresso-core:$espresso",
design : "com.android.support:design:$design",
appcompat : "androidx.appcompat:appcompat:$appcompat",
constraint_layout: "androidx.constraintlayout:constraintlayout:$constraintLayout",
espresso : "androidx.test.espresso:espresso-core:$espresso",
design : "com.google.android.material:material:$design",
junit : "junit:junit:$junit",
test_rules : "com.android.support.test:rules:$test",
test_runner : "com.android.support.test:runner:$test",
voice : "com.algolia.instantsearch:voice:$voice"
test_rules : "androidx.test:rules:$test",
test_runner : "androidx.test:runner:$test",
test_ext_junit : "androidx.test.ext:junit:$testExt",
leakcanary : "com.squareup.leakcanary:leakcanary-android:$leakcanary"
]
}
16 changes: 16 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# POM
GROUP=com.algolia.instantsearch
VERSION_NAME=1.1.0
POM_DESCRIPTION=An overlay that gets your user's voice permission and input as text
POM_URL=https://github.com/algolia/voice-overlay-android
POM_SCM_URL=https://github.com/algolia/voice-overlay-android
POM_SCM_CONNECTION=scm:git:git://github.com/algolia/voice-overlay-android.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/algolia/voice-overlay-android.git
POM_LICENCE_NAME=MIT
POM_LICENCE_URL=http://www.opensource.org/licenses/mit-license.php
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=algolia
POM_DEVELOPER_NAME=The Algolia Team
POM_DEVELOPER_EMAIL=hey@algolia.com
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 29 09:57:01 CEST 2018
#Wed Mar 10 15:27:32 CET 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
Loading

0 comments on commit 96e7d9c

Please sign in to comment.