Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit 9b66728

Browse files
committed
Removed anko click handlers
1 parent 95c5e9f commit 9b66728

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ dependencies {
3434
compile "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
3535

3636
// Coroutine listeners for Anko Layouts
37-
compile "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
38-
compile "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"
37+
// compile "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
38+
// compile "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"
3939
}
4040

4141
repositories {

app/src/main/java/com/q42/milightremotecontrol/MainActivity.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.support.v7.app.AppCompatActivity
55
import android.util.Log
66
import kotlinx.android.synthetic.main.activity_main.*
77
import kotlinx.coroutines.*
8-
import org.jetbrains.anko.sdk25.coroutines.onClick
98
import org.jetbrains.anko.toast
109
import java.net.InetAddress
1110
import java.net.UnknownHostException
@@ -30,34 +29,38 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
3029
setContentView(R.layout.activity_main)
3130

3231
launch(Dispatchers.IO) {
33-
try {
34-
controller = MiLightController(InetAddress.getByName(bridge))
32+
val ip = try {
33+
InetAddress.getByName(bridge)
3534
} catch (ex: UnknownHostException) {
3635
withContext(Dispatchers.Main) {
3736
toast("Error while looking for bridge:\n${ex.message}")
3837
}
38+
null
39+
}
40+
ip?.let {
41+
controller = MiLightController(ip)
3942
}
4043
}
4144

42-
on_button.onClick {
45+
on_button.setOnClickListener {
4346
Log.i(TAG, "Turning lights on")
4447
launch(Dispatchers.IO) {
4548
try {
4649
controller.turnOn()
47-
} catch(ex: Exception) {
50+
} catch (ex: Exception) {
4851
withContext(Dispatchers.Main) {
4952
toast("Error turning on lights:\n${ex.message}")
5053
}
5154
}
5255
}
5356
}
5457

55-
off_button.onClick {
58+
off_button.setOnClickListener {
5659
Log.i(TAG, "Turning lights off")
5760
launch(Dispatchers.IO) {
5861
try {
5962
controller.turnOff()
60-
} catch(ex: Exception) {
63+
} catch (ex: Exception) {
6164
withContext(Dispatchers.Main) {
6265
toast("Error turning off lights:\n${ex.message}")
6366
}
@@ -66,6 +69,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
6669
}
6770
}
6871

72+
6973
override fun onDestroy() {
7074
super.onDestroy()
7175
job.cancel() // Cancel job on activity destroy. After destroy all children jobs will be cancelled automatically

0 commit comments

Comments
 (0)