From e10cf9b863094d59835d4e8a57c1cdbf3e6f82a5 Mon Sep 17 00:00:00 2001 From: crc-32 Date: Sat, 15 Jun 2024 16:59:36 +0100 Subject: [PATCH] cleanup --- .../app/src/main/kotlin/io/rebble/cobble/MainActivity.kt | 2 +- .../bridges/background/NotificationsFlutterBridge.kt | 6 +++--- .../cobble/bridges/common/PackageDetailsFlutterBridge.kt | 2 +- .../rebble/cobble/bridges/ui/BridgeLifecycleController.kt | 2 +- .../bridges/ui/FirmwareUpdateControlFlutterBridge.kt | 2 +- .../cobble/bridges/ui/PermissionControlFlutterBridge.kt | 4 ++-- .../io/rebble/cobble/datasources/FlutterPreferences.kt | 2 +- .../kotlin/io/rebble/cobble/middleware/AppCompatibility.kt | 2 +- .../main/kotlin/io/rebble/cobble/service/WatchService.kt | 4 ---- .../main/java/io/rebble/cobble/bluetooth/ble/GattStatus.kt | 2 +- .../cobble/bluetooth/classic/ReconnectionSocketServer.kt | 7 +++---- 11 files changed, 15 insertions(+), 20 deletions(-) diff --git a/android/app/src/main/kotlin/io/rebble/cobble/MainActivity.kt b/android/app/src/main/kotlin/io/rebble/cobble/MainActivity.kt index bbaf0c26..d1571de7 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/MainActivity.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/MainActivity.kt @@ -94,7 +94,7 @@ class MainActivity : FlutterActivity() { val code = data.getQueryParameter("code") val state = data.getQueryParameter("state") val error = data.getQueryParameter("error") - oauthIntentCallback?.invoke(code, state, error); + oauthIntentCallback?.invoke(code, state, error) } } } diff --git a/android/app/src/main/kotlin/io/rebble/cobble/bridges/background/NotificationsFlutterBridge.kt b/android/app/src/main/kotlin/io/rebble/cobble/bridges/background/NotificationsFlutterBridge.kt index 761a7dda..67ed4b3f 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/bridges/background/NotificationsFlutterBridge.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/bridges/background/NotificationsFlutterBridge.kt @@ -42,7 +42,7 @@ class NotificationsFlutterBridge @Inject constructor( private val notifUtils = object : Pigeons.NotificationUtils { override fun openNotification(arg: Pigeons.StringWrapper) { - val id = UUID.fromString(arg?.value) + val id = UUID.fromString(arg.value) activeNotifs[id]?.notification?.contentIntent?.send() } @@ -65,7 +65,7 @@ class NotificationsFlutterBridge @Inject constructor( } override fun dismissNotificationWatch(arg: Pigeons.StringWrapper) { - val id = UUID.fromString(arg?.value) + val id = UUID.fromString(arg.value) val command = BlobCommand.DeleteCommand(Random.nextInt(0, UShort.MAX_VALUE.toInt()).toUShort(), BlobCommand.BlobDatabase.Notification, SUUID(StructMapper(), id).toBytes()) GlobalScope.launch { var blobResult = blobDBService.send(command) @@ -85,7 +85,7 @@ class NotificationsFlutterBridge @Inject constructor( ?: Timber.w("Dismiss on untracked notif") } catch (e: PendingIntent.CanceledException) { } - result?.success(BooleanWrapper(true)) + result.success(BooleanWrapper(true)) val command = BlobCommand.DeleteCommand(Random.nextInt(0, UShort.MAX_VALUE.toInt()).toUShort(), BlobCommand.BlobDatabase.Notification, SUUID(StructMapper(), id).toBytes()) GlobalScope.launch { diff --git a/android/app/src/main/kotlin/io/rebble/cobble/bridges/common/PackageDetailsFlutterBridge.kt b/android/app/src/main/kotlin/io/rebble/cobble/bridges/common/PackageDetailsFlutterBridge.kt index ea8e970a..ae45fbb3 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/bridges/common/PackageDetailsFlutterBridge.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/bridges/common/PackageDetailsFlutterBridge.kt @@ -17,7 +17,7 @@ class PackageDetailsFlutterBridge @Inject constructor( override fun getPackageList(): Pigeons.AppEntriesPigeon { val mainIntent = Intent(Intent.ACTION_MAIN, null) mainIntent.addCategory(Intent.CATEGORY_LAUNCHER) - val packages = context.getPackageManager().queryIntentActivities(mainIntent, 0) + val packages = context.packageManager.queryIntentActivities(mainIntent, 0) val ret = Pigeons.AppEntriesPigeon() val pm = context.packageManager ret.appName = ArrayList(packages.map { diff --git a/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/BridgeLifecycleController.kt b/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/BridgeLifecycleController.kt index a590ce9e..3b0d7e39 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/BridgeLifecycleController.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/BridgeLifecycleController.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.Job /** * Helper that automatically closes down all pigeon bridges when activity is destroyed */ -class BridgeLifecycleController constructor( +class BridgeLifecycleController( private val binaryMessenger: BinaryMessenger, coroutineScope: CoroutineScope ) { diff --git a/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/FirmwareUpdateControlFlutterBridge.kt b/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/FirmwareUpdateControlFlutterBridge.kt index fd9b15c3..f18f18c5 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/FirmwareUpdateControlFlutterBridge.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/FirmwareUpdateControlFlutterBridge.kt @@ -158,7 +158,7 @@ class FirmwareUpdateControlFlutterBridge @Inject constructor( error("Firmware update failed - Only reached ${putBytesController.status.value.progress}") } else { systemService.send(SystemMessage.FirmwareUpdateComplete()) - firmwareUpdateCallbacks.onFirmwareUpdateFinished() {} + firmwareUpdateCallbacks.onFirmwareUpdateFinished {} } } return@launchPigeonResult BooleanWrapper(true) diff --git a/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/PermissionControlFlutterBridge.kt b/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/PermissionControlFlutterBridge.kt index 38f7c190..4b90fa66 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/PermissionControlFlutterBridge.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/bridges/ui/PermissionControlFlutterBridge.kt @@ -145,7 +145,7 @@ class PermissionControlFlutterBridge @Inject constructor( } override fun requestLocationPermission(result: Pigeons.Result) { - coroutineScope.launchPigeonResult(result!!, coroutineScope.coroutineContext) { + coroutineScope.launchPigeonResult(result, coroutineScope.coroutineContext) { requestPermission( REQUEST_CODE_LOCATION, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) Manifest.permission.ACCESS_COARSE_LOCATION else Manifest.permission.ACCESS_FINE_LOCATION @@ -154,7 +154,7 @@ class PermissionControlFlutterBridge @Inject constructor( } override fun requestCalendarPermission(result: Pigeons.Result) { - coroutineScope.launchPigeonResult(result!!, coroutineScope.coroutineContext) { + coroutineScope.launchPigeonResult(result, coroutineScope.coroutineContext) { requestPermission( REQUEST_CODE_CALENDAR, Manifest.permission.READ_CALENDAR, diff --git a/android/app/src/main/kotlin/io/rebble/cobble/datasources/FlutterPreferences.kt b/android/app/src/main/kotlin/io/rebble/cobble/datasources/FlutterPreferences.kt index 9e96b9f5..27e9c948 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/datasources/FlutterPreferences.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/datasources/FlutterPreferences.kt @@ -111,4 +111,4 @@ private const val KEY_MASTER_NOTIFICATION_TOGGLE = "flutter.MASTER_NOTIFICATION_ private const val KEY_PREFIX_DISABLE_WORKAROUND = "flutter.DISABLE_WORKAROUND_" private const val KEY_MUTED_NOTIF_PACKAGES = "flutter.MUTED_NOTIF_PACKAGES" -private const val LIST_IDENTIFIER = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu"; \ No newline at end of file +private const val LIST_IDENTIFIER = "VGhpcyBpcyB0aGUgcHJlZml4IGZvciBhIGxpc3Qu" \ No newline at end of file diff --git a/android/app/src/main/kotlin/io/rebble/cobble/middleware/AppCompatibility.kt b/android/app/src/main/kotlin/io/rebble/cobble/middleware/AppCompatibility.kt index 3c1c58de..47b7553e 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/middleware/AppCompatibility.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/middleware/AppCompatibility.kt @@ -23,7 +23,7 @@ fun getCompatibleAppVariants(watchType: WatchType): List { fun getBestVariant(watchType: WatchType, availableAppVariants: List): WatchType? { val compatibleVariants = getCompatibleAppVariants(watchType) - return compatibleVariants.firstOrNull() { variant -> + return compatibleVariants.firstOrNull { variant -> availableAppVariants.contains(variant.codename) } } \ No newline at end of file diff --git a/android/app/src/main/kotlin/io/rebble/cobble/service/WatchService.kt b/android/app/src/main/kotlin/io/rebble/cobble/service/WatchService.kt index f81e5de2..a46778f9 100644 --- a/android/app/src/main/kotlin/io/rebble/cobble/service/WatchService.kt +++ b/android/app/src/main/kotlin/io/rebble/cobble/service/WatchService.kt @@ -64,10 +64,6 @@ class WatchService : LifecycleService() { return START_STICKY } - override fun onDestroy() { - super.onDestroy() - } - private fun startNotificationLoop() { coroutineScope.launch { Timber.d("Notification Loop start") diff --git a/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/ble/GattStatus.kt b/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/ble/GattStatus.kt index 4c6fff00..97a3e493 100644 --- a/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/ble/GattStatus.kt +++ b/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/ble/GattStatus.kt @@ -10,7 +10,7 @@ class GattStatus(val value: Int) { p.name.startsWith("GATT_") && p.getInt(null) == value } - var ret = err?.name?.replace("GATT", "")?.replace("_", "")?.toLowerCase(Locale.ROOT)?.capitalize() + var ret = err?.name?.replace("GATT", "")?.replace("_", "")?.lowercase(Locale.ROOT)?.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } ?: "Unknown error" ret += " (${value})" return ret diff --git a/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/classic/ReconnectionSocketServer.kt b/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/classic/ReconnectionSocketServer.kt index 70973c6f..dc313535 100644 --- a/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/classic/ReconnectionSocketServer.kt +++ b/android/pebble_bt_transport/src/main/java/io/rebble/cobble/bluetooth/classic/ReconnectionSocketServer.kt @@ -1,19 +1,18 @@ package io.rebble.cobble.bluetooth.classic import android.bluetooth.BluetoothAdapter -import android.bluetooth.BluetoothServerSocket import androidx.annotation.RequiresPermission -import kotlinx.coroutines.* -import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.runInterruptible import timber.log.Timber import java.util.UUID import kotlin.coroutines.CoroutineContext class ReconnectionSocketServer(private val adapter: BluetoothAdapter, private val ioDispatcher: CoroutineContext = Dispatchers.IO) { companion object { - private val socketUUID = UUID.fromString("a924496e-cc7c-4dff-8a9f-9a76cc2e9d50"); + private val socketUUID = UUID.fromString("a924496e-cc7c-4dff-8a9f-9a76cc2e9d50") private val socketName = "PebbleBluetoothServerSocket" }