Commit 134c13c6 authored by Stefan Zabka's avatar Stefan Zabka
Browse files

bunch of random cleanup

parent 8e4c68ed
Pipeline #2832 failed with stage
in 7 minutes and 29 seconds
......@@ -22,7 +22,6 @@
package de.ccc.events.badge.card10.hatchery
import android.net.Uri
import android.os.AsyncTask
import android.os.Bundle
import android.util.Log
......@@ -69,7 +68,7 @@ class AppDetailFragment : Fragment() {
val ctx = activity ?: throw java.lang.IllegalStateException()
val loadingDialog = LoadingDialog()
loadingDialog.show(fragmentManager, "loading")
loadingDialog.show(fragmentManager!!, "loading")
val errorDialog =
AlertDialog.Builder(ctx).setMessage(R.string.hatchery_error_generic)
......
......@@ -38,6 +38,7 @@ import de.ccc.events.badge.card10.ROCKETS_CHARACTERISTIC_UUID
import kotlinx.android.synthetic.main.mood_fragment.*
import java.util.concurrent.CountDownLatch
@ExperimentalUnsignedTypes
class MoodFragment : Fragment() {
private val bluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
......@@ -50,13 +51,13 @@ class MoodFragment : Fragment() {
val callback = object : BluetoothGattCallback() {
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
System.out.println("===== onConnectionStateChange " + gatt + " / " + status + " / " + newState)
println("===== onConnectionStateChange " + gatt + " / " + status + " / " + newState)
if (newState == BluetoothGatt.STATE_CONNECTED)
gatt.discoverServices()
}
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
System.out.println("===== onServicesDiscovered " + gatt + " / " + status)
println("===== onServicesDiscovered " + gatt + " / " + status)
val card10Service = gatt.getService(CARD10_SERVICE_UUID)
rocketsCharacteristic = card10Service.getCharacteristic(ROCKETS_CHARACTERISTIC_UUID)
}
......@@ -66,8 +67,8 @@ class MoodFragment : Fragment() {
characteristic: BluetoothGattCharacteristic,
status: Int
) {
System.out.println("===== onCharacteristicWrite " + characteristic.uuid.toString() + " / " + characteristic.value + " / " + status)
writeLatch?.countDown();
println("===== onCharacteristicWrite " + characteristic.uuid.toString() + " / " + characteristic.value + " / " + status)
writeLatch?.countDown()
}
}
......@@ -83,15 +84,15 @@ class MoodFragment : Fragment() {
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
mood_good.setOnClickListener({
writeGatt(rocketsCharacteristic!!, ubyteArrayOf(0xffu, 0x00u, 0x00u).toByteArray())
})
mood_neutral.setOnClickListener({
mood_good.setOnClickListener {
writeGatt(rocketsCharacteristic!!, ubyteArrayOf(0xffu, 0x00u, 0x00u).toByteArray())
}
mood_neutral.setOnClickListener {
writeGatt(rocketsCharacteristic!!, ubyteArrayOf(0x00u, 0xffu, 0x00u).toByteArray())
})
mood_bad.setOnClickListener({
}
mood_bad.setOnClickListener {
writeGatt(rocketsCharacteristic!!, ubyteArrayOf(0x00u, 0x00u, 0xffu).toByteArray())
})
}
}
fun writeGatt(characteristic: BluetoothGattCharacteristic, values: ByteArray) {
......@@ -100,11 +101,11 @@ class MoodFragment : Fragment() {
if (!init)
System.out.println("Failed to initiate writing GATT attribute")
writeLatch = CountDownLatch(1)
writeLatch!!.await();
writeLatch!!.await()
}
override fun onDestroy() {
gatt.close();
gatt.close()
super.onDestroy()
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment