Issue #369 - Expand bluetooth repository use cases

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
This commit is contained in:
Mike Cumings 2022-02-27 11:35:22 -08:00
parent f961f2e07e
commit 9592fd68de
7 changed files with 99 additions and 44 deletions

View file

@ -4,6 +4,7 @@ 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
/**
@ -13,7 +14,11 @@ import javax.inject.Inject
class BluetoothViewModel @Inject constructor(
private val bluetoothRepository: BluetoothRepository,
) : ViewModel() {
fun refreshState() = bluetoothRepository.refreshState()
/**
* Called when permissions have been updated. This causes an explicit refresh of the
* bluetooth state.
*/
fun permissionsUpdated() = bluetoothRepository.refreshState()
val enabled = bluetoothRepository.enabled.asLiveData()
val enabled = bluetoothRepository.state.map { it.enabled }.asLiveData()
}