Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.78 KB | None | 0 0
  1. class AddingPresenterImplementation @Inject constructor(private val dataSource: DataSource): AddingPresenter {
  2.     private var addingView: AddingView? = null
  3.  
  4.     @InternalCoroutinesApi
  5.     override suspend fun add(name: String, cost: Int, currency: Int, date: Long) {
  6.         addingView?.setLoadingVisibility(true)
  7.         val purchase = Purchase(0, name, cost, currency, date)
  8.         try {
  9.             dataSource.database.purchaseDao().insert(purchase)
  10.             addingView?.addSuccess()
  11.         } catch (e: Exception) {
  12.             addingView?.addFailed()
  13.             addingView?.showError(e.localizedMessage ?: "Unresolved error")
  14.         }
  15.     }
  16.  
  17.     override fun attachView(view: AddingView) {
  18.         addingView = view
  19.     }
  20.  
  21.     override fun detachView() {
  22.         addingView = null
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement