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
This commit is contained in:
parent
2a90d403cb
commit
94b7b82bb4
2 changed files with 32 additions and 6 deletions
|
@ -174,9 +174,18 @@ public class GameActivity extends BaseActivity implements NavigationView.OnNavig
|
|||
|
||||
List<GameInfoContainer> 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);
|
||||
|
|
|
@ -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<Database> 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) {
|
||||
|
|
Loading…
Reference in a new issue