diff --git a/app/src/main/java/org/apache/fineract/ui/online/groups/creategroup/GroupAddressStepFragment.kt b/app/src/main/java/org/apache/fineract/ui/online/groups/creategroup/GroupAddressStepFragment.kt index 533ffb55..70f9dbb6 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/groups/creategroup/GroupAddressStepFragment.kt +++ b/app/src/main/java/org/apache/fineract/ui/online/groups/creategroup/GroupAddressStepFragment.kt @@ -6,7 +6,6 @@ import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.Toast -import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import com.stepstone.stepper.Step import com.stepstone.stepper.VerificationError @@ -63,10 +62,12 @@ class GroupAddressStepFragment : FineractBaseFragment(), Step { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - viewModel.getCountries().observe(this, Observer { - countries = it - etCountry.setAdapter(ArrayAdapter(context, android.R.layout.simple_list_item_1, viewModel.getCountryNames(it))) - }) + + countries = viewModel.getCountries() + if (countries.isNotEmpty()) { + etCountry.setAdapter(ArrayAdapter(context, android.R.layout.simple_list_item_1, + viewModel.getCountryNames(countries))) + } etCountry.threshold = 1 if (groupAction == GroupAction.EDIT) { @@ -144,7 +145,9 @@ class GroupAddressStepFragment : FineractBaseFragment(), Step { } override fun getErrorMessage(): String { - return getString(R.string.invalid_country) + return if (countries.isEmpty()) { + getString(R.string.error_loading_countries) + } else getString(R.string.invalid_country) } }) .addErrorCallback { diff --git a/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupViewModel.kt b/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupViewModel.kt index 6f9f159a..c79099cf 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupViewModel.kt +++ b/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupViewModel.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel import io.reactivex.Observable import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.functions.Predicate +import io.reactivex.observers.DisposableObserver import io.reactivex.schedulers.Schedulers import kotlinx.coroutines.* import org.apache.fineract.data.Status @@ -44,13 +45,23 @@ class GroupViewModel constructor(val dataManagerGroups: DataManagerGroups, val d } @SuppressLint("CheckResult") - fun getCountries(): MutableLiveData> { - val countries = MutableLiveData>() - dataManagerAnonymous.countries.subscribeOn(Schedulers.io()) + fun getCountries(): List { + var countries:List = emptyList() + + dataManagerAnonymous.countries + .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe { - countries.value = it - } + .subscribeWith(object : DisposableObserver?>() { + override fun onNext(countriesList: List) { + countries = countriesList + } + + override fun onError(throwable: Throwable) { + countries = emptyList() + } + + override fun onComplete() {} + }) return countries }