Skip to content

Commit

Permalink
Merge pull request #82 from Picard4/Group-14-Palmar
Browse files Browse the repository at this point in the history
Group 14 palmar
  • Loading branch information
Picard4 authored Apr 28, 2024
2 parents f8bae70 + 5734139 commit 0bf809f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@ Appfile
releasePlayStore/*
Gemfile.lock

.DS_Store
.DS_Store
/.idea/sonarlint
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -37,6 +36,11 @@ protected void onCreate(Bundle savedInstanceState) {
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
/*
This method only exists out of obligation.
We just need an onPageSelected override to ensure that the leaderboardPagerAdapter's
currentLeaderboardFragment remains up to date when the user switches leaderboards.
*/
}

@Override
Expand All @@ -46,6 +50,11 @@ public void onPageSelected(int position) {

@Override
public void onPageScrollStateChanged(int state) {
/*
This method only exists out of obligation.
We just need an onPageSelected override to ensure that the leaderboardPagerAdapter's
currentLeaderboardFragment remains up to date when the user switches leaderboards.
*/
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public LeaderboardPagerAdapter(FragmentManager fm) {
}

public enum LeaderboardType {
MovingTime(0, "Moving Time"),
Distance(1, "Distance"),
MaxSpeed(2, "Max Speed"),
AverageMovingSpeed(3, "Average Speed");
MOVING_TIME(0, "Moving Time"),
DISTANCE(1, "Distance"),
MAX_SPEED(2, "Max Speed"),
AVERAGE_MOVING_SPEED(3, "Average Speed");

// Assisted by https://stackoverflow.com/questions/1067352/can-i-set-enum-start-value-in-java
private final int value;
Expand All @@ -62,13 +62,13 @@ public String getTitle() {
}

public void setCurrentLeaderboardFragment(int position) {
if (position == LeaderboardPagerAdapter.LeaderboardType.MovingTime.value)
if (position == LeaderboardPagerAdapter.LeaderboardType.MOVING_TIME.value)
currentLeaderboardFragment = movingTimeLeaderboardFragment;
else if (position == LeaderboardPagerAdapter.LeaderboardType.Distance.value)
else if (position == LeaderboardPagerAdapter.LeaderboardType.DISTANCE.value)
currentLeaderboardFragment = distanceLeaderboardFragment;
else if (position == LeaderboardPagerAdapter.LeaderboardType.MaxSpeed.value)
else if (position == LeaderboardPagerAdapter.LeaderboardType.MAX_SPEED.value)
currentLeaderboardFragment = maxSpeedLeaderboardFragment;
else if (position == LeaderboardPagerAdapter.LeaderboardType.AverageMovingSpeed.value)
else if (position == LeaderboardPagerAdapter.LeaderboardType.AVERAGE_MOVING_SPEED.value)
currentLeaderboardFragment = averageMovingSpeedLeaderboardFragment;
currentLeaderboardFragment.setDisplayedRankingList(currentLeaderboardType);
}
Expand All @@ -81,27 +81,27 @@ public int getCount() {
@Override
public Fragment getItem(int position) {
// Return the appropriate Fragment for each tab position
if (position == LeaderboardPagerAdapter.LeaderboardType.MovingTime.value)
if (position == LeaderboardPagerAdapter.LeaderboardType.MOVING_TIME.value)
return movingTimeLeaderboardFragment;
else if (position == LeaderboardPagerAdapter.LeaderboardType.Distance.value)
else if (position == LeaderboardPagerAdapter.LeaderboardType.DISTANCE.value)
return distanceLeaderboardFragment;
else if (position == LeaderboardPagerAdapter.LeaderboardType.MaxSpeed.value)
else if (position == LeaderboardPagerAdapter.LeaderboardType.MAX_SPEED.value)
return maxSpeedLeaderboardFragment;
else if (position == LeaderboardPagerAdapter.LeaderboardType.AverageMovingSpeed.value)
else if (position == LeaderboardPagerAdapter.LeaderboardType.AVERAGE_MOVING_SPEED.value)
return averageMovingSpeedLeaderboardFragment;
return null;
return currentLeaderboardFragment;
}

@Override
public CharSequence getPageTitle(int position) {
if (position == LeaderboardPagerAdapter.LeaderboardType.MovingTime.value)
return LeaderboardPagerAdapter.LeaderboardType.MovingTime.getTitle();
else if (position == LeaderboardPagerAdapter.LeaderboardType.Distance.value)
return LeaderboardPagerAdapter.LeaderboardType.Distance.getTitle();
else if (position == LeaderboardPagerAdapter.LeaderboardType.MaxSpeed.value)
return LeaderboardPagerAdapter.LeaderboardType.MaxSpeed.getTitle();
else if (position == LeaderboardPagerAdapter.LeaderboardType.AverageMovingSpeed.value)
return LeaderboardPagerAdapter.LeaderboardType.AverageMovingSpeed.getTitle();
if (position == LeaderboardPagerAdapter.LeaderboardType.MOVING_TIME.value)
return LeaderboardPagerAdapter.LeaderboardType.MOVING_TIME.getTitle();
else if (position == LeaderboardPagerAdapter.LeaderboardType.DISTANCE.value)
return LeaderboardPagerAdapter.LeaderboardType.DISTANCE.getTitle();
else if (position == LeaderboardPagerAdapter.LeaderboardType.MAX_SPEED.value)
return LeaderboardPagerAdapter.LeaderboardType.MAX_SPEED.getTitle();
else if (position == LeaderboardPagerAdapter.LeaderboardType.AVERAGE_MOVING_SPEED.value)
return LeaderboardPagerAdapter.LeaderboardType.AVERAGE_MOVING_SPEED.getTitle();
return null;
}

Expand Down

0 comments on commit 0bf809f

Please sign in to comment.