Skip to content

Commit

Permalink
[feat] Adds option to deactivate timer. closes #123
Browse files Browse the repository at this point in the history
  • Loading branch information
coderPaddyS committed Jan 2, 2025
1 parent ba8e45f commit fb5f81f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BackupRestorer : IBackupRestorer {
"pref_highlight_connected",
"pref_keep_screen_on",
"pref_automatic_note_deletion",
"pref_deactivate_timer",
"pref_dark_mode_automatically_by_system" -> preferences.putBoolean(name, reader.nextBoolean())
"lastChosenDifficulty",
"pref_symbols",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public void add(GameController gc){
numberOfGames++;
// min time is only minTime of games without hints used
minTime = (gc.getUsedHints() == 0 && gc.getTime()< minTime) ? gc.getTime() : minTime;
numberOfGamesNoHints = (gc.getUsedHints() == 0) ? numberOfGamesNoHints + 1 : numberOfGamesNoHints;
timeNoHints = (gc.getUsedHints() == 0) ? timeNoHints + gc.getTime() : timeNoHints;

numberOfGamesNoHints = (gc.getUsedHints() == 0) ? numberOfGamesNoHints + 1 : numberOfGamesNoHints;
}
public void incHints(){
numberOfHintsUsed++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static String timeToString(int time) {
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

if(gameSolved || !startGame) {
gameController.pauseTimer();
Expand All @@ -121,7 +122,9 @@ protected void onPostCreate(Bundle savedInstanceState) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
gameController.startTimer();
if (!sharedPref.getBoolean("pref_deactivate_timer", false)) {
gameController.startTimer();
}
}
}, MAIN_CONTENT_FADEIN_DURATION);
}
Expand Down Expand Up @@ -349,6 +352,9 @@ public void onClick(DialogInterface dialog, int id) {

//set TimerView
timerView = (TextView)findViewById(R.id.timerView);
if (sharedPref.getBoolean("pref_deactivate_timer", false)) {
timerView.setVisibility(View.GONE);
}


//set GameName
Expand Down Expand Up @@ -417,18 +423,20 @@ public void onResume(){
mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEOUT_DURATION);
}

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
gameController.initTimer();

if(!gameSolved && startGame) {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
gameController.startTimer();
if (!sharedPref.getBoolean("pref_deactivate_timer", false)) {
gameController.startTimer();
}
}
}, MAIN_CONTENT_FADEIN_DURATION);
}

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
Symbol s;
try {
s = Symbol.valueOf(sharedPref.getString("pref_symbols", Symbol.Default.name()));
Expand Down Expand Up @@ -578,10 +586,11 @@ public void onSolved() {
editor.apply();
}

//Don't save statistics if game is custom
//Don't save statistics if game is custom or timer is deactivated
boolean isNewBestTime;
boolean saveTime = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_deactivate_timer", false);

if (!gameController.gameIsCustom()) {
if (!gameController.gameIsCustom() && !saveTime) {
//Show time hints new plus old best time
statistics.saveGameStats();
isNewBestTime = gameController.getUsedHints() == 0
Expand All @@ -605,9 +614,14 @@ public void onSolved() {

private WinDialog buildWinDialog(String usedTime, String usedHints, boolean isNewBestTime) {
Bundle dialogArguments = new Bundle();
dialogArguments.putString(WinDialog.ARG_TIME, usedTime);
boolean showTime = !PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_deactivate_timer", false);
if (showTime) {
dialogArguments.putString(WinDialog.ARG_TIME, usedTime);
}
dialogArguments.putString(WinDialog.ARG_HINT, usedHints);
dialogArguments.putBoolean(WinDialog.ARG_BEST, isNewBestTime);
if (showTime) {
dialogArguments.putBoolean(WinDialog.ARG_BEST, isNewBestTime);
}

dialog = new WinDialog();
dialog.setArguments(dialogArguments);
Expand All @@ -623,7 +637,9 @@ private void disableReset(){
public void onTick(int time) {

// display the time
timerView.setText(timeToString(time));
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_deactivate_timer", false)) {
timerView.setText(timeToString(time));
}

if(gameSolved || !startGame) return;
// save time
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<string name="help_delete_summary">Löscht das ausgewählte Feld</string>
<string name="help_delete">Löschen</string>
<string name="help_privacyInfo">Privatsphäre Information</string>
<string name="pref_deactivate_timer_summary">Zeit deaktivieren</string>
<string name="pref_timer_reset">Zeit zurücksetzen</string>
<string name="pref_timer_reset_summary">Beim zurücksetzen des Spielfeldes wird die Zeit auch zurückgesetzt.</string>
<string name="okay">Okay</string>
Expand Down Expand Up @@ -127,5 +128,6 @@
<string name="verify_custom_sudoku_process_toast">Verifiziere Level&#8230;</string>
<string name="finished_verifying_custom_sudoku_toast">Verifizierung abgeschlossen!</string>
<string name="failed_to_verify_custom_sudoku_toast">Verifizierung fehlgeschlagen: Dein Sudoku kann nicht gelöst werden.</string>
<string name="pref_deactivate_timer">Zeit deaktivieren</string>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
</array>
<string name="pref_automatic_note_deletion">Note deletion</string>
<string name="pref_automatic_note_deletion_summary">Automatically remove notes when setting values on connected cells</string>
<string name="pref_deactivate_timer">Deactivate Timer</string>
<string name="pref_deactivate_timer_summary">If selected, the time needed to complete a sudoku won\'t be measured. Games played without an active timer won\'t be recorded in the stats.</string>
<string name="pref_timer_reset">Timer Reset</string>
<string name="pref_timer_reset_summary">Also reset the timer, when resetting the game board.</string>
<string name="pref_dark_mode">Dark Theme</string>
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/xml-v29/pref_settings_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
android:summary="@string/pref_automatic_note_deletion_summary"
android:defaultValue="true"/>

<SwitchPreference android:id="@+id/pref_timer"
android:key="pref_deactivate_timer"
android:title="@string/pref_deactivate_timer"
android:summary="@string/pref_deactivate_timer_summary"
android:disableDependentsState="true"
android:defaultValue="false" />

<SwitchPreference android:id="@+id/pref_timer_reset"
android:key="pref_timer_reset"
android:title="@string/pref_timer_reset"
android:summary="@string/pref_timer_reset_summary"
android:defaultValue="true" />
android:defaultValue="true"
android:dependency="pref_deactivate_timer"/>

<SwitchPreference android:id="@+id/pref_keep_screen_on"
android:key="pref_keep_screen_on"
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/res/xml/pref_settings_general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
android:summary="@string/pref_automatic_note_deletion_summary"
android:defaultValue="true"/>

<SwitchPreference android:id="@+id/pref_timer"
android:key="pref_deactivate_timer"
android:title="@string/pref_deactivate_timer"
android:summary="@string/pref_deactivate_timer_summary"
android:disableDependentsState="true"
android:defaultValue="false" />

<SwitchPreference android:id="@+id/pref_timer_reset"
android:key="pref_timer_reset"
android:title="@string/pref_timer_reset"
android:summary="@string/pref_timer_reset_summary"
android:defaultValue="true" />
android:defaultValue="true"
android:dependency="pref_deactivate_timer"/>

<SwitchPreference android:id="@+id/pref_keep_screen_on"
android:key="pref_keep_screen_on"
Expand Down

0 comments on commit fb5f81f

Please sign in to comment.