From 9224d51afd1734566862d7af709952565f2eadd8 Mon Sep 17 00:00:00 2001 From: panadax Date: Fri, 27 May 2022 16:48:24 +0200 Subject: [PATCH 1/4] fix offline leaderboard crash --- .../epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt index c600ca13..45fd7d98 100644 --- a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt +++ b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt @@ -81,9 +81,11 @@ class LeaderboardFragment : Fragment() { private fun loadPlayersUI(itemView: View, players: List) { - val champions = players.take(3) - showPlayersPosition(itemView, players) - showChampions(itemView, champions) + if(players.size > 3) { + val champions = players.take(3) + showPlayersPosition(itemView, players) + showChampions(itemView, champions) + } } From 6b7c54176ffb7fab1c8bc13998e01965ccf9b43d Mon Sep 17 00:00:00 2001 From: panadax Date: Sat, 28 May 2022 00:01:43 +0200 Subject: [PATCH 2/4] fix test --- .../ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt index 45fd7d98..91abd996 100644 --- a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt +++ b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt @@ -81,11 +81,11 @@ class LeaderboardFragment : Fragment() { private fun loadPlayersUI(itemView: View, players: List) { - if(players.size > 3) { + if(players.size >= 3) { val champions = players.take(3) - showPlayersPosition(itemView, players) showChampions(itemView, champions) } + showPlayersPosition(itemView, players) } From b1bc703d0c415f1ea35114039c6a7ece6397a918 Mon Sep 17 00:00:00 2001 From: panadax Date: Sat, 28 May 2022 22:09:45 +0200 Subject: [PATCH 3/4] show champions less than 3 --- .../rps/ui/leaderboard/LeaderboardFragment.kt | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt index 91abd996..14193de8 100644 --- a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt +++ b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt @@ -81,23 +81,19 @@ class LeaderboardFragment : Fragment() { private fun loadPlayersUI(itemView: View, players: List) { - if(players.size >= 3) { - val champions = players.take(3) - showChampions(itemView, champions) - } + val champions = players.take(3) + showChampions(itemView, champions) showPlayersPosition(itemView, players) } private fun showChampions(itemView: View, championPlayers: List) { - - itemView.findViewById(R.id.iv_champion1) - .load(championPlayers[0].userProfilePictureUrl) - itemView.findViewById(R.id.iv_champion2) - .load(championPlayers[1].userProfilePictureUrl) - itemView.findViewById(R.id.iv_champion3) - .load(championPlayers[2].userProfilePictureUrl) - + val championImgViewList = listOf(itemView.findViewById(R.id.iv_champion1),itemView.findViewById(R.id.iv_champion2), itemView.findViewById(R.id.iv_champion3)) + var index = 0 + for (championPlayer in championPlayers) { + championImgViewList[index].load(championPlayer.userProfilePictureUrl) + index += 1 + } } private fun showPlayersPosition( From 5ff587ff116b9a3baa0e172281b01372ee4c95fb Mon Sep 17 00:00:00 2001 From: panadax Date: Sat, 28 May 2022 22:30:54 +0200 Subject: [PATCH 4/4] change for loop --- .../ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt index 14193de8..86eb6ae5 100644 --- a/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt +++ b/app/src/main/java/ch/epfl/sweng/rps/ui/leaderboard/LeaderboardFragment.kt @@ -89,10 +89,8 @@ class LeaderboardFragment : Fragment() { private fun showChampions(itemView: View, championPlayers: List) { val championImgViewList = listOf(itemView.findViewById(R.id.iv_champion1),itemView.findViewById(R.id.iv_champion2), itemView.findViewById(R.id.iv_champion3)) - var index = 0 - for (championPlayer in championPlayers) { - championImgViewList[index].load(championPlayer.userProfilePictureUrl) - index += 1 + for ((i, championPlayer) in championPlayers.withIndex()) { + championImgViewList[i].load(championPlayer.userProfilePictureUrl) } }