You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2018/07/25 16:10:07 UTC

[GitHub] mohak1712 commented on a change in pull request #15: feat: ledger and account

mohak1712 commented on a change in pull request #15: feat: ledger and account
URL: https://github.com/apache/fineract-cn-mobile/pull/15#discussion_r205171233
 
 

 ##########
 File path: app/src/main/java/org/apache/fineract/ui/online/accounting/accounts/AccountsPresenter.kt
 ##########
 @@ -0,0 +1,85 @@
+package org.apache.fineract.ui.online.accounting.accounts
+
+import android.content.Context
+import io.reactivex.android.schedulers.AndroidSchedulers
+import io.reactivex.disposables.CompositeDisposable
+import io.reactivex.observers.DisposableObserver
+import io.reactivex.schedulers.Schedulers
+import org.apache.fineract.R
+import org.apache.fineract.data.datamanager.DataManagerAccounting
+import org.apache.fineract.data.models.accounts.Account
+import org.apache.fineract.data.models.accounts.AccountPage
+import org.apache.fineract.injection.ApplicationContext
+import org.apache.fineract.ui.base.BasePresenter
+import javax.inject.Inject
+
+class AccountsPresenter @Inject constructor(@ApplicationContext context: Context,
+                                            val dataManagerAccounting: DataManagerAccounting)
+    : BasePresenter<AccountContract.View>(context), AccountContract.Presenter {
+
+    val compositeDisposable: CompositeDisposable = CompositeDisposable()
+
+    override fun getAccountsPage() {
+
+        checkViewAttached()
+        mvpView.showProgressbar()
+
+        compositeDisposable.add(dataManagerAccounting.getAccounts()
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribeWith(object : DisposableObserver<AccountPage>() {
+                    override fun onComplete() {
+
+                    }
+
+                    override fun onNext(accountPage: AccountPage?) {
+
+                        mvpView.hideProgressbar()
+                        accountPage?.accounts?.let {
+                            if (it.isEmpty()) {
+                                mvpView.showEmptyAccounts()
+                            } else {
+                                mvpView.showAccounts(it)
+                            }
+                        }
+                    }
+
+                    override fun onError(e: Throwable?) {
+                        mvpView.hideProgressbar()
+                        showExceptionError(e, context.getString(R.string.error_fetching_accounts))
+                    }
+                }))
+    }
+
+    override fun searchAccount(query: String) {
+
+        checkViewAttached()
+        mvpView.showProgressbar()
+
+        compositeDisposable.add(dataManagerAccounting
+                .findAccount(query)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribeWith(object : DisposableObserver<Account>() {
+                    override fun onComplete() {
+
+                    }
+
+                    override fun onNext(account: Account?) {
+
+                        mvpView.hideProgressbar()
+                        account?.let {
 
 Review comment:
   @therajanmaurya if there is no account then I get an error else I have an account since this is a search feature.
   I have added a check for an empty list at line  39

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services