AA-4 | Reyaz & Shashidhara | Implement method to fetch MyLoans in viewModel
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user