Skip to content

Commit

Permalink
Fixes suggested by reviewers (part 3)
Browse files Browse the repository at this point in the history
- Pass DevicesUiModel to HomeScreen (instead of just a noDevices boolean)
  • Loading branch information
pierredelisle committed Dec 12, 2023
1 parent f9c1aa7 commit e2603da
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -449,24 +450,27 @@ class HomeFragment : Fragment() {
private fun HomeRoute(homeViewModel: HomeViewModel) {
// Observes values coming from the VM's devicesUiModelLiveData
val devicesUiModel by homeViewModel.devicesUiModelLiveData.observeAsState()
Timber.d("HomeRoute [${devicesUiModel}]")
val noDevices = devicesUiModel == null || devicesUiModel!!.devices.isEmpty()
HomeScreen(noDevices)
HomeScreen(devicesUiModel)
}

@Composable
private fun HomeScreen(noDevices: Boolean) {
// Observes values coming from the VM's devicesUiModelLiveData
private fun HomeScreen(devicesUiModel: DevicesUiModel?) {
val noDevices = devicesUiModel == null || devicesUiModel.devices.isEmpty()
if (noDevices) {
NoDevices()
}

LaunchedEffect(devicesUiModel) {
Timber.d("HomeRoute [${devicesUiModel}]")
}
}

@Preview(showSystemUi = true, showBackground = true)
@Composable
private fun HomeScreenNoDevicesPreview() {
val devicesUiModel = DevicesUiModel(emptyList(), showCodelabInfo = false, showOfflineDevices = false)
MaterialTheme {
HomeScreen(true)
HomeScreen(devicesUiModel)
}
}

Expand Down

0 comments on commit e2603da

Please sign in to comment.