BubbleApi (0:04)
- api 29
- What's New in the Android Os User Interface thu @ 9: 30
Dark theme (1:35)
- in Q()
- MODE_NIGHT_AUTO_TIME deprecated
- OptionA - use Theme
| // before | |
| class MainViewModel(val view: MainView, val dataStore: DataStore) { | |
| private var currentItem: Item by Delegates.observable(Item("kotlin", "#FF0000"), | |
| { _: KProperty<*>, oldItem: Item, newItem: Item -> | |
| view.onUpdatedItem(oldItem, newItem) | |
| }) | |
| private var currentState: NetworkState<Item> by Delegates.observable(NetworkState.Init(), | |
| { _: KProperty<*>, _: NetworkState<Item>, newState: NetworkState<Item> -> |
| class MainViewModel(val view: MainView, val dataStore: DataStore) { | |
| private var currentItem: Item by Delegates.observable(Item("kotlin", "#FF0000"), | |
| { _: KProperty<*>, oldItem: Item, newItem: Item -> | |
| view.onUpdatedItem(oldItem, newItem) | |
| }) | |
| private var currentState: NetworkState<Item> by Delegates.observable(NetworkState.Init(), | |
| { _: KProperty<*>, _: NetworkState<Item>, newState: NetworkState<Item> -> | |
| when (newState) { |
| // before | |
| sealed class NetworkState { | |
| class Init : NetworkState() | |
| class Loading : NetworkState() | |
| class Success(val item: Item) : NetworkState() | |
| class Error(val throwable: Throwable?) : NetworkState() | |
| } | |
| // after | |
| sealed class NetworkState<out T> { |
| class MainViewModel(val view: MainView, val dataStore: DataStore) { | |
| private var currentItem: Item by Delegates.observable(Item("kotlin", "#FF0000"), | |
| { _: KProperty<*>, oldItem: Item, newItem: Item -> | |
| view.onUpdatedItem(oldItem, newItem) | |
| }) | |
| private var currentState: NetworkState by Delegates.observable(NetworkState.Init(), | |
| { _: KProperty<*>, _: NetworkState, newState: NetworkState -> | |
| when (newState) { |
| sealed class NetworkState { | |
| class Init : NetworkState() | |
| class Loading : NetworkState() | |
| class Success(val item: Item) : NetworkState() | |
| class Error(val throwable: Throwable?) : NetworkState() | |
| } |
| // before | |
| class MainViewModel(val view: MainView) { | |
| private var currentItem: Item by Delegates.observable(Item.ITEM_A, | |
| { _: KProperty<*>, oldItem: Item, newItem: Item -> | |
| view.onUpdatedItem(oldItem, newItem) | |
| }) | |
| fun onClicked(item: Item) { | |
| currentItem = item |
| // before | |
| enum class Item(val titleId: Int, val colorId: Int) { | |
| ITEM_A(R.string.a, R.color.red), | |
| ITEM_B(R.string.b, R.color.green), | |
| ITEM_C(R.string.c, R.color.blue) | |
| } | |
| // after | |
| data class Item(val title: String, val color: String) |
| class MainActivity : AppCompatActivity(), MainView { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| val mainViewModel = MainViewModel(this, DataStore()) | |
| bt_a.setOnClickListener { | |
| mainViewModel.requestItemInfo(ItemType.ITEM_A) |
| interface MainView { | |
| fun onUpdatedItem(oldItem: Item, newItem: Item) | |
| fun showProgress() | |
| fun hideProgress() | |
| fun onError(throwable: Throwable) | |
| } |