Skip to content

Commit

Permalink
[feat] shows how many levels are available for each game/difficulty.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderPaddyS committed Jan 9, 2025
1 parent b35faf0 commit 28a1992
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@
android:layout_width="wrap_content"
android:text="@string/difficulty_easy"
android:textSize="@dimen/main_text_difficulty"/>
<TextView android:id="@+id/level_count"
android:text="Levels available:"
android:textStyle="bold"
android:textSize="14dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@
<string name="failed_to_verify_custom_sudoku_toast">Verifizierung fehlgeschlagen: Dein Sudoku kann nicht gelöst werden.</string>
<string name="pref_deactivate_timer">Zeit deaktivieren</string>
<string name="game_config_unsupported">Diese Spielkombination ist momentan nicht unterstützt.</string>
<string name="levels_available">Levels verfügbar: %s</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,6 @@
<string name="attachment_summary_off">Only download attachments when manually requested</string>
<string name="gametype_default_16x16" translatable="false">Sudoku 16x16</string>
<string name="game_config_unsupported">This game combination is currently not supported.</string>
<string name="levels_available">Levels available: %s</string>

</resources>

0 comments on commit 28a1992

Please sign in to comment.