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.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Observer
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import com.geeksville.android.BindFailedException import com.geeksville.android.BindFailedException
import com.geeksville.android.GeeksvilleApplication import com.geeksville.android.GeeksvilleApplication
@ -66,7 +65,6 @@ import com.vorlonsoft.android.rate.AppRate
import com.vorlonsoft.android.rate.StoreType import com.vorlonsoft.android.rate.StoreType
import kotlinx.coroutines.* import kotlinx.coroutines.*
import java.io.FileOutputStream import java.io.FileOutputStream
import java.lang.Runnable
import java.nio.charset.Charset import java.nio.charset.Charset
import java.text.DateFormat import java.text.DateFormat
import java.util.* import java.util.*
@ -194,7 +192,7 @@ class MainActivity : AppCompatActivity(), Logging,
} }
} }
private val btStateReceiver = BluetoothStateReceiver { _ -> private val btStateReceiver = BluetoothStateReceiver {
updateBluetoothEnabled() updateBluetoothEnabled()
} }
@ -532,9 +530,9 @@ class MainActivity : AppCompatActivity(), Logging,
tab.icon = ContextCompat.getDrawable(this, tabInfos[position].icon) tab.icon = ContextCompat.getDrawable(this, tabInfos[position].icon)
}.attach() }.attach()
model.isConnected.observe(this, Observer { connected -> model.isConnected.observe(this) { connected ->
updateConnectionStatusImage(connected) updateConnectionStatusImage(connected)
}) }
// Handle any intent // Handle any intent
handleIntent(intent) handleIntent(intent)
@ -927,10 +925,10 @@ class MainActivity : AppCompatActivity(), Logging,
private var connectionJob: Job? = null private var connectionJob: Job? = null
private val mesh = object : private val mesh = object :
ServiceClient<com.geeksville.mesh.IMeshService>({ ServiceClient<IMeshService>({
com.geeksville.mesh.IMeshService.Stub.asInterface(it) 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 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) val str = "Ping " + DateFormat.getTimeInstance(DateFormat.MEDIUM)
.format(Date(System.currentTimeMillis())) .format(Date(System.currentTimeMillis()))
model.messagesState.sendMessage(str) model.messagesState.sendMessage(str)
handler.postDelayed( handler.postDelayed({ postPing() }, 30000)
Runnable {
postPing()
},
30000
)
} }
item.isChecked = !item.isChecked // toggle ping test item.isChecked = !item.isChecked // toggle ping test
if (item.isChecked) if (item.isChecked)

Wyświetl plik

@ -1,5 +1,6 @@
package com.geeksville.mesh.service package com.geeksville.mesh.service
import android.annotation.SuppressLint
import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothGattCharacteristic import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattService import android.bluetooth.BluetoothGattService
@ -92,13 +93,13 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
} }
/// this service UUID is publically visible for scanning /// 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") UUID.fromString("8ba2bcc2-ee02-4a55-a531-c525c5e454d5")
val BTM_TORADIO_CHARACTER = val BTM_TORADIO_CHARACTER: UUID =
UUID.fromString("f75c76d2-129e-4dad-a1dd-7866124401e7") UUID.fromString("f75c76d2-129e-4dad-a1dd-7866124401e7")
val BTM_FROMNUM_CHARACTER = val BTM_FROMNUM_CHARACTER: UUID =
UUID.fromString("ed9da18c-a800-4f66-a670-aa7547e34453") UUID.fromString("ed9da18c-a800-4f66-a670-aa7547e34453")
/// Get our bluetooth adapter (should always succeed except on emulator /// 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 */ /** 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 { override fun addressValid(context: Context, rest: String): Boolean {
val allPaired = if (hasCompanionDeviceApi(context)) { val allPaired = if (hasCompanionDeviceApi(context)) {
val deviceManager = context.getSystemService(CompanionDeviceManager::class.java) val deviceManager = context.getSystemService(CompanionDeviceManager::class.java)
@ -196,7 +198,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
?: throw RadioNotConnectedException("No GATT") ?: 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 /// 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) get(): BluetoothGattService = device.getService(BTM_SERVICE_UUID)
?: throw RadioNotConnectedException("BLE service not found") ?: 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) * 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) { if (reconnectJob == null) {
warn("Scheduling reconnect because $reason") warn("Scheduling reconnect because $reason")
reconnectJob = service.serviceScope.handledLaunch { retryDueToException() } 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) regionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = regionAdapter spinner.adapter = regionAdapter
model.bluetoothEnabled.observe(viewLifecycleOwner, { model.bluetoothEnabled.observe(viewLifecycleOwner) {
if (it) binding.changeRadioButton.show() if (it) binding.changeRadioButton.show()
else binding.changeRadioButton.hide() else binding.changeRadioButton.hide()
}) }
model.ownerName.observe(viewLifecycleOwner, { name -> model.ownerName.observe(viewLifecycleOwner) { name ->
binding.usernameEditText.setText(name) binding.usernameEditText.setText(name)
}) }
// Only let user edit their name or set software update while connected to a radio // Only let user edit their name or set software update while connected to a radio
model.isConnected.observe(viewLifecycleOwner, { model.isConnected.observe(viewLifecycleOwner) {
updateNodeInfo() updateNodeInfo()
updateDevicesButtons(scanModel.devices.value) updateDevicesButtons(scanModel.devices.value)
}) }
model.radioConfig.observe(viewLifecycleOwner, { model.radioConfig.observe(viewLifecycleOwner) {
binding.provideLocationCheckbox.isEnabled = binding.provideLocationCheckbox.isEnabled =
isGooglePlayAvailable(requireContext()) && model.locationShare ?: true isGooglePlayAvailable(requireContext()) && model.locationShare ?: true
if (model.locationShare == false) { if (model.locationShare == false) {
model.provideLocation.value = false model.provideLocation.value = false
binding.provideLocationCheckbox.isChecked = false binding.provideLocationCheckbox.isChecked = false
} }
}) }
// Also watch myNodeInfo because it might change later // Also watch myNodeInfo because it might change later
model.myNodeInfo.observe(viewLifecycleOwner, { model.myNodeInfo.observe(viewLifecycleOwner) {
updateNodeInfo() updateNodeInfo()
}) }
scanModel.errorText.observe(viewLifecycleOwner, { errMsg -> scanModel.errorText.observe(viewLifecycleOwner) { errMsg ->
if (errMsg != null) { if (errMsg != null) {
binding.scanStatusText.text = errMsg binding.scanStatusText.text = errMsg
} }
}) }
scanModel.devices.observe(viewLifecycleOwner, { devices -> scanModel.devices.observe(viewLifecycleOwner) { devices ->
updateDevicesButtons(devices) updateDevicesButtons(devices)
}) }
binding.updateFirmwareButton.setOnClickListener { binding.updateFirmwareButton.setOnClickListener {
doFirmwareUpdate() doFirmwareUpdate()
@ -961,7 +961,11 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
if (!hasUSB) { if (!hasUSB) {
// Warn user if BLE is disabled // Warn user if BLE is disabled
if (scanModel.bluetoothAdapter?.isEnabled != true) { 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) { .setAction(R.string.okay) {
// dismiss // dismiss
} }