Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Fix-314: Instant crash on Group create/edit fixed #177

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,13 +45,23 @@ class GroupViewModel constructor(val dataManagerGroups: DataManagerGroups, val d
}

@SuppressLint("CheckResult")
fun getCountries(): MutableLiveData<List<Country>> {
val countries = MutableLiveData<List<Country>>()
dataManagerAnonymous.countries.subscribeOn(Schedulers.io())
fun getCountries(): List<Country> {
var countries:List<Country> = emptyList()

dataManagerAnonymous.countries
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
countries.value = it
}
.subscribeWith(object : DisposableObserver<List<Country>?>() {
override fun onNext(countriesList: List<Country>) {
countries = countriesList
}

override fun onError(throwable: Throwable) {
countries = emptyList()
}

override fun onComplete() {}
})
return countries
}

Expand Down