Last active
August 30, 2021 02:29
-
-
Save widiarifki/5f26f9e5a51f3cbce2f793094585da9c to your computer and use it in GitHub Desktop.
This gist is part of https://github.com/widiarifki/android-playground/tree/master/compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShoppingListActivity : ComponentActivity() { | |
private val viewModel by viewModels<ShoppingListViewModel>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
// observeAsState() hanya bisa dipanggil dari fungsi Composable | |
// tujuannya a/ utk mengobserve LiveData dan direpresentasikan ke dalam State | |
val shoppingItemsState = viewModel.shoppingItems.observeAsState(listOf()) | |
val shoppingItems by rememberSaveable { shoppingItemsState } | |
MaterialTheme { | |
ShoppingListScreen( | |
isLoading = viewModel.isLoading, | |
shoppingItems = shoppingItems, | |
onAddItem = viewModel::addItem, | |
onToggleTickItem = viewModel::toggleTickItem, | |
onDeleteItem = viewModel::deleteItem | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment