Skip to content

Instantly share code, notes, and snippets.

@CesarValiente
Last active March 24, 2018 17:24
Show Gist options
  • Save CesarValiente/4ea66102719ec76101d9d591fa40340e to your computer and use it in GitHub Desktop.
Save CesarValiente/4ea66102719ec76101d9d591fa40340e to your computer and use it in GitHub Desktop.
class ItemsActivity : ViewActivity<ItemsControllerView>(), ItemsViewCallback {
//--- We set up the ControllerView --- //
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.items_layout)
setupControllerView()
bindViews()
}
override fun setupControllerView() {
val controllerView = ItemsControllerView(
itemsViewCallback = WeakReference(this),
store = AppStore,
mainThread = MainThread(WeakReference(this)))
registerControllerViewForLifecycle(controllerView)
}
//--- Once the ControllerView is configured, we can start using it --- //
override fun onResume() {
super.onResume()
controllerView.fetchItems()
}
private fun openEditItemScreen(item: Item) =
controllerView.toEditItemScreen(item)
private fun changeFavoriteStatus(item: Item) =
controllerView.changeFavoriteStatus(item)
// --- Implementation of the interface (ItemsViewCallback) that will make
// possible for the ControllerView to communicate back with the View --- //
override fun updateItems(items: List<Item>) =
itemsAdapter.updateItems(items)
override fun goToEditItem() {
val intent = EditItemActivity.createEditItemActivityIntent(this)
startActivity(intent)
}
}
interface ItemsViewCallback {
fun updateItems(items: List<Item>)
fun goToEditItem()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment