Realization of the API call in the Detail Page ✅
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
31d8f6d0cf
commit
64d75971b0
@ -1,4 +1,37 @@
|
||||
package uca.iut.clermont.view.viewModel
|
||||
|
||||
class DetailViewModel {
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.launch
|
||||
import uca.iut.clermont.api.ApiManager
|
||||
import uca.iut.clermont.model.Competition
|
||||
import uca.iut.clermont.model.Match
|
||||
import java.util.*
|
||||
|
||||
class DetailViewModel : ViewModel() {
|
||||
|
||||
val manager = ApiManager()
|
||||
val competition = MutableLiveData<Competition?>()
|
||||
val competitionMatches = MutableLiveData<List<Match>>()
|
||||
val nbCompetitionMatches = MutableLiveData<Int>()
|
||||
|
||||
fun loadCurrentCompetition(id: Int) = viewModelScope.launch {
|
||||
val result = manager.competitionsMgr.getItemById(id)
|
||||
competition.value = result
|
||||
}
|
||||
|
||||
fun loadMatches(id: Int) = viewModelScope.launch {
|
||||
|
||||
val matchResults = manager.matchesMgr.getItemsByCompetition(id)
|
||||
competitionMatches.value = matchResults.filter { it.status != "TIMED" && it.status != "SCHEDULED" }
|
||||
.apply { forEach { it.date.add(Calendar.HOUR_OF_DAY, 2) } }
|
||||
.sortedBy { it.competition.name }
|
||||
.sortedByDescending { it.date }
|
||||
}
|
||||
|
||||
fun loadNumberMatches(id: Int) = viewModelScope.launch {
|
||||
val nb = manager.matchesMgr.getNbItemsByCompetition(id)
|
||||
nbCompetitionMatches.value = nb
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
<resources>
|
||||
<string name="app_name">Scor_It</string>
|
||||
<string name="noMatches">No games started yet!</string>
|
||||
<string name="imageNotFound">Image not found</string>
|
||||
<string name="hello">Hello</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in new issue