Skip to content

Commit 96e7d9c

Browse files
authored
refact: library revamp (#23)
- 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
2 parents 404c844 + 1e0594e commit 96e7d9c

21 files changed

+230
-188
lines changed

app/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
43

54
android {
65
compileSdkVersion sdkCompile
@@ -10,7 +9,7 @@ android {
109
targetSdkVersion sdkTarget
1110
versionCode versioningCode
1211
versionName versioningName
13-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1413
}
1514
buildTypes {
1615
release {
@@ -21,6 +20,9 @@ android {
2120
sourceSets {
2221
main.java.srcDirs += "src/main/kotlin"
2322
}
23+
buildFeatures {
24+
viewBinding true
25+
}
2426
}
2527

2628
dependencies {
@@ -30,10 +32,13 @@ dependencies {
3032
implementation dependency_android.design
3133
implementation dependency_android.constraint_layout
3234

33-
implementation dependency_android.voice
35+
implementation project(":voice")
3436

3537
androidTestImplementation dependency_android.junit
3638
androidTestImplementation dependency_android.test_rules
3739
androidTestImplementation dependency_android.test_runner
40+
androidTestImplementation dependency_android.test_ext_junit
3841
androidTestImplementation dependency_android.espresso
42+
43+
debugImplementation dependency_android.leakcanary
3944
}

app/src/androidTest/java/com/algolia/instantsearch/voice/demo/MainActivityNoPermissionTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package com.algolia.instantsearch.voice.demo;
22

33

4-
import android.support.test.filters.LargeTest;
5-
import android.support.test.rule.ActivityTestRule;
6-
import android.support.test.runner.AndroidJUnit4;
4+
import androidx.test.filters.LargeTest;
5+
import androidx.test.rule.ActivityTestRule;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
77

88
import org.junit.Rule;
99
import org.junit.Test;
1010
import org.junit.runner.RunWith;
1111

12-
import static android.support.test.espresso.Espresso.onView;
13-
import static android.support.test.espresso.action.ViewActions.click;
14-
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
15-
import static android.support.test.espresso.assertion.ViewAssertions.matches;
16-
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
17-
import static android.support.test.espresso.matcher.ViewMatchers.withId;
12+
import static androidx.test.espresso.Espresso.onView;
13+
import static androidx.test.espresso.action.ViewActions.click;
14+
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
15+
import static androidx.test.espresso.assertion.ViewAssertions.matches;
16+
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
17+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
1818

1919
/**
2020
* Tests the behavior of the application when no permission are set.

app/src/androidTest/java/com/algolia/instantsearch/voice/demo/MainActivityWithPermissionTest.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
package com.algolia.instantsearch.voice.demo;
22

33
import android.Manifest;
4-
import android.support.test.espresso.matcher.ViewMatchers;
5-
import android.support.test.filters.LargeTest;
6-
import android.support.test.rule.ActivityTestRule;
7-
import android.support.test.rule.GrantPermissionRule;
8-
import android.support.test.runner.AndroidJUnit4;
4+
import android.os.Build;
5+
import androidx.test.espresso.ViewInteraction;
6+
import androidx.test.espresso.matcher.ViewMatchers;
7+
import androidx.test.filters.LargeTest;
8+
import androidx.test.filters.SdkSuppress;
9+
import androidx.test.rule.ActivityTestRule;
10+
import androidx.test.rule.GrantPermissionRule;
11+
import androidx.test.ext.junit.runners.AndroidJUnit4;
912

1013
import junit.framework.AssertionFailedError;
1114

1215
import org.junit.Rule;
1316
import org.junit.Test;
1417
import org.junit.runner.RunWith;
1518

16-
import static android.support.test.espresso.Espresso.onView;
17-
import static android.support.test.espresso.action.ViewActions.click;
18-
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
19-
import static android.support.test.espresso.assertion.ViewAssertions.matches;
20-
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
21-
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
22-
import static android.support.test.espresso.matcher.ViewMatchers.withId;
23-
import static android.support.test.espresso.matcher.ViewMatchers.withText;
19+
import static androidx.test.espresso.Espresso.onView;
20+
import static androidx.test.espresso.action.ViewActions.click;
21+
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
22+
import static androidx.test.espresso.assertion.ViewAssertions.matches;
23+
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
24+
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
25+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
26+
import static androidx.test.espresso.matcher.ViewMatchers.withText;
2427

2528
@RunWith(AndroidJUnit4.class)
2629
@LargeTest
@@ -52,13 +55,16 @@ public void clickInputButton_displaysInputOverlay() {
5255
check_displaysListeningOrError();
5356
}
5457

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

5965
// Then clicking on the mic button
60-
onView(withId(R.id.microphone))
61-
.perform(click());
66+
ViewInteraction viewInteraction = onView(withId(R.id.microphone));
67+
viewInteraction.perform(click());
6268

6369
check_displaysError();
6470
}

app/src/main/kotlin/com/algolia/instantsearch/voice/demo/MainActivity.kt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package com.algolia.instantsearch.voice.demo
22

33
import android.os.Bundle
4-
import android.support.v7.app.AppCompatActivity
4+
import androidx.appcompat.app.AppCompatActivity
55
import android.view.View
66
import com.algolia.instantsearch.voice.VoiceSpeechRecognizer
7+
import com.algolia.instantsearch.voice.demo.databinding.MainBinding
78
import com.algolia.instantsearch.voice.ui.Voice
89
import com.algolia.instantsearch.voice.ui.Voice.isRecordAudioPermissionGranted
910
import com.algolia.instantsearch.voice.ui.Voice.shouldExplainPermission
1011
import com.algolia.instantsearch.voice.ui.Voice.showPermissionRationale
1112
import com.algolia.instantsearch.voice.ui.VoiceInputDialogFragment
1213
import com.algolia.instantsearch.voice.ui.VoicePermissionDialogFragment
13-
import kotlinx.android.synthetic.main.main.*
14-
import kotlinx.android.synthetic.main.main.view.*
15-
1614

1715
class MainActivity : AppCompatActivity(), VoiceSpeechRecognizer.ResultsListener {
1816

@@ -21,28 +19,36 @@ class MainActivity : AppCompatActivity(), VoiceSpeechRecognizer.ResultsListener
2119
Voice
2220
}
2321

22+
private lateinit var binding: MainBinding
23+
2424
override fun onCreate(savedInstanceState: Bundle?) {
2525
super.onCreate(savedInstanceState)
26-
setContentView(R.layout.main)
26+
binding = MainBinding.inflate(layoutInflater)
27+
val view = binding.root
28+
setContentView(view)
2729

28-
main.buttonVoice.setOnClickListener { _ ->
30+
binding.buttonVoice.setOnClickListener { _ ->
2931
if (!isRecordAudioPermissionGranted()) {
3032
VoicePermissionDialogFragment().show(supportFragmentManager, Tag.Permission.name)
3133
} else {
3234
showVoiceDialog()
3335
}
3436
}
3537

36-
main.buttonPermission.setOnClickListener {
38+
binding.buttonPermission.setOnClickListener {
3739
VoicePermissionDialogFragment().show(supportFragmentManager, Tag.Permission.name)
3840
}
3941
}
4042

4143
override fun onResults(possibleTexts: Array<out String>) {
42-
main.results.text = possibleTexts.firstOrNull()?.capitalize()
44+
binding.results.text = possibleTexts.firstOrNull()?.capitalize()
4345
}
4446

45-
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
47+
override fun onRequestPermissionsResult(
48+
requestCode: Int,
49+
permissions: Array<out String>,
50+
grantResults: IntArray
51+
) {
4652
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
4753
if (Voice.isRecordPermissionWithResults(requestCode, grantResults)) {
4854
when {
@@ -64,10 +70,12 @@ class MainActivity : AppCompatActivity(), VoiceSpeechRecognizer.ResultsListener
6470
}
6571
}
6672

67-
private fun getVoiceDialog() = (supportFragmentManager.findFragmentByTag(Tag.Voice.name) as? VoiceInputDialogFragment)
68-
69-
private fun getPermissionDialog() = (supportFragmentManager.findFragmentByTag(Tag.Permission.name) as? VoicePermissionDialogFragment)
73+
private fun getVoiceDialog() =
74+
(supportFragmentManager.findFragmentByTag(Tag.Voice.name) as? VoiceInputDialogFragment)
7075

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

79+
private fun getPermissionView(): View =
80+
getPermissionDialog()!!.view!!.findViewById(R.id.positive)
7381
}

app/src/main/res/layout/main.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout
2+
<androidx.constraintlayout.widget.ConstraintLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
xmlns:tools="http://schemas.android.com/tools"
@@ -20,7 +20,7 @@
2020
app:layout_constraintBottom_toTopOf="@id/buttonVoice"
2121
android:layout_height="wrap_content"/>
2222

23-
<android.support.design.button.MaterialButton
23+
<com.google.android.material.button.MaterialButton
2424
android:id="@+id/buttonVoice"
2525
app:layout_constraintStart_toStartOf="parent"
2626
app:layout_constraintEnd_toEndOf="parent"
@@ -40,7 +40,7 @@
4040
android:layout_width="0dp"
4141
android:layout_height="56dp"/>
4242

43-
<android.support.design.button.MaterialButton
43+
<com.google.android.material.button.MaterialButton
4444
android:id="@+id/buttonPermission"
4545
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
4646
app:layout_constraintEnd_toEndOf="@id/buttonVoice"
@@ -56,4 +56,4 @@
5656
android:layout_width="0dp"
5757
android:layout_height="56dp"/>
5858

59-
</android.support.constraint.ConstraintLayout>
59+
</androidx.constraintlayout.widget.ConstraintLayout>

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ buildscript {
33

44
repositories {
55
google()
6-
jcenter()
76
mavenCentral()
7+
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.3.2'
10+
classpath 'com.android.tools.build:gradle:4.1.2'
1111
classpath "com.github.ben-manes:gradle-versions-plugin:$benManes"
12-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlins"
13-
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka"
14-
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray"
15-
classpath "com.github.dcendents:android-maven-gradle-plugin:$maven"
12+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin"
13+
classpath "com.vanniktech:gradle-maven-publish-plugin:$mavenpublish"
14+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka"
1615
}
1716
}
1817

1918
allprojects {
2019
repositories {
2120
google()
21+
mavenCentral()
2222
jcenter()
2323
}
2424
buildscript {

dependency.gradle

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
11
ext.with {
2-
sdkCompile = 28
2+
sdkCompile = 30
33
sdkMin = 16
4-
sdkTarget = 28
4+
sdkTarget = 30
55

66
versioningName = '1.0'
77
versioningCode = 1
88

99
benManes = '0.20.0'
1010
jvm = '1.8'
1111

12-
appcompat = '28.0.0'
13-
design = '28.0.0'
14-
constraintLayout = '1.1.2'
15-
espresso = '3.0.2'
12+
appcompat = '1.2.0'
13+
design = '1.3.0'
14+
constraintLayout = '2.0.4'
15+
espresso = '3.3.0'
1616

17-
kotlins = '1.3.11'
18-
dokka = '0.9.17'
17+
kotlin = '1.4.31'
18+
dokka = '1.4.20'
1919

20-
bintray = '1.8.4'
21-
maven = '2.1'
20+
mavenpublish = '0.14.2'
2221

2322
junit = '4.12'
24-
test = '1.0.2'
23+
test = '1.3.0'
24+
testExt = '1.1.2'
2525

26-
voice = '1.+'
26+
leakcanary = '2.6'
2727

2828
dependency_jvm = [
29-
kotlin_stdlib : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlins",
30-
kotlin_test : "org.jetbrains.kotlin:kotlin-test:$kotlins",
31-
kotlin_test_junit: "org.jetbrains.kotlin:kotlin-test-junit:$kotlins"
29+
kotlin_stdlib : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin",
30+
kotlin_test : "org.jetbrains.kotlin:kotlin-test:$kotlin",
31+
kotlin_test_junit: "org.jetbrains.kotlin:kotlin-test-junit:$kotlin"
3232
]
3333
dependency_android = [
34-
appcompat : "com.android.support:appcompat-v7:$appcompat",
35-
constraint_layout: "com.android.support.constraint:constraint-layout:$constraintLayout",
36-
espresso : "com.android.support.test.espresso:espresso-core:$espresso",
37-
design : "com.android.support:design:$design",
34+
appcompat : "androidx.appcompat:appcompat:$appcompat",
35+
constraint_layout: "androidx.constraintlayout:constraintlayout:$constraintLayout",
36+
espresso : "androidx.test.espresso:espresso-core:$espresso",
37+
design : "com.google.android.material:material:$design",
3838
junit : "junit:junit:$junit",
39-
test_rules : "com.android.support.test:rules:$test",
40-
test_runner : "com.android.support.test:runner:$test",
41-
voice : "com.algolia.instantsearch:voice:$voice"
39+
test_rules : "androidx.test:rules:$test",
40+
test_runner : "androidx.test:runner:$test",
41+
test_ext_junit : "androidx.test.ext:junit:$testExt",
42+
leakcanary : "com.squareup.leakcanary:leakcanary-android:$leakcanary"
4243
]
4344
}

gradle.properties

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@
66
# http://www.gradle.org/docs/current/userguide/build_environment.html
77
# Specifies the JVM arguments used for the daemon process.
88
# The setting is particularly useful for tweaking memory settings.
9+
android.useAndroidX=true
910
org.gradle.jvmargs=-Xmx1536m
1011
# When configured, Gradle will run in incubating parallel mode.
1112
# This option should only be used with decoupled projects. More details, visit
1213
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1314
# org.gradle.parallel=true
15+
16+
# POM
17+
GROUP=com.algolia.instantsearch
18+
VERSION_NAME=1.1.0
19+
POM_DESCRIPTION=An overlay that gets your user's voice permission and input as text
20+
POM_URL=https://github.com/algolia/voice-overlay-android
21+
POM_SCM_URL=https://github.com/algolia/voice-overlay-android
22+
POM_SCM_CONNECTION=scm:git:git://github.com/algolia/voice-overlay-android.git
23+
POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/algolia/voice-overlay-android.git
24+
POM_LICENCE_NAME=MIT
25+
POM_LICENCE_URL=http://www.opensource.org/licenses/mit-license.php
26+
POM_LICENCE_DIST=repo
27+
POM_DEVELOPER_ID=algolia
28+
POM_DEVELOPER_NAME=The Algolia Team
29+
POM_DEVELOPER_EMAIL=hey@algolia.com
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Aug 29 09:57:01 CEST 2018
1+
#Wed Mar 10 15:27:32 CET 2021
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip

0 commit comments

Comments
 (0)