diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java index 3c40446..44441ce 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/DailySudoku.java @@ -76,6 +76,19 @@ public class DailySudoku extends Level { return 0; } + public int getOrderingDateID(){ + int year = id%10000; + int month = ((id/10000) -1) % 100; + int day = id/1000000; + StringBuffer sb = new StringBuffer(); + sb.append(year); + if(month<10) sb.append(0); + sb.append(month); + if(day<10) sb.append(0); + sb.append(day); + return Integer.valueOf(sb.toString()); + } + /** * Set a new value for the timeNeeded attribute of this daily sudoku * @param timeNeeded the new value for the timeNeeded attribute diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/Level.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/Level.java index be46794..18fdbbb 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/Level.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/controller/database/model/Level.java @@ -21,7 +21,7 @@ import org.secuso.privacyfriendlysudoku.game.GameDifficulty; import org.secuso.privacyfriendlysudoku.game.GameType; public class Level { - private int id = -1; + protected int id = -1; private GameDifficulty difficulty = GameDifficulty.Unspecified; private GameType gameType = GameType.Unspecified; private int[] puzzle; diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/DailySudokuActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/DailySudokuActivity.java index e684b06..d0c28b7 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/DailySudokuActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/DailySudokuActivity.java @@ -47,6 +47,7 @@ import org.secuso.privacyfriendlysudoku.ui.view.R; import java.text.DateFormat; import java.util.Calendar; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.TimeZone; @@ -75,6 +76,8 @@ public class DailySudokuActivity extends AppCompatActivity { setSupportActionBar(toolbar); sudokuList = dbHelper.getDailySudokus(); + Collections.sort(sudokuList, (o1, o2) -> o2.getOrderingDateID() - o1.getOrderingDateID()); + TextView totalGamesTextView = findViewById(R.id.numb_of_total_games); TextView hintsTextView = findViewById(R.id.numb_of_hints); TextView totalTimeTextView = findViewById(R.id.numb_of_total_time); @@ -257,7 +260,8 @@ public class DailySudokuActivity extends AppCompatActivity { int id = sudoku.getId(); Calendar cal = Calendar.getInstance(); - cal.set(id%10000, (id/10000) % 100, id/1000000, 0, 0, 0 ); + //-1 at month because for some reason, it is added by 1 when saving the dailySudoku + cal.set(id%10000, ((id/10000) -1) % 100, id/1000000, 0, 0, 0 ); DateFormat format = DateFormat.getDateInstance();