Merge pull request 'Clean code ♻️' (#9) from API_NextStep into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #9
pull/10/head
Emre KARTAL 2 years ago
commit 5389b060eb

@ -50,10 +50,8 @@ class ApiManager : DataManager() {
override suspend fun getItemById(id: Int): Personne? = coroutineScope { override suspend fun getItemById(id: Int): Personne? = coroutineScope {
val personne = footballApi.getPlayer(id) val personne = footballApi.getPlayer(id)
personne?.let { return@coroutineScope personne.toModel()
return@coroutineScope personne.toModel()
}
return@coroutineScope null
} }
} }

@ -13,13 +13,14 @@ data class CurrentSeason(
) { ) {
fun toModel(): Season { fun toModel(): Season {
val calendar = Calendar.getInstance() val calendar = Calendar.getInstance()
val calendar2 = Calendar.getInstance()
return Season( return Season(
id, id,
calendar.apply { calendar.apply {
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(startDate) time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(startDate) as Date
}, },
calendar.apply { calendar2.apply {
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(endDate) time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(endDate) as Date
}, },
currentMatchday, currentMatchday,
if (winner is Int) winner else null if (winner is Int) winner else null

@ -22,7 +22,7 @@ class MatchResult(
homeTeam.toModel(), homeTeam.toModel(),
awayTeam.toModel(), awayTeam.toModel(),
Calendar.getInstance().apply { Calendar.getInstance().apply {
time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(utcDate) time = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(utcDate) as Date
}, },
status, status,
score.toModel(), score.toModel(),

@ -22,15 +22,15 @@ data class PlayerResponse(
lastName, lastName,
name, name,
Calendar.getInstance().apply { Calendar.getInstance().apply {
time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(dateOfBirth) time = SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(dateOfBirth) as Date
}, },
nationality, nationality,
Contract( Contract(
Calendar.getInstance().apply { Calendar.getInstance().apply {
time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.start) time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.start) as Date
}, },
Calendar.getInstance().apply { Calendar.getInstance().apply {
time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.until) time = SimpleDateFormat("yyyy-MM", Locale.US).parse(currentTeam.contract.until) as Date
} }
) )
) )

@ -55,11 +55,10 @@ class DetailFragment : Fragment() {
} }
}) })
viewModel.loadNumberMatches(id)
viewModel.competitionMatches.observe(viewLifecycleOwner, Observer { competitions -> viewModel.competitionMatches.observe(viewLifecycleOwner, Observer { competitions ->
competitions?.let { competitions?.let {
initRecyclerView(view) initRecyclerView(view)
viewModel.loadNumberMatches()
} }
}) })

@ -30,8 +30,7 @@ class DetailViewModel : ViewModel() {
.sortedByDescending { it.date } .sortedByDescending { it.date }
} }
fun loadNumberMatches(id: Int) = viewModelScope.launch { fun loadNumberMatches() = viewModelScope.launch {
val nb = manager.matchesMgr.getNbItemsByCompetition(id) nbCompetitionMatches.value = competitionMatches.value?.size
nbCompetitionMatches.value = nb
} }
} }
Loading…
Cancel
Save