2022-02-26 22:59:20 -08:00
|
|
|
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
|
2022-02-27 11:35:22 -08:00
|
|
|
import kotlinx.coroutines.flow.map
|
2022-02-26 22:59:20 -08:00
|
|
|
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() {
|
2022-02-27 11:35:22 -08:00
|
|
|
/**
|
|
|
|
|
* Called when permissions have been updated. This causes an explicit refresh of the
|
|
|
|
|
* bluetooth state.
|
|
|
|
|
*/
|
|
|
|
|
fun permissionsUpdated() = bluetoothRepository.refreshState()
|
2022-02-26 22:59:20 -08:00
|
|
|
|
2022-02-27 11:35:22 -08:00
|
|
|
val enabled = bluetoothRepository.state.map { it.enabled }.asLiveData()
|
2022-02-26 22:59:20 -08:00
|
|
|
}
|