Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import com.sample.di.data.GroceryItem
  2. import com.sample.di.data.IRepository
  3. import java.util.*
  4.  
  5.  
  6. class GroceryPresenter(view: GroceryContact.View, repository: IRepository) : GroceryContact.UserActionsListener {
  7.  
  8. private val mRepository: IRepository = repository
  9. private val mView: GroceryContact.View = view
  10.  
  11. override fun loadGroceryItem(forceUpdate: Boolean) {
  12. if (forceUpdate) {
  13. mRepository.refreshData()
  14. }
  15.  
  16. mRepository.getGroceryItems(object : IRepository.OnLoadCallback<List<GroceryItem>> {
  17. override fun onLoaded(items: List<GroceryItem>) {
  18. mView.showAllGroceryItem(items)
  19. }
  20. })
  21. }
  22.  
  23. override fun randomItem() {
  24. mRepository.getGroceryItems(object : IRepository.OnLoadCallback<List<GroceryItem>> {
  25. override fun onLoaded(items: List<GroceryItem>) {
  26. mView.showItem(items[Random().nextInt(items.size)])
  27. }
  28. })
  29. }
  30.  
  31. override fun autoAddItem() {
  32. val id = UUID.randomUUID().toString()
  33. val item = GroceryItem(id, "Add$id", 0)
  34. mRepository.addGroceryItem(item)
  35. mView.showToast("Added!")
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement