Skip to content

Commit

Permalink
Merge pull request #57 from SecUSo/Sudoku-v3.0
Browse files Browse the repository at this point in the history
Sudoku v3.0
- Added Darktheme
- Added Custom Sudokus
- Added Daily Sudoku
- Added Sudoku Sharing
- Several Bugfixes
Fixes #45, Fixes #24
  • Loading branch information
Kamuno authored Oct 5, 2020
2 parents 3bfffc8 + c3651b3 commit 70a0a80
Show file tree
Hide file tree
Showing 188 changed files with 6,219 additions and 769 deletions.
17 changes: 12 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "org.secuso.privacyfriendlysudoku"
minSdkVersion 16
targetSdkVersion 29
versionCode 8
versionName "2.2.1"
versionCode 9
versionName "3.0.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
Expand All @@ -25,16 +25,23 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dataBinding {
enabled = true
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.12'
implementation 'androidx.core:core:1.2.0'
implementation 'androidx.core:core:1.3.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'

}
42 changes: 33 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,66 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.secuso.privacyfriendlysudoku.ui.view">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name="org.secuso.privacyfriendlysudoku.SudokuApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="org.secuso.privacyfriendlysudoku.SudokuApp">
android:theme="@style/AppTheme">
<activity
android:name="org.secuso.privacyfriendlysudoku.ui.SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.secuso.privacyfriendlysudoku.ui.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="org.secuso.privacyfriendlysudoku.ui.TutorialActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="org.secuso.privacyfriendlysudoku.ui.DailySudokuActivity"
android:label="@string/Sudoku"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="org.secuso.privacyfriendlysudoku.ui.CreateSudokuActivity"
android:label="@string/Sudoku"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name="org.secuso.privacyfriendlysudoku.ui.SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName="org.secuso.privacyfriendlysudoku.ui.MainActivity" />
<activity
android:name="org.secuso.privacyfriendlysudoku.ui.GameActivity"
android:label="@string/title_activity_game_view"
android:theme="@style/AppTheme.NoActionBar" />
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sudoku" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="sudoku.secuso.org"
android:scheme="http" />
<data
android:host="sudoku.secuso.org"
android:scheme="https" />
</intent-filter>
</activity>
<activity android:name="org.secuso.privacyfriendlysudoku.ui.AboutActivity" />
<activity android:name="org.secuso.privacyfriendlysudoku.ui.LoadGameActivity" />
<activity
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/org/secuso/privacyfriendlysudoku/SudokuApp.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
This file is part of Privacy Friendly Sudoku.
Privacy Friendly Sudoku is free software:
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or any later version.
Privacy Friendly Sudoku is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Privacy Friendly Sudoku. If not, see <http://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlysudoku;

import android.app.Application;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
This file is part of Privacy Friendly Sudoku.
Privacy Friendly Sudoku is free software:
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or any later version.
Privacy Friendly Sudoku is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Privacy Friendly Sudoku. If not, see <http://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlysudoku.controller;

import android.content.Context;
Expand All @@ -6,7 +22,10 @@
import android.os.Parcel;
import android.os.Parcelable;

import org.secuso.privacyfriendlysudoku.controller.database.DatabaseHelper;
import org.secuso.privacyfriendlysudoku.controller.database.model.DailySudoku;
import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer;
import org.secuso.privacyfriendlysudoku.controller.qqwing.QQWing;
import org.secuso.privacyfriendlysudoku.game.CellConflict;
import org.secuso.privacyfriendlysudoku.game.CellConflictList;
import org.secuso.privacyfriendlysudoku.game.GameBoard;
Expand All @@ -19,7 +38,10 @@
import org.secuso.privacyfriendlysudoku.game.listener.IHintListener;
import org.secuso.privacyfriendlysudoku.game.listener.IModelChangedListener;
import org.secuso.privacyfriendlysudoku.game.listener.ITimerListener;
import org.secuso.privacyfriendlysudoku.ui.GameActivity;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Timer;
Expand All @@ -32,6 +54,7 @@
public class GameController implements IModelChangedListener, Parcelable {

// General
public static final int DAILY_SUDOKU_ID = Integer.MAX_VALUE - 1;
private SharedPreferences settings;

// View
Expand All @@ -57,6 +80,7 @@ public class GameController implements IModelChangedListener, Parcelable {
private GameType gameType;
private GameDifficulty difficulty;
private CellConflictList errorList = new CellConflictList();
private boolean gameIsCustom;

// Undo Redo
private UndoRedoManager undoRedoManager;
Expand Down Expand Up @@ -84,6 +108,7 @@ public GameController(SharedPreferences pref, Context context) {
public GameController(GameType type, SharedPreferences pref, Context context) {
this.context = context;
this.gameBoard = new GameBoard(type);
this.gameIsCustom = false;

setGameType(type);
setSettings(pref);
Expand All @@ -95,6 +120,8 @@ public int getGameID() {
return gameID;
}

public boolean gameIsCustom() { return gameIsCustom; }

public void loadNewLevel(GameType type, GameDifficulty difficulty) {
NewLevelManager newLevelManager = NewLevelManager.getInstance(context, settings);

Expand All @@ -105,6 +132,23 @@ public void loadNewLevel(GameType type, GameDifficulty difficulty) {
newLevelManager.checkAndRestock();
}

public void loadNewDailySudokuLevel() {
NewLevelManager newLevelManager = NewLevelManager.getInstance(context, settings);

// generate the daily sudoku
int[] level = newLevelManager.loadDailySudoku();

// calculate the difficulty of the daily sudoku
QQWing difficultyCheck = new QQWing(GameType.Default_9x9, GameDifficulty.Unspecified);
difficultyCheck.setRecordHistory(true);
difficultyCheck.setPuzzle(level);
difficultyCheck.solve();

loadLevel(new GameInfoContainer(DAILY_SUDOKU_ID, difficultyCheck.getDifficulty(),
GameType.Default_9x9, level, null, null));

}

public int getTime() {
return time;
}
Expand All @@ -117,6 +161,7 @@ public void loadLevel(GameInfoContainer gic) {
this.difficulty = gic.getDifficulty();
this.time = gic.getTimePlayed();
this.usedHints = gic.getHintsUsed();
this.gameIsCustom = gic.isCustom();

setGameType(gic.getGameType());
this.gameBoard = new GameBoard(gic.getGameType());
Expand Down Expand Up @@ -305,7 +350,7 @@ public void saveGame(Context context) {

SharedPreferences.Editor editor = settings.edit();
// is anyone ever gonna play so many levels? :)
if(gameID == Integer.MAX_VALUE-1) {
if(gameID == DAILY_SUDOKU_ID - 1) {
editor.putInt("lastGameID", 1);
} else {
editor.putInt("lastGameID", gameID);
Expand All @@ -318,6 +363,31 @@ public void saveGame(Context context) {
fm.saveGameState(this);
}

/**
* Save progress on the current daily sudoku
* @param context the context in which this method is called
*/
public void saveDailySudoku(Context context) {
int amountOfCells = size * size;
int[] encodedBoard = new int[amountOfCells];

for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
encodedBoard[i * size + j] = gameBoard.getCell(i, j).getValue();
}
}

// turn the current date into an id
Calendar currentDate = Calendar.getInstance();
int id = currentDate.get(Calendar.DAY_OF_MONTH) * 1000000
+ (currentDate.get(Calendar.MONTH) + 1) * 10000 + currentDate.get(Calendar.YEAR);

// save the sudoku to the database using the previously calculated id
DatabaseHelper db = new DatabaseHelper(context);
DailySudoku dailySudoku = new DailySudoku(id, difficulty, gameType, encodedBoard, usedHints, GameActivity.timeToString(time));
db.addDailySudoku(dailySudoku);
}

public void deleteGame(Context context) {
if(gameID == 0) {
throw new IllegalArgumentException("GameID may not be 0.");
Expand Down Expand Up @@ -414,6 +484,7 @@ public String getFieldAsString() {
return gameBoard.toString();
}

public String getCodeOfField() { return gameBoard.transformToCode(); }



Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
This file is part of Privacy Friendly Sudoku.
Privacy Friendly Sudoku is free software:
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or any later version.
Privacy Friendly Sudoku is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Privacy Friendly Sudoku. If not, see <http://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlysudoku.controller;

import android.content.Context;
Expand All @@ -20,6 +36,7 @@ public class GameStateManager {

Context context;
private SharedPreferences settings;
private boolean includesDaily;

private static String FILE_EXTENSION = ".txt";
private static String SAVE_PREFIX = "save_";
Expand Down Expand Up @@ -87,6 +104,15 @@ public List<GameInfoContainer> loadGameStateInfo() {
gic.parseSetValues(values[i++]);
gic.parseNotes(values[i++]);
gic.parseHintsUsed(values[i++]);

if (values.length > i) {
gic.setCustom(true);
}

if (gic.getID() == GameController.DAILY_SUDOKU_ID) {
includesDaily = true;
}

} catch(IllegalArgumentException e) {
file.delete();
continue;
Expand All @@ -108,7 +134,7 @@ public List<GameInfoContainer> loadGameStateInfo() {
LinkedList<GameInfoContainer> removeList = new LinkedList<>();

for(int i = 0; i < list.size(); i++) {
if(i >= MAX_NUM_OF_SAVED_GAMES) {
if((i >= MAX_NUM_OF_SAVED_GAMES && !includesDaily) || i > MAX_NUM_OF_SAVED_GAMES) {
deleteGameStateFile(list.get(i));
removeList.add(list.get(i));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
This file is part of Privacy Friendly Sudoku.
Privacy Friendly Sudoku is free software:
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or any later version.
Privacy Friendly Sudoku is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Privacy Friendly Sudoku. If not, see <http://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlysudoku.controller;

import android.app.IntentService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
This file is part of Privacy Friendly Sudoku.
Privacy Friendly Sudoku is free software:
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or any later version.
Privacy Friendly Sudoku is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Privacy Friendly Sudoku. If not, see <http://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlysudoku.controller;

/**
Expand Down
Loading

0 comments on commit 70a0a80

Please sign in to comment.