mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Migrate RadioInterfaceService prefs to repo pattern (#2768)
This commit is contained in:
parent
daa5afe8ee
commit
ae9b5f4db3
3 changed files with 7 additions and 50 deletions
|
|
@ -18,8 +18,6 @@
|
|||
package com.geeksville.mesh.repository.radio
|
||||
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import com.geeksville.mesh.BuildConfig
|
||||
|
|
@ -29,6 +27,7 @@ import com.geeksville.mesh.android.BinaryLogFile
|
|||
import com.geeksville.mesh.android.BuildUtils
|
||||
import com.geeksville.mesh.android.GeeksvilleApplication
|
||||
import com.geeksville.mesh.android.Logging
|
||||
import com.geeksville.mesh.android.prefs.RadioPrefs
|
||||
import com.geeksville.mesh.concurrent.handledLaunch
|
||||
import com.geeksville.mesh.repository.bluetooth.BluetoothRepository
|
||||
import com.geeksville.mesh.repository.network.NetworkRepository
|
||||
|
|
@ -61,6 +60,7 @@ import javax.inject.Singleton
|
|||
* Note - this class intentionally dumb. It doesn't understand protobuf framing etc... It is designed to be simple so it
|
||||
* can be stubbed out with a simulated version as needed.
|
||||
*/
|
||||
@Suppress("LongParameterList")
|
||||
@Singleton
|
||||
class RadioInterfaceService
|
||||
@Inject
|
||||
|
|
@ -70,7 +70,7 @@ constructor(
|
|||
private val bluetoothRepository: BluetoothRepository,
|
||||
private val networkRepository: NetworkRepository,
|
||||
private val processLifecycle: Lifecycle,
|
||||
@RadioRepositoryQualifier private val prefs: SharedPreferences,
|
||||
private val radioPrefs: RadioPrefs,
|
||||
private val interfaceFactory: InterfaceFactory,
|
||||
) : Logging {
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ constructor(
|
|||
val receivedData: SharedFlow<ByteArray> = _receivedData
|
||||
|
||||
// Thread-safe StateFlow for tracking device address changes
|
||||
private val _currentDeviceAddressFlow = MutableStateFlow<String?>(prefs.getString(DEVADDR_KEY, null))
|
||||
private val _currentDeviceAddressFlow = MutableStateFlow(radioPrefs.devAddr)
|
||||
val currentDeviceAddressFlow: StateFlow<String?> = _currentDeviceAddressFlow.asStateFlow()
|
||||
|
||||
private val logSends = false
|
||||
|
|
@ -129,7 +129,6 @@ constructor(
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val DEVADDR_KEY = "devAddr2" // the new name for devaddr
|
||||
private const val HEARTBEAT_INTERVAL_MILLIS = 5 * 60 * 1000L
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +166,7 @@ constructor(
|
|||
*/
|
||||
fun getDeviceAddress(): String? {
|
||||
// If the user has unpaired our device, treat things as if we don't have one
|
||||
var address = prefs.getString(DEVADDR_KEY, null)
|
||||
var address = radioPrefs.devAddr
|
||||
|
||||
// If we are running on the emulator we default to the mock interface, so we can have some data to show to the
|
||||
// user
|
||||
|
|
@ -309,13 +308,8 @@ constructor(
|
|||
|
||||
debug("Setting bonded device to ${address.anonymize}")
|
||||
|
||||
prefs.edit {
|
||||
if (address == null) {
|
||||
this.remove(DEVADDR_KEY)
|
||||
} else {
|
||||
putString(DEVADDR_KEY, address)
|
||||
}
|
||||
}
|
||||
// Stores the address if non-null, otherwise removes the pref
|
||||
radioPrefs.devAddr = address
|
||||
_currentDeviceAddressFlow.value = address
|
||||
|
||||
// Force the service to reconnect
|
||||
|
|
|
|||
|
|
@ -17,12 +17,8 @@
|
|||
|
||||
package com.geeksville.mesh.repository.radio
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import dagger.multibindings.IntoMap
|
||||
|
|
@ -49,11 +45,4 @@ abstract class RadioRepositoryModule {
|
|||
|
||||
@[Binds IntoMap InterfaceMapKey(InterfaceId.TCP)]
|
||||
abstract fun bindTCPInterfaceSpec(spec: TCPInterfaceSpec): @JvmSuppressWildcards InterfaceSpec<*>
|
||||
|
||||
companion object {
|
||||
@Provides
|
||||
@RadioRepositoryQualifier
|
||||
fun provideSharedPreferences(application: Application): SharedPreferences =
|
||||
application.getSharedPreferences("radio-prefs", Context.MODE_PRIVATE)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025 Meshtastic LLC
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.geeksville.mesh.repository.radio
|
||||
|
||||
import javax.inject.Qualifier
|
||||
|
||||
/**
|
||||
* Qualifier to distinguish radio repository- specific object instances.
|
||||
*/
|
||||
@Qualifier
|
||||
annotation class RadioRepositoryQualifier
|
||||
Loading…
Add table
Add a link
Reference in a new issue