Skip to content

Commit

Permalink
Fixes for ancient device compatibility and button focus
Browse files Browse the repository at this point in the history
  • Loading branch information
dozingcat committed Oct 10, 2022
1 parent efe5e30 commit 458d0de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,9 @@ public void unpauseGame() {
void updateButtons() {
GameState state = field.getGameState();
if (state.isPaused()) {
if (highScorePanel.getVisibility() == View.VISIBLE){
if (highScorePanel.getVisibility() == View.VISIBLE) {
buttonPanel.setVisibility(View.GONE);
hideHighScoreButton.requestFocus();
}
else {
buttonPanel.setVisibility(View.VISIBLE);
Expand All @@ -327,8 +328,9 @@ void updateButtons() {
buttonPanel.setVisibility(View.GONE);
highScorePanel.setVisibility(View.GONE);
}
else if (highScorePanel.getVisibility() == View.VISIBLE){
else if (highScorePanel.getVisibility() == View.VISIBLE) {
buttonPanel.setVisibility(View.GONE);
hideHighScoreButton.requestFocus();
}
else {
buttonPanel.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -610,12 +612,14 @@ public void showHighScore(View view) {
this.fillHighScoreAdapter();
this.buttonPanel.setVisibility(View.GONE);
this.highScorePanel.setVisibility(View.VISIBLE);
updateButtons();
}

public void hideHighScore(View view) {
this.buttonPanel.setVisibility(View.VISIBLE);
this.highScorePanel.setVisibility(View.GONE);
this.highScoreListLayout.removeAllViews();
updateButtons();
}

private void fillHighScoreAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ public class FieldLayoutReader {

public static int getNumberOfLevels(Context context) {
try {
return (int) Arrays.stream(context.getAssets().list("tables"))
.filter(name -> name.matches("^table\\d+\\.json"))
.count();
// This would be cleaner with Arrays.stream/filter/count, but that's not supported
// by Android's desugaring library so it breaks on older devices.
List<String> tableFiles = Arrays.asList(context.getAssets().list("tables"));
int count = 0;
while (tableFiles.contains("table" + (count + 1) + ".json")) {
count++;
}
return count;
}
catch (IOException ex) {
throw new RuntimeException(ex);
Expand Down

0 comments on commit 458d0de

Please sign in to comment.