diff --git a/.drone.yml b/.drone.yml
index 28b449f..51f53b2 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -8,12 +8,17 @@ trigger:
steps:
- name: code-analysis
- image: androidsdk/android-31
+ image: openjdk:8-jdk
environment:
- SONAR_TOKEN:
- from_secret: SECRET_TOKEN
+ SONAR_TOKEN:
+ from_secret: SECRET_TOKEN
settings:
- sources: ./src/
+ sources: ./src/
commands:
- - cd src
- - ./gradlew --no-daemon :app:assembleDebug sonarqube -Dsonar.projectKey=Scor_It -Dsonar.host.url=https://codefirst.iut.uca.fr/sonar -Dsonar.login=$${SONAR_TOKEN}
\ No newline at end of file
+ - export SONAR_SCANNER_VERSION=4.7.0.2747
+ - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
+ - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
+ - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
+ - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
+ - export SONAR_SCANNER_OPTS="-server"
+ - sonar-scanner -D sonar.projectKey=Scor_It -D sonar.sources=./src -D sonar.host.url=https://codefirst.iut.uca.fr/sonar
\ No newline at end of file
diff --git a/src/app/build.gradle b/src/app/build.gradle
index 6206e55..0c2eeee 100644
--- a/src/app/build.gradle
+++ b/src/app/build.gradle
@@ -45,7 +45,7 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
- implementation 'androidx.core:core-ktx:1.7.0'
+ implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
diff --git a/src/app/src/main/java/uca/iut/clermont/api/ApiManager.kt b/src/app/src/main/java/uca/iut/clermont/api/ApiManager.kt
index 0259afc..48b9d2e 100644
--- a/src/app/src/main/java/uca/iut/clermont/api/ApiManager.kt
+++ b/src/app/src/main/java/uca/iut/clermont/api/ApiManager.kt
@@ -10,8 +10,6 @@ import kotlinx.coroutines.coroutineScope
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import uca.iut.clermont.model.*
-import java.text.SimpleDateFormat
-import java.util.*
val retrofit: Retrofit = Retrofit.Builder()
.baseUrl("https://api.football-data.org/v4/")
@@ -29,29 +27,26 @@ class ApiManager : DataManager() {
class ApiAreaManager : AreaManager {
- override fun getItemsByName(substring: String): List {
- TODO("Not yet implemented")
+ override suspend fun getItemsByName(substring: String): List = coroutineScope {
+ val areas = footballApi.getAreas()
+ return@coroutineScope areas.areas.filter { it.name.contains(substring) }
}
- override suspend fun getItems(): List {
- TODO("Not yet implemented")
+ override suspend fun getItems(): List = coroutineScope {
+ val areas = footballApi.getAreas()
+ return@coroutineScope areas.areas
}
- override suspend fun getItemById(id: Int): Area? {
- TODO("Not yet implemented")
+ override suspend fun getItemById(id: Int): Area = coroutineScope {
+ val area = footballApi.getArea(id)
+ return@coroutineScope area
}
}
class ApiPeopleManager : PeopleManager {
- override fun getItemsByName(substring: String): List {
- TODO("Not yet implemented")
- }
-
- override suspend fun getItems(): List {
- TODO("Not yet implemented")
- }
+ override suspend fun getItems(): List = listOf()
override suspend fun getItemById(id: Int): Personne? = coroutineScope {
val personne = footballApi.getPlayer(id)
@@ -63,42 +58,53 @@ class ApiManager : DataManager() {
}
class ApiMatchesManager : MatchesManager {
- override fun getNbItemsByCompetition(substring: String): Int {
- TODO("Not yet implemented")
- }
- override fun getItemsByCompetition(substring: String): List {
- TODO("Not yet implemented")
+ 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 =
+ coroutineScope {
+ val matches = footballApi.getMatchesByCompetition(id)
+ return@coroutineScope matches.matches.map { it.toModel() }
+ }
+
override suspend fun getItems(): List = coroutineScope {
val matches = footballApi.getMatches()
return@coroutineScope matches.matches.map { matchResult -> matchResult.toModel() }
}
- override suspend fun getItemById(id: Int): Match? {
- TODO("Not yet implemented")
+ override suspend fun getItemById(id: Int): Match = coroutineScope {
+ val match = footballApi.getMatch(id)
+ return@coroutineScope match.toModel()
}
}
class ApiCompetitionsManager : CompetitionsManager {
- override fun getItemsByName(substring: String): List {
- TODO("Not yet implemented")
+
+ override suspend fun getItemsByName(substring: String): List = coroutineScope {
+ val competitons = footballApi.getCompetitions()
+ return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }
+ .filter { it.name == substring }
}
override suspend fun getItems(): List = coroutineScope {
val competitons = footballApi.getCompetitions()
- return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }.sortedBy { it.name }
+ return@coroutineScope competitons.competitions.map { competitionResult -> competitionResult.toModel() }
+ .sortedBy { it.name }
}
- override suspend fun getItemById(id: Int): Competition? {
- TODO("Not yet implemented")
+ 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 {
TODO("Not yet implemented")
}
diff --git a/src/app/src/main/java/uca/iut/clermont/api/FootballApi.kt b/src/app/src/main/java/uca/iut/clermont/api/FootballApi.kt
index 4839b6e..93ba88f 100644
--- a/src/app/src/main/java/uca/iut/clermont/api/FootballApi.kt
+++ b/src/app/src/main/java/uca/iut/clermont/api/FootballApi.kt
@@ -3,29 +3,46 @@ 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(): List
+ suspend fun getAreas(): AreaResponse
@Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
@GET("persons/{id}")
suspend fun getPlayer(@Path("id") playerId: Int): PlayerResponse
- @Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
- @GET("persons")
- suspend fun getPlayers(): List
-
- @Headers("X-Auth-Token: 7814ffe5b0314b5291a287d32a178e57")
+ @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
+
}
diff --git a/src/app/src/main/java/uca/iut/clermont/api/response/areaResponse/AreaResponse.kt b/src/app/src/main/java/uca/iut/clermont/api/response/areaResponse/AreaResponse.kt
new file mode 100644
index 0000000..a8c71b9
--- /dev/null
+++ b/src/app/src/main/java/uca/iut/clermont/api/response/areaResponse/AreaResponse.kt
@@ -0,0 +1,8 @@
+package uca.iut.clermont.api.response.areaResponse
+
+import uca.iut.clermont.model.Area
+
+data class AreaResponse(
+ val areas: List,
+ val count: Int
+)
\ No newline at end of file
diff --git a/src/app/src/main/java/uca/iut/clermont/data/StubData.kt b/src/app/src/main/java/uca/iut/clermont/data/StubData.kt
index 95d1e4b..862cd53 100644
--- a/src/app/src/main/java/uca/iut/clermont/data/StubData.kt
+++ b/src/app/src/main/java/uca/iut/clermont/data/StubData.kt
@@ -246,7 +246,7 @@ class StubData : DataManager() {
)
)
- private val random = java.util.Random()
+ private val random = Random()
val matchList: MutableList = mutableListOf()
fun initMatches() {
@@ -421,7 +421,7 @@ class StubData : DataManager() {
class StubAreaManager(private val parent: StubData) : AreaManager {
- override fun getItemsByName(substring: String) =
+ override suspend fun getItemsByName(substring: String) =
parent.areaList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems(): List = parent.areaList
@@ -431,8 +431,6 @@ class StubData : DataManager() {
}
class StubPeopleManager(private val parent: StubData) : PeopleManager {
- override fun getItemsByName(substring: String) =
- parent.peopleList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems() = parent.peopleList
@@ -440,11 +438,12 @@ class StubData : DataManager() {
}
class StubMatchesManager(private val parent: StubData) : MatchesManager {
- override fun getNbItemsByCompetition(substring: String) =
- parent.matchList.filter { it.competition.name.contains(substring) }.count()
- override fun getItemsByCompetition(substring: String) =
- parent.matchList.filter { it.competition.name.contains(substring) }
+ override suspend fun getNbItemsByCompetition(id: Int) =
+ parent.matchList.filter { it.competition.id == id }.size
+
+ override suspend fun getItemsByCompetition(id: Int) =
+ parent.matchList.filter { it.competition.id == id }
override suspend fun getItems(): List = parent.matchList
@@ -453,7 +452,7 @@ class StubData : DataManager() {
}
class StubCompetitionsManager(private val parent: StubData) : CompetitionsManager {
- override fun getItemsByName(substring: String) =
+ override suspend fun getItemsByName(substring: String) =
parent.competitionList.filter { it.name.contains(substring, ignoreCase = true) }
override suspend fun getItems() = parent.competitionList
diff --git a/src/app/src/main/java/uca/iut/clermont/model/DataManager.kt b/src/app/src/main/java/uca/iut/clermont/model/DataManager.kt
index c62bc7a..0910fc8 100644
--- a/src/app/src/main/java/uca/iut/clermont/model/DataManager.kt
+++ b/src/app/src/main/java/uca/iut/clermont/model/DataManager.kt
@@ -9,22 +9,20 @@ abstract class DataManager {
}
interface AreaManager : GenericDataManager {
- fun getItemsByName(substring: String): List
+ suspend fun getItemsByName(substring: String): List
}
-interface PeopleManager : GenericDataManager {
- fun getItemsByName(substring: String): List
-}
+interface PeopleManager : GenericDataManager {}
interface MatchesManager : GenericDataManager {
- fun getNbItemsByCompetition(substring: String): Int
+ suspend fun getNbItemsByCompetition(id: Int): Int
- fun getItemsByCompetition(substring: String): List
+ suspend fun getItemsByCompetition(id: Int): List
}
interface CompetitionsManager : GenericDataManager {
- fun getItemsByName(substring: String): List
+ suspend fun getItemsByName(substring: String): List
}
interface TeamsManager : GenericDataManager {
diff --git a/src/app/src/main/java/uca/iut/clermont/view/DetailFragment.kt b/src/app/src/main/java/uca/iut/clermont/view/DetailFragment.kt
index 4a68b36..41ca7fc 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/DetailFragment.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/DetailFragment.kt
@@ -8,13 +8,16 @@ import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
+import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
-import androidx.recyclerview.widget.LinearLayoutManager
-import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import uca.iut.clermont.R
+import androidx.lifecycle.Observer
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
import uca.iut.clermont.model.Competition
import uca.iut.clermont.view.adapter.MatchesAdapter
+import uca.iut.clermont.view.viewModel.DetailViewModel
import java.text.SimpleDateFormat
import java.util.*
@@ -22,6 +25,8 @@ class DetailFragment : Fragment() {
private var isLiked = false
private lateinit var competition: Competition
+ private val viewModel: DetailViewModel by viewModels()
+
override fun onCreateView(
inflater: LayoutInflater,
@@ -33,10 +38,33 @@ class DetailFragment : Fragment() {
val id = arguments?.getInt("idItem")!!
- //competition = (activity as MainActivity).manager.competitionsMgr.getItemById(id)!!
- initializeView(view)
- initRecyclerView(view)
+ viewModel.competition.observe(viewLifecycleOwner, Observer { comp ->
+ comp?.let {
+ competition = comp
+ initializeView(view)
+ initRecyclerView(view)
+ }
+ })
+
+ viewModel.loadCurrentCompetition(id)
+
+ viewModel.nbCompetitionMatches.observe(viewLifecycleOwner, Observer { comp ->
+ comp?.let {
+ initNumberMatches(view)
+ }
+ })
+
+ viewModel.loadNumberMatches(id)
+
+ viewModel.competitionMatches.observe(viewLifecycleOwner, Observer { competitions ->
+ competitions?.let {
+ initRecyclerView(view)
+ }
+ })
+
+
+ viewModel.loadMatches(id)
return view;
}
@@ -79,20 +107,23 @@ class DetailFragment : Fragment() {
dateStart.text = formattedDate
- nbMatches.text =
- (activity as MainActivity).manager.matchesMgr.getNbItemsByCompetition(competition.name)
- .toString()
}
+ private fun initNumberMatches(view: View) {
+ val nbMatches = view.findViewById(R.id.nbMatches)
+
+ nbMatches.text = viewModel.nbCompetitionMatches.value.toString()
+ }
private fun initRecyclerView(view: View) {
val recyclerViewMatches = view.findViewById(R.id.listRecentsMatches)
with(recyclerViewMatches) {
layoutManager = LinearLayoutManager(view.context)
- adapter = MatchesAdapter(
- (activity as MainActivity).manager.matchesMgr.getItemsByCompetition(competition.name)
- .toList().toTypedArray()
- )
+ adapter = viewModel.competitionMatches.value?.toList()?.let {
+ MatchesAdapter(
+ it.toTypedArray()
+ )
+ }
}
}
diff --git a/src/app/src/main/java/uca/iut/clermont/view/FavoriteFragment.kt b/src/app/src/main/java/uca/iut/clermont/view/FavoriteFragment.kt
index c7e2660..8052d67 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/FavoriteFragment.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/FavoriteFragment.kt
@@ -6,7 +6,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageButton
-import android.widget.TextView
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
@@ -21,7 +20,7 @@ import uca.iut.clermont.view.viewModel.FavoriteViewModel
class FavoriteFragment : Fragment(), FavoritesAdapter.OnItemClickListener {
- private val viewModel: FavoriteViewModel by viewModels()
+ private val viewModel: FavoriteViewModel by viewModels()
override fun onCreateView(
inflater: LayoutInflater,
@@ -72,8 +71,8 @@ class FavoriteFragment : Fragment(), FavoritesAdapter.OnItemClickListener {
}
override fun onItemClick(position: Int) {
- /*val competitions = viewModel.competitions
+ val competitions = viewModel.competitions.value!!
val bundle = bundleOf("idItem" to competitions[position].id)
- findNavController().navigate(R.id.action_favoriteFragment_to_detailFragment, bundle)*/
+ findNavController().navigate(R.id.action_favoriteFragment_to_detailFragment, bundle)
}
}
\ No newline at end of file
diff --git a/src/app/src/main/java/uca/iut/clermont/view/HomeFragment.kt b/src/app/src/main/java/uca/iut/clermont/view/HomeFragment.kt
index e32d365..3a17e9b 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/HomeFragment.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/HomeFragment.kt
@@ -19,7 +19,7 @@ import uca.iut.clermont.view.viewModel.HomeViewModel
class HomeFragment : Fragment() {
- val viewModel: HomeViewModel by viewModels()
+ val viewModel: HomeViewModel by viewModels()
override fun onCreateView(
inflater: LayoutInflater,
@@ -29,26 +29,30 @@ class HomeFragment : Fragment() {
val view = inflater.inflate(R.layout.fragment_home, container, false)
- val text = view.findViewById(R.id.textEmpty)
+ val buttonFavorite = view.findViewById(R.id.buttonFavorite)
+ val restartMatches = view.findViewById(R.id.restartMatches)
+ val text = view.findViewById(R.id.textEmpty)
viewModel.matches.observe(viewLifecycleOwner, Observer { matches ->
matches?.let {
if (it.isNotEmpty()) {
initRecyclerView(view, it)
} else {
- text.setText("No games started yet!")
+ text.setText(R.string.noMatches)
}
}
})
- viewModel.loadMatches()
-
- val buttonFavorite = view.findViewById(R.id.buttonFavorite)
+ displayMatches()
buttonFavorite.setOnClickListener {
findNavController().navigate(R.id.favoriteFragment)
}
+ restartMatches.setOnClickListener {
+ displayMatches()
+ }
+
return view
}
@@ -57,9 +61,11 @@ class HomeFragment : Fragment() {
with(recyclerViewMatches) {
layoutManager = LinearLayoutManager(view.context)
adapter = MatchesAdapter(matches.toList().toTypedArray())
-
}
+ }
+ private fun displayMatches() {
+ viewModel.loadMatches()
}
diff --git a/src/app/src/main/java/uca/iut/clermont/view/StartFragment.kt b/src/app/src/main/java/uca/iut/clermont/view/StartFragment.kt
index 3d0940d..ac43dc3 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/StartFragment.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/StartFragment.kt
@@ -11,16 +11,10 @@ import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.ImageView
-import android.widget.TextView
import androidx.core.view.marginStart
import androidx.fragment.app.Fragment
-import androidx.fragment.app.activityViewModels
-import androidx.fragment.app.viewModels
-import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import uca.iut.clermont.R
-import uca.iut.clermont.view.viewModel.HomeViewModel
-
class StartFragment : Fragment(), SensorEventListener {
diff --git a/src/app/src/main/java/uca/iut/clermont/view/adapter/MatchesAdapter.kt b/src/app/src/main/java/uca/iut/clermont/view/adapter/MatchesAdapter.kt
index b54566b..42422cb 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/adapter/MatchesAdapter.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/adapter/MatchesAdapter.kt
@@ -33,11 +33,41 @@ class MatchesAdapter(private val recentMatches: Array) :
}
val date = recentMatches[position].date
-
- val formatter = SimpleDateFormat("dd-MM-yyyy", Locale.US)
+ val formatter = SimpleDateFormat("dd/MM/yyyy' 'HH:mm", Locale.US)
val formattedDate = formatter.format(date.time)
- holder.dateCompetition.text = recentMatches[position].competition.name.plus(" : ").plus(formattedDate)
+ with(holder.iconStatus) {
+ setImageResource(R.drawable.mi_temp)
+ layoutParams.width = 0
+ layoutParams.height = 0
+ (layoutParams as ViewGroup.MarginLayoutParams).apply {
+ topMargin = 8
+ bottomMargin = 7
+ }
+ }
+
+ if (recentMatches[position].status == "IN_PLAY") {
+ with(holder.iconStatus) {
+ setImageResource(R.drawable.live)
+ layoutParams.width = 130
+ layoutParams.height = 130
+ (layoutParams as ViewGroup.MarginLayoutParams).apply {
+ topMargin = 0
+ bottomMargin = 0
+ }
+ }
+ }
+
+ if (recentMatches[position].status == "PAUSED") {
+ with(holder.iconStatus) {
+ setImageResource(R.drawable.mi_temp)
+ layoutParams.width = 100
+ layoutParams.height = 100
+ }
+ }
+
+ holder.dateCompetition.text =
+ recentMatches[position].competition.name.plus(" : ").plus(formattedDate)
Glide.with(holder.itemView.context)
.load(recentMatches[position].homeTeam.crest)
diff --git a/src/app/src/main/java/uca/iut/clermont/view/viewHolder/MatchHolder.kt b/src/app/src/main/java/uca/iut/clermont/view/viewHolder/MatchHolder.kt
index cd63f51..6869eb1 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/viewHolder/MatchHolder.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/viewHolder/MatchHolder.kt
@@ -13,6 +13,7 @@ class MatchHolder(view: View) : RecyclerView.ViewHolder(view) {
val scoreAwayTeam: TextView
val imageHomeTeam: ImageView
val imageAwayTeam: ImageView
+ val iconStatus: ImageView
val dateCompetition: TextView
init {
@@ -23,6 +24,7 @@ class MatchHolder(view: View) : RecyclerView.ViewHolder(view) {
imageHomeTeam = view.findViewById(R.id.ImageFirstTeam)
imageAwayTeam = view.findViewById(R.id.ImageSecondTeam)
dateCompetition = view.findViewById(R.id.DateCompetition)
+ iconStatus = view.findViewById(R.id.iconStatus)
}
diff --git a/src/app/src/main/java/uca/iut/clermont/view/viewModel/DetailViewModel.kt b/src/app/src/main/java/uca/iut/clermont/view/viewModel/DetailViewModel.kt
index 8865287..2e531fc 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/viewModel/DetailViewModel.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/viewModel/DetailViewModel.kt
@@ -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()
+ val competitionMatches = MutableLiveData>()
+ val nbCompetitionMatches = MutableLiveData()
+
+ 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
+ }
}
\ No newline at end of file
diff --git a/src/app/src/main/java/uca/iut/clermont/view/viewModel/HomeViewModel.kt b/src/app/src/main/java/uca/iut/clermont/view/viewModel/HomeViewModel.kt
index 996ce80..454642f 100644
--- a/src/app/src/main/java/uca/iut/clermont/view/viewModel/HomeViewModel.kt
+++ b/src/app/src/main/java/uca/iut/clermont/view/viewModel/HomeViewModel.kt
@@ -6,6 +6,7 @@ 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() {
@@ -13,8 +14,11 @@ class HomeViewModel : ViewModel() {
val matches = MutableLiveData?>()
fun loadMatches() = viewModelScope.launch {
- val matchResult = manager.matchesMgr.getItems()
- matches.value = matchResult.filter { it.status == "FINISHED" }
+ 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 }
}
}
\ No newline at end of file
diff --git a/src/app/src/main/res/drawable/live.png b/src/app/src/main/res/drawable/live.png
new file mode 100644
index 0000000..127a50c
Binary files /dev/null and b/src/app/src/main/res/drawable/live.png differ
diff --git a/src/app/src/main/res/drawable/mi_temp.png b/src/app/src/main/res/drawable/mi_temp.png
new file mode 100644
index 0000000..b3da61e
Binary files /dev/null and b/src/app/src/main/res/drawable/mi_temp.png differ
diff --git a/src/app/src/main/res/drawable/restart.png b/src/app/src/main/res/drawable/restart.png
new file mode 100644
index 0000000..e551024
Binary files /dev/null and b/src/app/src/main/res/drawable/restart.png differ
diff --git a/src/app/src/main/res/layout-land/fragment_favorite.xml b/src/app/src/main/res/layout-land/fragment_favorite.xml
index dbc24bd..ec5cd2f 100644
--- a/src/app/src/main/res/layout-land/fragment_favorite.xml
+++ b/src/app/src/main/res/layout-land/fragment_favorite.xml
@@ -20,7 +20,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
- android:src="@drawable/arrow" />
+ android:src="@drawable/arrow"
+ android:contentDescription="@string/imageNotFound" />
@@ -28,10 +28,11 @@
android:id="@+id/buttonFavorite"
android:layout_width="34dp"
android:layout_height="34dp"
- android:layout_gravity="right"
+ android:layout_gravity="end"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
- android:src="@drawable/icon_like" />
+ android:src="@drawable/icon_like"
+ android:contentDescription="@string/imageNotFound" />
diff --git a/src/app/src/main/res/layout/cellule_favorite.xml b/src/app/src/main/res/layout/cellule_favorite.xml
index 1afd0d7..20d4a53 100644
--- a/src/app/src/main/res/layout/cellule_favorite.xml
+++ b/src/app/src/main/res/layout/cellule_favorite.xml
@@ -1,11 +1,11 @@
+ android:layout_marginVertical="10dp"
+ android:contentDescription="@string/imageNotFound"/>
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="5dp">
+
+
+
+
+
+
+ android:baselineAligned="false"
+ android:gravity="center"
+ android:orientation="horizontal">
+ android:src="@drawable/arrow"
+ android:contentDescription="@string/imageNotFound" />
@@ -29,10 +29,11 @@
android:id="@+id/buttonFavorite"
android:layout_width="34dp"
android:layout_height="34dp"
- android:layout_gravity="right"
+ android:layout_gravity="end"
android:background="@android:color/transparent"
android:scaleType="fitCenter"
- android:src="@drawable/icon_like" />
+ android:src="@drawable/icon_like"
+ android:contentDescription="@string/imageNotFound" />
@@ -95,21 +96,34 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchBarContainer" />
+
+
+ app:layout_constraintTop_toTopOf="parent"
+ android:contentDescription="@string/imageNotFound" />
Scor_It
+ No games started yet!
+ Image not found
+ Hello
+
\ No newline at end of file