Skip to content

Commit 04c811f

Browse files
committed
wip: remove kotlin-android-extension
1 parent f95ce0d commit 04c811f

File tree

6 files changed

+63
-32
lines changed

6 files changed

+63
-32
lines changed

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ dependencies {
3636
androidTestImplementation dependency_android.test_rules
3737
androidTestImplementation dependency_android.test_runner
3838
androidTestImplementation dependency_android.espresso
39+
40+
debugImplementation dependency_android.leakcanary
3941
}

dependency.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
@@ -14,7 +14,7 @@ ext.with {
1414
constraintLayout = '1.1.2'
1515
espresso = '3.0.2'
1616

17-
kotlins = '1.3.71'
17+
kotlins = '1.4.31'
1818
dokka = '0.9.17'
1919

2020
bintray = '1.8.4'
@@ -25,6 +25,8 @@ ext.with {
2525

2626
voice = '1.+'
2727

28+
leakcanary = '2.6'
29+
2830
dependency_jvm = [
2931
kotlin_stdlib : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlins",
3032
kotlin_test : "org.jetbrains.kotlin:kotlin-test:$kotlins",
@@ -38,6 +40,7 @@ ext.with {
3840
junit : "junit:junit:$junit",
3941
test_rules : "com.android.support.test:rules:$test",
4042
test_runner : "com.android.support.test:runner:$test",
41-
voice : "com.algolia.instantsearch:voice:$voice"
43+
voice : "com.algolia.instantsearch:voice:$voice",
44+
leakcanary : "com.squareup.leakcanary:leakcanary-android:$leakcanary"
4245
]
4346
}

voice/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'kotlin-android-extensions'
43
apply plugin: 'maven'
54
apply plugin: 'maven-publish'
65
apply plugin: 'com.github.dcendents.android-maven'

voice/src/main/kotlin/com/algolia/instantsearch/voice/ui/VoiceAndroidView.kt

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,42 @@ import android.os.Build
44
import android.support.constraint.ConstraintLayout
55
import android.text.Html
66
import android.view.View
7+
import android.widget.ImageView
8+
import android.widget.TextView
79
import com.algolia.instantsearch.voice.R
8-
import kotlinx.android.synthetic.main.voice_input.view.*
9-
1010

1111
class VoiceAndroidView(
1212
private val view: ConstraintLayout
1313
) : VoiceUI {
1414

1515
private val context = view.context
16-
17-
override val formatterSuggestion = { suggestion: String -> context.getString(R.string.format_voice_suggestion_html, suggestion) }
16+
private val voiceInput: ConstraintLayout get() = view.findViewById(R.id.voiceInput)
17+
private val suggestionsView: TextView? get() = view.findViewById(R.id.voiceInput)
18+
private val ConstraintLayout.close: ImageView get() = findViewById(R.id.close)
19+
private val ConstraintLayout.microphone: VoiceMicrophone get() = findViewById(R.id.microphone)
20+
private val ConstraintLayout.title: TextView get() = findViewById(R.id.microphone)
21+
private val ConstraintLayout.subtitle: TextView get() = findViewById(R.id.subtitle)
22+
private val ConstraintLayout.suggestions: TextView? get() = findViewById(R.id.suggestions)
23+
private val ConstraintLayout.hint: TextView get() = findViewById(R.id.hint)
24+
private val ConstraintLayout.ripple: RippleView get() = findViewById(R.id.ripple)
25+
26+
override val formatterSuggestion = { suggestion: String ->
27+
context.getString(
28+
R.string.format_voice_suggestion_html,
29+
suggestion
30+
)
31+
}
1832

1933
override fun setOnClickListenerClose(onClickListener: View.OnClickListener) {
20-
view.voiceInput.close.setOnClickListener(onClickListener)
34+
voiceInput.close.setOnClickListener(onClickListener)
2135
}
2236

2337
override fun setOnClickMicrophoneListener(onClickListener: View.OnClickListener) {
24-
view.voiceInput.microphone.setOnClickListener(onClickListener)
38+
voiceInput.microphone.setOnClickListener(onClickListener)
2539
}
2640

2741
override fun setSuggestions(suggestions: Array<out String>) {
28-
view.suggestions?.let {
42+
suggestionsView?.let {
2943
val formattedSuggestions = suggestions.joinToString("") { formatterSuggestion(it) }
3044
val html = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
3145
Html.fromHtml(formattedSuggestions, Html.FROM_HTML_MODE_LEGACY)
@@ -37,31 +51,31 @@ class VoiceAndroidView(
3751
}
3852

3953
override fun setTitle(title: VoiceUI.Title) {
40-
view.voiceInput.title.setText(title.resource)
54+
voiceInput.title.setText(title.resource)
4155
}
4256

4357
override fun setSubtitle(subtitle: String) {
44-
view.voiceInput.subtitle.text = subtitle
58+
voiceInput.subtitle.text = subtitle
4559
}
4660

4761
override fun setSubtitle(subtitle: VoiceUI.Subtitle) {
48-
view.voiceInput.subtitle.setText(subtitle.resource)
62+
voiceInput.subtitle.setText(subtitle.resource)
4963
}
5064

5165
override fun setSuggestionVisibility(isVisible: Boolean) {
52-
view.voiceInput.suggestions?.visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
66+
voiceInput.suggestions?.visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
5367
}
5468

5569
override fun setHintVisibility(isVisible: Boolean) {
56-
view.voiceInput.hint.visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
70+
voiceInput.hint.visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
5771
}
5872

5973
override fun setRippleActivity(isActive: Boolean) =
60-
if (isActive) view.voiceInput.ripple.start() else view.voiceInput.ripple.cancel()
74+
if (isActive) voiceInput.ripple.start() else voiceInput.ripple.cancel()
6175

6276
override fun setMicrophoneState(state: VoiceMicrophone.State) {
63-
view.voiceInput.microphone.state = state
77+
voiceInput.microphone.state = state
6478
}
6579

66-
override fun getMicrophoneState(): VoiceMicrophone.State = view.voiceInput.microphone.state
67-
}
80+
override fun getMicrophoneState(): VoiceMicrophone.State = voiceInput.microphone.state
81+
}

voice/src/main/kotlin/com/algolia/instantsearch/voice/ui/VoiceInputDialogFragment.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.algolia.instantsearch.voice.ui
22

33
import android.os.Bundle
4+
import android.support.constraint.ConstraintLayout
45
import android.support.v4.app.DialogFragment
56
import android.view.LayoutInflater
67
import android.view.View
78
import android.view.ViewGroup
89
import com.algolia.instantsearch.voice.R
910
import com.algolia.instantsearch.voice.VoiceSpeechRecognizer
10-
import kotlinx.android.synthetic.main.voice_input.*
11-
1211

1312
class VoiceInputDialogFragment : DialogFragment() {
1413

@@ -55,11 +54,16 @@ class VoiceInputDialogFragment : DialogFragment() {
5554
suggestions = arguments?.getStringArray(Field.Suggestions.name)
5655
}
5756

58-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =
57+
override fun onCreateView(
58+
inflater: LayoutInflater,
59+
container: ViewGroup?,
60+
savedInstanceState: Bundle?
61+
): View? =
5962
inflater.inflate(R.layout.voice_input, container, false)
6063

6164
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
6265
super.onViewCreated(view, savedInstanceState)
66+
val voiceInput = view.findViewById<ConstraintLayout>(R.id.voiceInput)
6367
val androidView = VoiceAndroidView(voiceInput)
6468
val presenter = VoicePresenter(androidView) { result ->
6569
(activity as? VoiceSpeechRecognizer.ResultsListener)?.onResults(result.toTypedArray())

voice/src/main/kotlin/com/algolia/instantsearch/voice/ui/VoicePermissionDialogFragment.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ package com.algolia.instantsearch.voice.ui
22

33
import android.Manifest
44
import android.os.Bundle
5+
import android.support.constraint.ConstraintLayout
56
import android.support.v4.app.ActivityCompat
67
import android.support.v4.app.DialogFragment
78
import android.view.LayoutInflater
89
import android.view.View
910
import android.view.ViewGroup
11+
import android.widget.Button
12+
import android.widget.ImageView
1013
import com.algolia.instantsearch.voice.R
11-
import kotlinx.android.synthetic.main.voice_permission.*
12-
import kotlinx.android.synthetic.main.voice_permission.view.*
13-
1414

1515
class VoicePermissionDialogFragment : DialogFragment() {
1616

@@ -19,18 +19,27 @@ class VoicePermissionDialogFragment : DialogFragment() {
1919
setStyle(DialogFragment.STYLE_NORMAL, R.style.VoiceDialogTheme)
2020
}
2121

22-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
22+
override fun onCreateView(
23+
inflater: LayoutInflater,
24+
container: ViewGroup?,
25+
savedInstanceState: Bundle?
26+
): View? {
2327
return inflater.inflate(R.layout.voice_permission, container, false)
2428
}
2529

2630
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
2731
super.onViewCreated(view, savedInstanceState)
32+
val voicePermission = view.findViewById<ConstraintLayout>(R.id.voicePermission)
2833
voicePermission.let {
29-
it.close.setOnClickListener { dismiss() }
30-
it.positive.setOnClickListener {
31-
ActivityCompat.requestPermissions(requireActivity(), arrayOf(Manifest.permission.RECORD_AUDIO), Voice.PermissionRequestRecordAudio)
34+
it.findViewById<ImageView>(R.id.close).setOnClickListener { dismiss() }
35+
it.findViewById<Button>(R.id.positive).setOnClickListener {
36+
ActivityCompat.requestPermissions(
37+
requireActivity(),
38+
arrayOf(Manifest.permission.RECORD_AUDIO),
39+
Voice.PermissionRequestRecordAudio
40+
)
3241
}
33-
it.negative.setOnClickListener { dismiss() }
42+
it.findViewById<Button>(R.id.negative).setOnClickListener { dismiss() }
3443
}
3544
}
3645
}

0 commit comments

Comments
 (0)