clean up and reformat

pull/357/head
andrekir 2022-01-31 21:55:24 -03:00
rodzic dc852b97ba
commit 084c16bfe9
3 zmienionych plików z 34 dodań i 35 usunięć

Wyświetl plik

@ -36,7 +36,6 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Observer
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.geeksville.android.BindFailedException
import com.geeksville.android.GeeksvilleApplication
@ -66,7 +65,6 @@ import com.vorlonsoft.android.rate.AppRate
import com.vorlonsoft.android.rate.StoreType
import kotlinx.coroutines.*
import java.io.FileOutputStream
import java.lang.Runnable
import java.nio.charset.Charset
import java.text.DateFormat
import java.util.*
@ -194,7 +192,7 @@ class MainActivity : AppCompatActivity(), Logging,
}
}
private val btStateReceiver = BluetoothStateReceiver { _ ->
private val btStateReceiver = BluetoothStateReceiver {
updateBluetoothEnabled()
}
@ -532,9 +530,9 @@ class MainActivity : AppCompatActivity(), Logging,
tab.icon = ContextCompat.getDrawable(this, tabInfos[position].icon)
}.attach()
model.isConnected.observe(this, Observer { connected ->
model.isConnected.observe(this) { connected ->
updateConnectionStatusImage(connected)
})
}
// Handle any intent
handleIntent(intent)
@ -927,10 +925,10 @@ class MainActivity : AppCompatActivity(), Logging,
private var connectionJob: Job? = null
private val mesh = object :
ServiceClient<com.geeksville.mesh.IMeshService>({
com.geeksville.mesh.IMeshService.Stub.asInterface(it)
ServiceClient<IMeshService>({
IMeshService.Stub.asInterface(it)
}) {
override fun onConnected(service: com.geeksville.mesh.IMeshService) {
override fun onConnected(service: IMeshService) {
/*
Note: we must call this callback in a coroutine. Because apparently there is only a single activity looper thread. and if that onConnected override
@ -1147,12 +1145,7 @@ class MainActivity : AppCompatActivity(), Logging,
val str = "Ping " + DateFormat.getTimeInstance(DateFormat.MEDIUM)
.format(Date(System.currentTimeMillis()))
model.messagesState.sendMessage(str)
handler.postDelayed(
Runnable {
postPing()
},
30000
)
handler.postDelayed({ postPing() }, 30000)
}
item.isChecked = !item.isChecked // toggle ping test
if (item.isChecked)

Wyświetl plik

@ -1,5 +1,6 @@
package com.geeksville.mesh.service
import android.annotation.SuppressLint
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattService
@ -92,13 +93,13 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
}
/// this service UUID is publically visible for scanning
val BTM_SERVICE_UUID = UUID.fromString("6ba1b218-15a8-461f-9fa8-5dcae273eafd")
val BTM_SERVICE_UUID: UUID = UUID.fromString("6ba1b218-15a8-461f-9fa8-5dcae273eafd")
val BTM_FROMRADIO_CHARACTER =
val BTM_FROMRADIO_CHARACTER: UUID =
UUID.fromString("8ba2bcc2-ee02-4a55-a531-c525c5e454d5")
val BTM_TORADIO_CHARACTER =
val BTM_TORADIO_CHARACTER: UUID =
UUID.fromString("f75c76d2-129e-4dad-a1dd-7866124401e7")
val BTM_FROMNUM_CHARACTER =
val BTM_FROMNUM_CHARACTER: UUID =
UUID.fromString("ed9da18c-a800-4f66-a670-aa7547e34453")
/// Get our bluetooth adapter (should always succeed except on emulator
@ -109,6 +110,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
}
/** Return true if this address is still acceptable. For BLE that means, still bonded */
@SuppressLint("NewApi", "MissingPermission")
override fun addressValid(context: Context, rest: String): Boolean {
val allPaired = if (hasCompanionDeviceApi(context)) {
val deviceManager = context.getSystemService(CompanionDeviceManager::class.java)
@ -196,7 +198,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
?: throw RadioNotConnectedException("No GATT")
/// Our service - note - it is possible to get back a null response for getService if the device services haven't yet been found
val bservice
private val bservice
get(): BluetoothGattService = device.getService(BTM_SERVICE_UUID)
?: throw RadioNotConnectedException("BLE service not found")
@ -268,7 +270,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
/**
* We had some problem, schedule a reconnection attempt (if one isn't already queued)
*/
fun scheduleReconnect(reason: String) {
private fun scheduleReconnect(reason: String) {
if (reconnectJob == null) {
warn("Scheduling reconnect because $reason")
reconnectJob = service.serviceScope.handledLaunch { retryDueToException() }

Wyświetl plik

@ -619,44 +619,44 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
regionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = regionAdapter
model.bluetoothEnabled.observe(viewLifecycleOwner, {
model.bluetoothEnabled.observe(viewLifecycleOwner) {
if (it) binding.changeRadioButton.show()
else binding.changeRadioButton.hide()
})
}
model.ownerName.observe(viewLifecycleOwner, { name ->
model.ownerName.observe(viewLifecycleOwner) { name ->
binding.usernameEditText.setText(name)
})
}
// Only let user edit their name or set software update while connected to a radio
model.isConnected.observe(viewLifecycleOwner, {
model.isConnected.observe(viewLifecycleOwner) {
updateNodeInfo()
updateDevicesButtons(scanModel.devices.value)
})
}
model.radioConfig.observe(viewLifecycleOwner, {
model.radioConfig.observe(viewLifecycleOwner) {
binding.provideLocationCheckbox.isEnabled =
isGooglePlayAvailable(requireContext()) && model.locationShare ?: true
if (model.locationShare == false) {
model.provideLocation.value = false
binding.provideLocationCheckbox.isChecked = false
}
})
}
// Also watch myNodeInfo because it might change later
model.myNodeInfo.observe(viewLifecycleOwner, {
model.myNodeInfo.observe(viewLifecycleOwner) {
updateNodeInfo()
})
}
scanModel.errorText.observe(viewLifecycleOwner, { errMsg ->
scanModel.errorText.observe(viewLifecycleOwner) { errMsg ->
if (errMsg != null) {
binding.scanStatusText.text = errMsg
}
})
}
scanModel.devices.observe(viewLifecycleOwner, { devices ->
scanModel.devices.observe(viewLifecycleOwner) { devices ->
updateDevicesButtons(devices)
})
}
binding.updateFirmwareButton.setOnClickListener {
doFirmwareUpdate()
@ -961,7 +961,11 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
if (!hasUSB) {
// Warn user if BLE is disabled
if (scanModel.bluetoothAdapter?.isEnabled != true) {
Snackbar.make(binding.changeRadioButton, R.string.error_bluetooth, Snackbar.LENGTH_INDEFINITE)
Snackbar.make(
binding.changeRadioButton,
R.string.error_bluetooth,
Snackbar.LENGTH_INDEFINITE
)
.setAction(R.string.okay) {
// dismiss
}