AA-4 | Reyaz & Shashidhara | Implement method to fetch MyLoans in viewModel

This commit is contained in:
Reyaz Ahmad
2019-11-06 14:29:56 +05:30
parent 1c73613f28
commit 037c0d0a41

View File

@@ -1,7 +1,41 @@
package com.navi.medici.android_customer_app.bottomNavigation.myLoans
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class MyLoansViewModel : ViewModel() {
// TODO: Implement the ViewModel
private val myLoansRepository = MyLoansRepository(MyLoansApi())
private val coroutineScope = CoroutineScope(Dispatchers.Main)
val myLoans = MutableLiveData<List<Loan>>()
fun fetchMyLoans() {
coroutineScope.launch {
val response = myLoansRepository.fetchMyLoans()
response.forEachIndexed { index, loan ->
loan.apply {
if (index % 2 == 0) {
amount = 25000
dueDate = "24th December"
interestRate = 12.5f
startDate = "24th September"
emiDue = 2500
status = LoanStatus.ACTIVE
type = LoanType.PERSONAL
} else {
amount = 25000
dueDate = "24th December"
interestRate = 12.5f
startDate = "24th September"
completionDate = "21 January"
status = LoanStatus.COMPLETED
type = LoanType.PERSONAL
}
}
}
myLoans.value = response.subList(0,7)
}
}
}