Compare commits
No commits in common. 'master' and 'HorizontalView' have entirely different histories.
master
...
Horizontal
Before Width: | Height: | Size: 89 KiB |
Before Width: | Height: | Size: 75 KiB |
Before Width: | Height: | Size: 86 KiB |
Before Width: | Height: | Size: 35 KiB |
@ -1,119 +0,0 @@
|
||||
package uca.iut.clermont.api
|
||||
|
||||
import AreaManager
|
||||
import CompetitionsManager
|
||||
import DataManager
|
||||
import MatchesManager
|
||||
import PeopleManager
|
||||
import TeamsManager
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import uca.iut.clermont.model.*
|
||||
|
||||
val retrofit: Retrofit = Retrofit.Builder()
|
||||
.baseUrl("https://api.football-data.org/v4/")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
|
||||
val footballApi: FootballApi = retrofit.create(FootballApi::class.java)
|
||||
|
||||
class ApiManager : DataManager() {
|
||||
override val areaMgr: AreaManager = ApiAreaManager()
|
||||
override val peopleMgr: PeopleManager = ApiPeopleManager()
|
||||
override val matchesMgr: MatchesManager = ApiMatchesManager()
|
||||
override val competitionsMgr: CompetitionsManager = ApiCompetitionsManager()
|
||||
override val teamsMgr: TeamsManager = ApiTeamsManager()
|
||||
|
||||
class ApiAreaManager : AreaManager {
|
||||
|
||||
override suspend fun getItemsByName(substring: String): List<Area> = coroutineScope {
|
||||
val areas = footballApi.getAreas()
|
||||
return@coroutineScope areas.areas.filter { it.name.contains(substring) }
|
||||
}
|
||||
|
||||
override suspend fun getItems(): List<Area> = coroutineScope {
|
||||
val areas = footballApi.getAreas()
|
||||
return@coroutineScope areas.areas
|
||||
}
|
||||
|
||||
override suspend fun getItemById(id: Int): Area = coroutineScope {
|
||||
val area = footballApi.getArea(id)
|
||||
return@coroutineScope area
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ApiPeopleManager : PeopleManager {
|
||||
|
||||
override suspend fun getItems(): List<Personne> = listOf()
|
||||
|
||||
override suspend fun getItemById(id: Int): Personne? = coroutineScope {
|
||||
val personne = footballApi.getPlayer(id)
|
||||
return@coroutineScope personne.toModel()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class ApiMatchesManager : MatchesManager {
|
||||
|
||||
override suspend fun getNbItemsByCompetition(id: Int): Int = coroutineScope {
|
||||
val matches = footballApi.getMatchesByCompetition(id)
|
||||
return@coroutineScope matches.matches.size
|
||||
}
|
||||
|
||||
override suspend fun getItemsByCompetition(id: Int): List<Match> =
|
||||
coroutineScope {
|
||||
val matches = footballApi.getMatchesByCompetition(id)
|
||||
return@coroutineScope matches.matches.map { it.toModel() }
|
||||
}
|
||||
|
||||
override suspend fun getItems(): List<Match> = coroutineScope {
|
||||
val matches = footballApi.getMatches()
|
||||
return@coroutineScope matches.matches.map { matchResult -> matchResult.toModel() }
|
||||
}
|
||||
|
||||
override suspend fun getItemById(id: Int): Match = coroutineScope {
|
||||
val match = footballApi.getMatch(id)
|
||||
return@coroutineScope match.toModel()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ApiCompetitionsManager : CompetitionsManager {
|
||||
|
||||
override suspend fun getItemsByName(substring: String): List<Competition> = coroutineScope {
|
||||
val competitons = footballApi.getCompetitions()
|
||||
return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }
|
||||
.filter { it.name == substring }
|
||||
}
|
||||
|
||||
override suspend fun getItems(): List<Competition> = coroutineScope {
|
||||
val competitons = footballApi.getCompetitions()
|
||||
return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }
|
||||
.sortedBy { it.name }
|
||||
}
|
||||
|
||||
override suspend fun getItemById(id: Int): Competition = coroutineScope {
|
||||
val competition = footballApi.getCompetition(id)
|
||||
return@coroutineScope competition.toModel()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ApiTeamsManager : TeamsManager {
|
||||
|
||||
override fun getItemsByName(substring: String): List<Team> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getItems(): List<Team> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getItemById(id: Int): Team? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package uca.iut.clermont.api
|
||||
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Headers
|
||||
import retrofit2.http.Path
|
||||
import uca.iut.clermont.api.response.areaResponse.AreaResponse
|
||||
import uca.iut.clermont.api.response.competitionResponse.CompetitionResponse
|
||||
import uca.iut.clermont.api.response.competitionResponse.CompetitionResult
|
||||
import uca.iut.clermont.api.response.matchResponse.MatchResponse
|
||||
import uca.iut.clermont.api.response.matchResponse.MatchResult
|
||||
import uca.iut.clermont.model.Area
|
||||
import uca.iut.clermont.model.PlayerResponse
|
||||
|
||||
interface FootballApi {
|
||||
|
||||
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||
@GET("areas/{id}")
|
||||
suspend fun getArea(@Path("id") id: Int): Area
|
||||
|
||||
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||
@GET("areas")
|
||||
suspend fun getAreas(): AreaResponse
|
||||
|
||||
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||
@GET("persons/{id}")
|
||||
suspend fun getPlayer(@Path("id") playerId: Int): PlayerResponse
|
||||
|
||||
@Headers("X-Auth-Token: 621ef06e148542f98b4993a5442421eb")
|
||||
@GET("competitions")
|
||||
suspend fun getCompetitions(): CompetitionResponse
|
||||
|
||||
@Headers("X-Auth-Token: 8f51b43de0444026bd3ec3484f082575")
|
||||
@GET("competitions/{id}")
|
||||
suspend fun getCompetition(@Path("id") id: Int): CompetitionResult
|
||||
|
||||
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
|
||||
@GET("matches")
|
||||
suspend fun getMatches(): MatchResponse
|
||||
|
||||
@Headers("X-Auth-Token: 621ef06e148542f98b4993a5442421eb")
|
||||
@GET("matches/{id}")
|
||||
suspend fun getMatch(@Path("id") id: Int): MatchResult
|
||||
|
||||
@Headers("X-Auth-Token: b002ff114afa41a590e2baef63d8c689")
|
||||
@GET("competitions/{id}/matches")
|
||||
suspend fun getMatchesByCompetition(@Path("id") id: Int): MatchResponse
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package uca.iut.clermont.api.response.areaResponse
|
||||
|
||||
import uca.iut.clermont.model.Area
|
||||
|
||||
data class AreaResponse(
|
||||
val areas: List<Area>,
|
||||
val count: Int
|
||||
)
|
@ -1,7 +0,0 @@
|
||||
package uca.iut.clermont.api.response.competitionResponse
|
||||
|
||||
data class CompetitionResponse(
|
||||
val competitions: List<CompetitionResult>,
|
||||
val count: Int,
|
||||
val filters: Filters
|
||||
)
|
@ -1,24 +0,0 @@
|
||||
package uca.iut.clermont.api.response.competitionResponse
|
||||
|
||||
import uca.iut.clermont.model.Area
|
||||
import uca.iut.clermont.model.Competition
|
||||
|
||||
class CompetitionResult(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val code: String,
|
||||
val type: String,
|
||||
val emblem: String,
|
||||
val currentSeason: CurrentSeason,
|
||||
val area: Area
|
||||
) {
|
||||
fun toModel() = Competition(
|
||||
id,
|
||||
name,
|
||||
code,
|
||||
type,
|
||||
emblem,
|
||||
currentSeason.toModel(),
|
||||
area
|
||||
)
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package uca.iut.clermont.api.response.competitionResponse
|
||||
|
||||
import uca.iut.clermont.model.Season
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
data class CurrentSeason(
|
||||
val currentMatchday: Int,
|
||||
val endDate: String,
|
||||
val id: Int,
|
||||
val startDate: String,
|
||||
val winner: Any
|
||||
) {
|
||||
fun toModel(): Season {
|
||||
val calendar = Calendar.getInstance()
|
||||
val calendar2 = Calendar.getInstance()
|
||||
return Season(
|
||||
id,
|
||||
calendar.apply {
|
||||
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(startDate) as Date
|
||||
},
|
||||
calendar2.apply {
|
||||
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(endDate) as Date
|
||||
},
|
||||
currentMatchday,
|
||||
if (winner is Int) winner else null
|
||||
)
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package uca.iut.clermont.api.response.competitionResponse
|
||||
|
||||
data class Filters(
|
||||
val client: String
|
||||
)
|
@ -1,7 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
data class Filters(
|
||||
val dateFrom: String,
|
||||
val dateTo: String,
|
||||
val permission: String
|
||||
)
|
@ -1,23 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
import uca.iut.clermont.api.response.competitionResponse.CurrentSeason
|
||||
import uca.iut.clermont.model.Area
|
||||
import uca.iut.clermont.model.Competition
|
||||
|
||||
class MatchCompetitionResult(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val code: String,
|
||||
val type: String,
|
||||
val emblem: String
|
||||
) {
|
||||
fun toModel(season: CurrentSeason, area: Area) = Competition(
|
||||
id,
|
||||
name,
|
||||
code,
|
||||
type,
|
||||
emblem,
|
||||
season.toModel(),
|
||||
area
|
||||
)
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
data class MatchResponse(
|
||||
val filters: Filters,
|
||||
val matches: List<MatchResult>,
|
||||
val resultSet: ResultSet
|
||||
)
|
@ -1,32 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
import uca.iut.clermont.api.response.competitionResponse.CurrentSeason
|
||||
import uca.iut.clermont.model.Area
|
||||
import uca.iut.clermont.model.Match
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class MatchResult(
|
||||
val id: Int,
|
||||
val homeTeam: TeamResult,
|
||||
val awayTeam: TeamResult,
|
||||
val utcDate: String,
|
||||
val status: String,
|
||||
val score: ScoreResult,
|
||||
val season: CurrentSeason,
|
||||
val area: Area,
|
||||
val competition: MatchCompetitionResult
|
||||
) {
|
||||
fun toModel() = Match(
|
||||
id,
|
||||
homeTeam.toModel(),
|
||||
awayTeam.toModel(),
|
||||
Calendar.getInstance().apply {
|
||||
time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(utcDate) as Date
|
||||
},
|
||||
status,
|
||||
score.toModel(),
|
||||
competition.toModel(season, area)
|
||||
|
||||
)
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
data class ResultSet(
|
||||
val competitions: String,
|
||||
val count: Int,
|
||||
val first: String,
|
||||
val last: String,
|
||||
val played: Int
|
||||
)
|
@ -1,16 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
import uca.iut.clermont.model.Score
|
||||
|
||||
data class ScoreResult(
|
||||
val duration: String,
|
||||
val fullTime: Time,
|
||||
val halfTime: Time,
|
||||
val winner: String?
|
||||
){
|
||||
fun toModel() = Score(
|
||||
fullTime.home,
|
||||
fullTime.away,
|
||||
winner
|
||||
)
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
import uca.iut.clermont.model.Area
|
||||
import uca.iut.clermont.model.Coach
|
||||
import uca.iut.clermont.model.Contract
|
||||
import uca.iut.clermont.model.Team
|
||||
import java.util.*
|
||||
|
||||
class TeamResult(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val shortName: String,
|
||||
val crest: String
|
||||
) {
|
||||
fun toModel() = Team(
|
||||
id,
|
||||
name,
|
||||
shortName,
|
||||
crest,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
Area(1, "", "", "", ""),
|
||||
"",
|
||||
Coach(
|
||||
1, "", "", "", Calendar.getInstance()
|
||||
.apply { set(2022, 12, 28) }, "",
|
||||
Contract(
|
||||
Calendar.getInstance().apply { set(2020, 7, 1) },
|
||||
Calendar.getInstance().apply { set(2024, 7, 1) })
|
||||
),
|
||||
listOf(),
|
||||
listOf()
|
||||
|
||||
)
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package uca.iut.clermont.api.response.matchResponse
|
||||
|
||||
data class Time(
|
||||
val away: Int?,
|
||||
val home: Int?
|
||||
)
|
@ -1,6 +0,0 @@
|
||||
package uca.iut.clermont.api.response.playerResponse
|
||||
|
||||
data class ContractResponse(
|
||||
val start: String,
|
||||
val until: String
|
||||
)
|
@ -1,7 +0,0 @@
|
||||
package uca.iut.clermont.api.response.playerResponse
|
||||
|
||||
data class CurrentTeamResponse(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val contract: ContractResponse
|
||||
)
|
@ -1,38 +0,0 @@
|
||||
package uca.iut.clermont.model
|
||||
|
||||
import uca.iut.clermont.api.response.playerResponse.CurrentTeamResponse
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
data class PlayerResponse(
|
||||
val id: Int,
|
||||
val firstName: String,
|
||||
val lastName: String,
|
||||
val name: String,
|
||||
val dateOfBirth: String,
|
||||
val nationality: String,
|
||||
val position: String,
|
||||
val shirtNumber: Int,
|
||||
val lastUpdated: String,
|
||||
val currentTeam: CurrentTeamResponse
|
||||
) {
|
||||
fun toModel() = Personne(
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
name,
|
||||
Calendar.getInstance().apply {
|
||||
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(dateOfBirth) as Date
|
||||
},
|
||||
nationality,
|
||||
Contract(
|
||||
Calendar.getInstance().apply {
|
||||
time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.start) as Date
|
||||
},
|
||||
Calendar.getInstance().apply {
|
||||
time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.until) as Date
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package uca.iut.clermont.data
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import uca.iut.clermont.data.dao.CompetitionDao
|
||||
import uca.iut.clermont.model.Competition
|
||||
|
||||
@Database(entities = arrayOf(Competition::class), version = 1)
|
||||
abstract class BDD : RoomDatabase() {
|
||||
|
||||
abstract fun competitionDao(): CompetitionDao
|
||||
|
||||
companion object {
|
||||
|
||||
private var INSTANCE: BDD? = null
|
||||
|
||||
fun getInstance(context: Context) =
|
||||
INSTANCE ?: synchronized(this) {
|
||||
val db = Room.databaseBuilder(
|
||||
context,
|
||||
BDD::class.java,
|
||||
"ScorItDB"
|
||||
).build()
|
||||
INSTANCE = db
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package uca.iut.clermont.data.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Delete
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import uca.iut.clermont.model.Competition
|
||||
|
||||
@Dao
|
||||
interface CompetitionDao {
|
||||
|
||||
@Delete
|
||||
fun deleteCompetition(competition: Competition)
|
||||
|
||||
@Query("SELECT * FROM competition")
|
||||
fun getAllCompetitions(): Flow<List<Competition>>
|
||||
|
||||
@Insert
|
||||
fun insertCompetition(competition: Competition)
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package uca.iut.clermont.model
|
||||
|
||||
import AreaManager
|
||||
import CompetitionsManager
|
||||
import DataManager
|
||||
import MatchesManager
|
||||
import PeopleManager
|
||||
import TeamsManager
|
||||
|
||||
class ApiManager : DataManager() {
|
||||
override val areaMgr: AreaManager = ApiAreaManager()
|
||||
override val peopleMgr: PeopleManager = ApiPeopleManager()
|
||||
override val matchesMgr: MatchesManager = ApiMatchesManager()
|
||||
override val competitionsMgr: CompetitionsManager = ApiCompetitionsManager()
|
||||
override val teamsMgr: TeamsManager = ApiTeamsManager()
|
||||
|
||||
class ApiAreaManager : AreaManager {
|
||||
override fun getItemsByName(substring: String): List<Area> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItems(): List<Area> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItemById(id: Int): Area? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ApiPeopleManager : PeopleManager {
|
||||
override fun getItemsByName(substring: String): List<Personne> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItems(): List<Personne> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItemById(id: Int): Personne? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ApiMatchesManager : MatchesManager {
|
||||
override fun getNbItemsByCompetition(substring: String): Int {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItemsByCompetition(substring: String): List<Match> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItems(): List<Match> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItemById(id: Int): Match? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ApiCompetitionsManager : CompetitionsManager {
|
||||
override fun getItemsByName(substring: String): List<Competition> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItems(): List<Competition> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItemById(id: Int): Competition? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ApiTeamsManager : TeamsManager {
|
||||
override fun getItemsByName(substring: String): List<Team> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItems(): List<Team> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItemById(id: Int): Team? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,16 +1,11 @@
|
||||
package uca.iut.clermont.model
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "competitions")
|
||||
class Competition(
|
||||
@PrimaryKey val id: Int,
|
||||
@ColumnInfo val name: String,
|
||||
@ColumnInfo val code: String,
|
||||
@ColumnInfo val type: String,
|
||||
@ColumnInfo val emblem: String,
|
||||
@ColumnInfo val currentSeason: Season,
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val code: String,
|
||||
val type: String,
|
||||
val emblem: String,
|
||||
val currentSeason: Season,
|
||||
val area: Area
|
||||
)
|
@ -1,6 +1,6 @@
|
||||
package uca.iut.clermont.model
|
||||
|
||||
interface GenericDataManager<T> {
|
||||
suspend fun getItems(): List<T>
|
||||
suspend fun getItemById(id: Int): T?
|
||||
fun getItems(): List<T>
|
||||
fun getItemById(id: Int): T?
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package uca.iut.clermont.model
|
||||
|
||||
class Score(
|
||||
val home: Int?,
|
||||
val away: Int?,
|
||||
val winner: String?
|
||||
val home: Int,
|
||||
val away: Int,
|
||||
val winner: String
|
||||
)
|
@ -0,0 +1,13 @@
|
||||
package uca.iut.clermont.view
|
||||
|
||||
import com.bumptech.glide.annotation.GlideModule
|
||||
import com.bumptech.glide.module.AppGlideModule
|
||||
|
||||
@GlideModule
|
||||
class SampleGlideModule : AppGlideModule() {
|
||||
|
||||
override fun isManifestParsingEnabled(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package uca.iut.clermont.view.viewModel
|
||||
|
||||
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(
|
||||
//val dao: CompetitionDao
|
||||
) : ViewModel() {
|
||||
|
||||
val manager = ApiManager()
|
||||
val competition = MutableLiveData<Competition?>()
|
||||
val competitionMatches = MutableLiveData<List<Match>>()
|
||||
val nbCompetitionMatches = MutableLiveData<Int>()
|
||||
|
||||
/*fun insertCompetition(competition: Competition) =
|
||||
viewModelScope.launch {
|
||||
dao.insertCompetition(competition)
|
||||
}
|
||||
*/
|
||||
|
||||
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" && it.status != "POSTPONED" }
|
||||
.apply { forEach { it.date.add(Calendar.HOUR_OF_DAY, 2) } }
|
||||
.sortedBy { it.competition.name }
|
||||
.sortedByDescending { it.date }
|
||||
}
|
||||
|
||||
fun loadNumberMatches() = viewModelScope.launch {
|
||||
nbCompetitionMatches.value = competitionMatches.value?.size
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package uca.iut.clermont.view.viewModel
|
||||
|
||||
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
|
||||
|
||||
class FavoriteViewModel(
|
||||
//val dao: CompetitionDao
|
||||
) : ViewModel() {
|
||||
|
||||
val manager = ApiManager()
|
||||
val competitions = MutableLiveData<List<Competition>>()
|
||||
|
||||
//fun getAllCompetitions() = dao.getAllCompetitions()
|
||||
//.isLiveDate()
|
||||
|
||||
fun loadCompetitions() = viewModelScope.launch {
|
||||
val result = manager.competitionsMgr.getItems()
|
||||
competitions.value = result
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package uca.iut.clermont.view.viewModel
|
||||
|
||||
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.Match
|
||||
import java.util.*
|
||||
|
||||
class HomeViewModel : ViewModel() {
|
||||
|
||||
val manager = ApiManager()
|
||||
val matches = MutableLiveData<List<Match>?>()
|
||||
|
||||
fun loadMatches() = viewModelScope.launch {
|
||||
val matchResults = manager.matchesMgr.getItems()
|
||||
matches.value = matchResults.filter { it.status != "TIMED" }
|
||||
.apply { forEach { it.date.add(Calendar.HOUR_OF_DAY, 2) } }
|
||||
.sortedBy { it.competition.name }
|
||||
.sortedByDescending { it.date }
|
||||
}
|
||||
|
||||
}
|
Before Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 8.7 KiB |
@ -1,7 +1,3 @@
|
||||
<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>
|