From 94b7b82bb45aec081cd24d2ed9c07f3565bf88cf Mon Sep 17 00:00:00 2001 From: uykek Date: Wed, 27 May 2020 23:09:09 +0200 Subject: [PATCH] Only calculate the daily sudoku once a day; after the DailySudokuActivity's floating action button has been pressed for the first time a day, load the daily sudoku from the 'saves' directory --- .../ui/GameActivity.java | 15 +++++++++--- .../ui/view/DailySudokuActivity.java | 23 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java index 441e2ae..df80fc6 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/GameActivity.java @@ -174,9 +174,18 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig List loadableGames = GameStateManager.getLoadableGameList(); - if (loadLevel && loadableGames.size() > loadLevelID) { - // load level from GameStateManager - gameController.loadLevel(loadableGames.get(loadLevelID)); + if (loadLevel) { + if (loadableGames.size() > loadLevelID) { + // load level from GameStateManager + gameController.loadLevel(loadableGames.get(loadLevelID)); + } else if (loadLevelID == GameController.DAILY_SUDOKU_ID) { + for (GameInfoContainer container : loadableGames) { + if (container.getID() == loadLevelID) { + gameController.loadLevel(container); + break; + } + } + } } else { // load a new level gameController.loadNewLevel(gameType, gameDifficulty); diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java index 3cc73d9..02eed27 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/view/DailySudokuActivity.java @@ -17,6 +17,8 @@ import android.widget.ListView; import android.widget.TextView; import android.view.View; import android.widget.RatingBar; + +import org.secuso.privacyfriendlysudoku.controller.GameController; import org.secuso.privacyfriendlysudoku.controller.database.DatabaseHelper; import org.secuso.privacyfriendlysudoku.controller.database.model.DailySudoku; import androidx.appcompat.app.AppCompatActivity; @@ -25,6 +27,8 @@ import org.secuso.privacyfriendlysudoku.controller.SaveLoadStatistics; import org.secuso.privacyfriendlysudoku.game.GameDifficulty; import org.secuso.privacyfriendlysudoku.ui.GameActivity; import org.secuso.privacyfriendlysudoku.ui.StatsActivity; + +import java.util.Calendar; import java.util.List; @@ -74,13 +78,26 @@ public class DailySudokuActivity extends AppCompatActivity { int index = difficultyBar.getProgress()-1; GameDifficulty gameDifficulty = GameDifficulty.getValidDifficultyList().get(index < 0 ? 0 : index); + //send everything to game activity + Calendar currentDate = Calendar.getInstance(); + int id = currentDate.get(Calendar.DAY_OF_MONTH) * 1000000 + + (currentDate.get(Calendar.MONTH) + 1) * 10000 + currentDate.get(Calendar.YEAR); final Intent intent = new Intent(this,GameActivity.class); - intent.putExtra("gameDifficulty", gameDifficulty.name()); - intent.putExtra("isDailySudoku", true); + + if (settings.getInt("lastPlayed", 0) == id) { + intent.putExtra("loadLevel", true); + intent.putExtra("loadLevelID", GameController.DAILY_SUDOKU_ID); + } else { + SharedPreferences.Editor editor = settings.edit(); + editor.putInt("lastPlayed", id); + editor.apply(); + + intent.putExtra("gameDifficulty", gameDifficulty.name()); + intent.putExtra("isDailySudoku", true); + } startActivity(intent); - } public boolean onCreateOptionsMenu(Menu menu) {