mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Changes:
- Adds support for obtaining bonded devices
- Adds support for obtaining BLE scanner
- Consolidates state into a single, immutable data class instance
- Simplified and renamed broadcast receiver
- Renamed view model permissionsUpdated fun to identify the intended use
(cherry picked from commit 9592fd68de)
24 lines
No EOL
786 B
Kotlin
24 lines
No EOL
786 B
Kotlin
package com.geeksville.mesh.model
|
|
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.asLiveData
|
|
import com.geeksville.mesh.repository.bluetooth.BluetoothRepository
|
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
import kotlinx.coroutines.flow.map
|
|
import javax.inject.Inject
|
|
|
|
/**
|
|
* Thin view model which adapts the view layer to the `BluetoothRepository`.
|
|
*/
|
|
@HiltViewModel
|
|
class BluetoothViewModel @Inject constructor(
|
|
private val bluetoothRepository: BluetoothRepository,
|
|
) : ViewModel() {
|
|
/**
|
|
* Called when permissions have been updated. This causes an explicit refresh of the
|
|
* bluetooth state.
|
|
*/
|
|
fun permissionsUpdated() = bluetoothRepository.refreshState()
|
|
|
|
val enabled = bluetoothRepository.state.map { it.enabled }.asLiveData()
|
|
} |