Skip to content

Commit e179d6b

Browse files
committed
refact: remove deprecated kotlin-android-extension
1 parent 04c811f commit e179d6b

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

app/build.gradle

Lines changed: 3 additions & 1 deletion
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
@@ -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 {

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import android.os.Bundle
44
import android.support.v7.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
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class VoiceAndroidView(
1515
private val context = view.context
1616
private val voiceInput: ConstraintLayout get() = view.findViewById(R.id.voiceInput)
1717
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)
18+
private val View.close: ImageView get() = findViewById(R.id.close)
19+
private val View.microphone: VoiceMicrophone get() = findViewById(R.id.microphone)
20+
private val View.title: TextView get() = findViewById(R.id.microphone)
21+
private val View.subtitle: TextView get() = findViewById(R.id.subtitle)
22+
private val View.suggestions: TextView? get() = findViewById(R.id.suggestions)
23+
private val View.hint: TextView get() = findViewById(R.id.hint)
24+
private val View.ripple: RippleView get() = findViewById(R.id.ripple)
2525

2626
override val formatterSuggestion = { suggestion: String ->
2727
context.getString(

0 commit comments

Comments
 (0)