From ac7ab3306cb7a16a96494425a520a7ea9cd39d7c Mon Sep 17 00:00:00 2001 From: Palmarino DiMarco Date: Sun, 28 Apr 2024 05:51:04 -0400 Subject: [PATCH 1/2] GitIgnore update --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 83f20f47a..57fe92fe3 100644 --- a/.gitignore +++ b/.gitignore @@ -83,4 +83,5 @@ Appfile releasePlayStore/* Gemfile.lock -.DS_Store \ No newline at end of file +.DS_Store +/.idea/sonarlint From 5734139a75925766bdcb7325d57f5e4b33e43a9f Mon Sep 17 00:00:00 2001 From: Palmarino DiMarco Date: Sun, 28 Apr 2024 05:58:08 -0400 Subject: [PATCH 2/2] Implemented a few fixes based on what I learned from SonarQube (and removed a useless import). --- .../ui/leaderboard/LeaderboardActivity.java | 11 ++++- .../leaderboard/LeaderboardPagerAdapter.java | 42 +++++++++---------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardActivity.java b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardActivity.java index 359ed8150..7a212c61c 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardActivity.java +++ b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardActivity.java @@ -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; @@ -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 @@ -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. + */ } }); diff --git a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardPagerAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardPagerAdapter.java index a7c7abcbe..4c3351e1b 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardPagerAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/leaderboard/LeaderboardPagerAdapter.java @@ -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; @@ -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); } @@ -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; }