From 28a1992c6e839a783ebe8365319b216d9eb6eadc Mon Sep 17 00:00:00 2001 From: Patrick Schneider Date: Thu, 9 Jan 2025 17:53:21 +0100 Subject: [PATCH] [feat] shows how many levels are available for each game/difficulty. --- .../controller/NewLevelManager.java | 3 +++ .../ui/MainActivity.java | 20 ++++++++++++++++++- .../main/res/layout/activity_main_menu.xml | 6 ++++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java index 32d23ac1..24ffbb45 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/NewLevelManager.java @@ -77,6 +77,9 @@ private NewLevelManager(Context context, SharedPreferences settings) { public boolean isLevelLoadable(GameType type, GameDifficulty diff) { return dbHelper.getLevels(diff, type).size() > 0; } + public int getCountAvailableLevels(GameType type, GameDifficulty diff) { + return dbHelper.getLevels(diff, type).size(); + } @Deprecated public boolean isLevelLoadableOld(GameType type, GameDifficulty diff) { diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java index 30b0bf50..31ecd6f1 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java @@ -147,6 +147,12 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse public void onPageSelected(int position) { arrowLeft.setVisibility((position==0)?View.INVISIBLE:View.VISIBLE); arrowRight.setVisibility((position==mSectionsPagerAdapter.getCount()-1)?View.INVISIBLE:View.VISIBLE); + + GameType gameType = GameType.getValidGameTypes().get(mViewPager.getCurrentItem()); + int index = difficultyBar.getProgress()-1; + GameDifficulty gameDifficulty = GameDifficulty.getValidDifficultyList().get(index < 0 ? 0 : index); + ((TextView) findViewById(R.id.level_count)) + .setText(String.format(getString(R.string.levels_available), newLevelManager.getCountAvailableLevels(gameType, gameDifficulty))); } @Override @@ -171,7 +177,10 @@ public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) button.setText(R.string.new_game); if (rating >= 1) { - if (GameType.getValidGameTypes().get(mViewPager.getCurrentItem()) == GameType.Default_16x16 && rating <= 2) { + GameType gameType = GameType.getValidGameTypes().get(mViewPager.getCurrentItem()); + int index = difficultyBar.getProgress()-1; + GameDifficulty gameDifficulty = GameDifficulty.getValidDifficultyList().get(index < 0 ? 0 : index); + if (gameType == GameType.Default_16x16 && rating <= 2) { button.setEnabled(false); button.setText(R.string.game_config_unsupported); button.setBackgroundResource(R.drawable.button_inactive); @@ -180,6 +189,10 @@ public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) button.setText(R.string.new_game); button.setBackgroundResource(R.drawable.button_standalone); } + + ((TextView) findViewById(R.id.level_count)) + .setText(String.format(getString(R.string.levels_available), newLevelManager.getCountAvailableLevels(gameType, gameDifficulty))); + difficultyText.setText(getString(difficultyList.get((int) ratingBar.getRating() - 1).getStringResID())); } else { button.setEnabled(true); @@ -191,6 +204,11 @@ public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) } }); + GameType gameType = GameType.getValidGameTypes().get(mViewPager.getCurrentItem()); + GameDifficulty gameDifficulty = GameDifficulty.getValidDifficultyList().get(index < 0 ? 0 : index); + ((TextView) findViewById(R.id.level_count)) + .setText(String.format(getString(R.string.levels_available), newLevelManager.getCountAvailableLevels(gameType, gameDifficulty))); + createGameBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/res/layout/activity_main_menu.xml b/app/src/main/res/layout/activity_main_menu.xml index 39c22732..865033ee 100644 --- a/app/src/main/res/layout/activity_main_menu.xml +++ b/app/src/main/res/layout/activity_main_menu.xml @@ -100,6 +100,12 @@ android:layout_width="wrap_content" android:text="@string/difficulty_easy" android:textSize="@dimen/main_text_difficulty"/> + Verifizierung fehlgeschlagen: Dein Sudoku kann nicht gelöst werden. Zeit deaktivieren Diese Spielkombination ist momentan nicht unterstützt. + Levels verfügbar: %s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b2e1c10..1433c402 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -205,5 +205,6 @@ Only download attachments when manually requested Sudoku 16x16 This game combination is currently not supported. + Levels available: %s