Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: SwipeRefreshLayout spinning endlessly on the account section #217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.mifos.mobile.cn.ui.mifos.accounts

import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.github.therajanmaurya.sweeterror.SweetUIErrorHandler
import kotlinx.android.synthetic.main.fragment_accounts.*
import kotlinx.android.synthetic.main.layout_exception_handler.*
import org.mifos.mobile.cn.R
import org.mifos.mobile.cn.data.models.accounts.deposit.DepositAccount
import org.mifos.mobile.cn.data.models.accounts.loan.LoanAccount
Expand All @@ -19,7 +20,7 @@ import org.mifos.mobile.cn.ui.base.MifosBaseFragment
import org.mifos.mobile.cn.ui.utils.ConstantKeys
import org.mifos.mobile.cn.ui.utils.Network
import javax.inject.Inject
import kotlinx.android.synthetic.main.layout_sweet_exception_handler.*
//import kotlinx.android.synthetic.main.layout_sweet_exception_handler.*
import org.mifos.mobile.cn.data.models.CheckboxStatus
import org.mifos.mobile.cn.ui.base.OnItemClickListener
import org.mifos.mobile.cn.ui.mifos.customerDepositDetails.CustomerDepositDetailsFragment
Expand All @@ -28,10 +29,11 @@ import org.mifos.mobile.cn.ui.utils.RxBus
import org.mifos.mobile.cn.ui.utils.RxEvent


class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClickListener {
class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClickListener, SwipeRefreshLayout.OnRefreshListener {


private lateinit var accountType: String

private lateinit var loanAccounts: List<LoanAccount>
private lateinit var depositAccounts: List<DepositAccount>
var currentFilterList: List<CheckboxStatus>? = null
Expand Down Expand Up @@ -118,7 +120,12 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
rv_accounts.addItemDecoration(DividerItemDecoration(activity,
layoutManager.orientation))
btn_try_again.setOnClickListener { retry() }
swipe_container.setOnRefreshListener(this)

loadAdapterData()
}

private fun loadAdapterData() {
when (accountType) {
ConstantKeys.LOAN_ACCOUNTS -> {
rv_accounts.adapter = loanAccountsListAdapter
Expand All @@ -135,15 +142,15 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
when (accountType) {
ConstantKeys.LOAN_ACCOUNTS -> {
(activity as MifosBaseActivity).replaceFragment(
CustomerLoanDetailsFragment.newInstance(
loanAccounts[position].productIdentifier!!,
loanAccounts[position].identifier!!), true, R.id.container)
CustomerLoanDetailsFragment.newInstance(
loanAccounts[position].productIdentifier!!,
loanAccounts[position].identifier!!), true, R.id.container)
}
ConstantKeys.DEPOSIT_ACCOUNTS -> {
(activity as MifosBaseActivity).replaceFragment(
CustomerDepositDetailsFragment.newInstance(
depositAccounts[position].accountIdentifier!!),true,R.id.container
)
CustomerDepositDetailsFragment.newInstance(
depositAccounts[position].accountIdentifier!!),true,R.id.container
)
}
}
}
Expand All @@ -163,6 +170,7 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
/**
* Shows [List] of [LoanAccount] fetched from server using
* [LoanAccountListAdapter]

* @param loanAccounts [List] of [LoanAccount]
*/
override fun showLoanAccounts(loanAccounts: List<LoanAccount>) {
Expand All @@ -178,12 +186,12 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
when (feature) {
getString(R.string.loan) -> {
errorHandler.showSweetEmptyUI(feature, R.drawable.ic_payment_black_24dp, rv_accounts,
layout_error)
layout_error)
}

getString(R.string.deposit) ->
errorHandler.showSweetEmptyUI(feature, R.drawable.ic_monetization_on_black_24dp,
rv_accounts, layout_error)
rv_accounts, layout_error)
}

}
Expand Down Expand Up @@ -211,7 +219,7 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
val filteredLoans = java.util.ArrayList<LoanAccount>()
for (status in accountsPresenter.getCheckedStatus(statusModelList)) {
filteredLoans.addAll(accountsPresenter.getFilteredLoanAccount(loanAccounts,
status))
status))
}
loanAccountsListAdapter.setCustomerLoanAccounts(filteredLoans)
}
Expand All @@ -220,7 +228,7 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
val filteredDeposit = ArrayList<DepositAccount>()
for (status in accountsPresenter.getCheckedStatus(statusModelList)) {
filteredDeposit.addAll(accountsPresenter.getFilteredDepositAccount(depositAccounts,
status))
status))
depositAccountListAdapter.setCustomerDepositAccounts(filteredDeposit)
}
}
Expand All @@ -232,7 +240,7 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
*/
fun searchLoanAccount(input: String) {
loanAccountsListAdapter.setCustomerLoanAccounts(accountsPresenter
.searchInLoanList(loanAccounts, input))
.searchInLoanList(loanAccounts, input))
}

/**
Expand All @@ -242,7 +250,7 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
*/
fun searchDepositAccount(input: String) {
depositAccountListAdapter.setCustomerDepositAccounts(accountsPresenter
.searchInDepositList(depositAccounts, input))
.searchInDepositList(depositAccounts, input))
}


Expand All @@ -258,6 +266,11 @@ class AccountsFragment : MifosBaseFragment(), AccountsContract.View, OnItemClick
}
}

override fun onRefresh() {
loadAdapterData()
swipe_container.isRefreshing =false
}

override fun showProgress() {
showProgressBar()
}
Expand Down