Merge pull request 'API_NextStep' (#8) from API_NextStep into master
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #8pull/10/head
commit
a5e07309ba
@ -0,0 +1,8 @@
|
|||||||
|
package uca.iut.clermont.api.response.areaResponse
|
||||||
|
|
||||||
|
import uca.iut.clermont.model.Area
|
||||||
|
|
||||||
|
data class AreaResponse(
|
||||||
|
val areas: List<Area>,
|
||||||
|
val count: Int
|
||||||
|
)
|
@ -1,4 +1,37 @@
|
|||||||
package uca.iut.clermont.view.viewModel
|
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
|
||||||
|
}
|
||||||
}
|
}
|
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 8.7 KiB |
@ -1,3 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Scor_It</string>
|
<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>
|
</resources>
|
Loading…
Reference in new issue