diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/activities/MainActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/activities/MainActivity.java index 3cb9f2e..2d9f584 100644 --- a/app/src/main/java/com/luca0n/joguitos/pluck/activities/MainActivity.java +++ b/app/src/main/java/com/luca0n/joguitos/pluck/activities/MainActivity.java @@ -43,6 +43,7 @@ import com.luca0n.joguitos.pluck.trivia.TriviaCategory; import com.luca0n.joguitos.pluck.trivia.TriviaDifficulty; import com.luca0n.joguitos.pluck.trivia.TriviaQuery; import com.luca0n.joguitos.pluck.trivia.TriviaFilters; +import com.luca0n.joguitos.pluck.util.UiUtil; public class MainActivity extends BaseActivity { @@ -61,6 +62,7 @@ public class MainActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { + UiUtil.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameActivity.java index 2007448..2bedad8 100644 --- a/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameActivity.java +++ b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameActivity.java @@ -66,6 +66,7 @@ import com.luca0n.joguitos.pluck.trivia.TriviaSource; import com.luca0n.joguitos.pluck.trivia.TriviaFilters; import com.luca0n.joguitos.pluck.util.ApiUtil; import com.luca0n.joguitos.pluck.util.SoundUtil; +import com.luca0n.joguitos.pluck.util.UiUtil; public class TriviaGameActivity extends BaseActivity implements IDownloadTriviaQuestionReceiver { @@ -92,6 +93,7 @@ public class TriviaGameActivity extends BaseActivity @Override protected void onCreate(Bundle savedInstanceState) { + UiUtil.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.activity_trivia_game); ButterKnife.bind(this); diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameResultsActivity.java b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameResultsActivity.java index bdfc09c..5c98e70 100644 --- a/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameResultsActivity.java +++ b/app/src/main/java/com/luca0n/joguitos/pluck/activities/TriviaGameResultsActivity.java @@ -31,55 +31,57 @@ import butterknife.BindView; import butterknife.ButterKnife; import com.luca0n.joguitos.pluck.R; import com.luca0n.joguitos.pluck.trivia.TriviaGame; +import com.luca0n.joguitos.pluck.util.UiUtil; public class TriviaGameResultsActivity extends BaseActivity { - static final String EXTRA_TRIVIA_GAME = "extra_trivia_game"; + static final String EXTRA_TRIVIA_GAME = "extra_trivia_game"; - @BindView(R.id.text_results_correct) - TextView textResultsCorrect; - @BindView(R.id.text_results_wrong) - TextView textResultsWrong; - @BindView(R.id.text_results_total) - TextView textResultsTotal; - @BindView(R.id.text_results_time_elapsed) - TextView textResultsTimeElapsed; - @BindView(R.id.button_return_to_menu) - Button buttonReturnToMenu; + @BindView(R.id.text_results_correct) + TextView textResultsCorrect; + @BindView(R.id.text_results_wrong) + TextView textResultsWrong; + @BindView(R.id.text_results_total) + TextView textResultsTotal; + @BindView(R.id.text_results_time_elapsed) + TextView textResultsTimeElapsed; + @BindView(R.id.button_return_to_menu) + Button buttonReturnToMenu; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_trivia_game_results); - ButterKnife.bind(this); + @Override + protected void onCreate(Bundle savedInstanceState) { + UiUtil.setTheme(this); + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_trivia_game_results); + ButterKnife.bind(this); - Bundle bundle = getIntent().getExtras(); - TriviaGame game = (TriviaGame) bundle.get(EXTRA_TRIVIA_GAME); + Bundle bundle = getIntent().getExtras(); + TriviaGame game = (TriviaGame) bundle.get(EXTRA_TRIVIA_GAME); - int correctTotal = 0; + int correctTotal = 0; - for (boolean result : game.getResults()) { - if (result) { - correctTotal++; - } - } + for (boolean result : game.getResults()) { + if (result) { + correctTotal++; + } + } - // Calculate the difference between startEpoch and endEpoch - float timeDifference = (game.getEndEpoch() - game.getStartEpoch())/1000F; + // Calculate the difference between startEpoch and endEpoch + float timeDifference = (game.getEndEpoch() - game.getStartEpoch())/1000F; - textResultsCorrect.setText(String.valueOf(correctTotal)); - textResultsWrong.setText(String.valueOf(game.getQuestionsCount() - correctTotal)); - textResultsTotal.setText(String.valueOf(game.getQuestionsCount())); - if (timeDifference < 60000L) - // Use the "n seconds" string since the time difference was less than 60 seconds. - textResultsTimeElapsed.setText( - String.format(getString(R.string.ui_results_time_elapsed_format_seconds), timeDifference) - ); - else - // Use the "n minutes" string since the time difference was equal to or more than 60 seconds. - textResultsTimeElapsed.setText( - String.format(getString(R.string.ui_results_time_elapsed_format_minutes), timeDifference / 60F) - ); + textResultsCorrect.setText(String.valueOf(correctTotal)); + textResultsWrong.setText(String.valueOf(game.getQuestionsCount() - correctTotal)); + textResultsTotal.setText(String.valueOf(game.getQuestionsCount())); + if (timeDifference < 60000L) + // Use the "n seconds" string since the time difference was less than 60 seconds. + textResultsTimeElapsed.setText( + String.format(getString(R.string.ui_results_time_elapsed_format_seconds), timeDifference) + ); + else + // Use the "n minutes" string since the time difference was equal to or more than 60 seconds. + textResultsTimeElapsed.setText( + String.format(getString(R.string.ui_results_time_elapsed_format_minutes), timeDifference / 60F) + ); - buttonReturnToMenu.setOnClickListener(v -> finish()); - } + buttonReturnToMenu.setOnClickListener(v -> finish()); + } } diff --git a/app/src/main/java/com/luca0n/joguitos/pluck/util/UiUtil.java b/app/src/main/java/com/luca0n/joguitos/pluck/util/UiUtil.java new file mode 100644 index 0000000..7bca056 --- /dev/null +++ b/app/src/main/java/com/luca0n/joguitos/pluck/util/UiUtil.java @@ -0,0 +1,52 @@ +/* +Pluck: an open source trivia game for Android + +Copyright (C) 2021 Joguitos do luca0N! + +This program 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 (at your option) any later +version. + +This program 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 +this program. If not, see . + +This game is a fork of LibreTrivia, and its source code is available at +. + +Contact us at . +*/ + +package com.luca0n.joguitos.pluck.util; + +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import com.luca0n.joguitos.pluck.R; + +public class UiUtil { + /** + * Applies the theme selected by the user to the context. + * @param context The activity context. + * @since 2021-03-17 + */ + public static void setTheme(Context context){ + SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); + + + String light = context.getString(R.string.pref_ui_theme_entryValues_light), + dark = context.getString(R.string.pref_ui_theme_entryValues_dark), + themeKey = context.getString(R.string.pref_ui_theme), + theme = s.getString(themeKey, light); + + if (theme.equals(dark)) + context.setTheme(R.style.AppTheme_Dark); + else + context.setTheme(R.style.AppTheme); + } +} diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..12972ab --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,30 @@ + + + + + + pref_ui_theme_entryValues_light + pref_ui_theme_entryValues_dark + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2fab1c0..91cacb0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,97 +23,105 @@ Contact us at . --> - Pluck - An open source trivia game. + Pluck + An open source trivia game. - - General Knowledge - Entertainment: Books - Entertainment: Film - Entertainment: Music - Entertainment: Musicals & Theatres - Entertainment: Television - Entertainment: Video Games - Entertainment: Board Games - Entertainment: Japanese Anime & Manga - Entertainment: Cartoons & Animation - Entertainment: Comics - Science & Nature - Science: Computers - Science: Mathematics - Science: Gadgets - Mythology - Sports - Geography - History - Politics - Art - Celebrities - Animals - Vehicles + + General Knowledge + Entertainment: Books + Entertainment: Film + Entertainment: Music + Entertainment: Musicals & Theatres + Entertainment: Television + Entertainment: Video Games + Entertainment: Board Games + Entertainment: Japanese Anime & Manga + Entertainment: Cartoons & Animation + Entertainment: Comics + Science & Nature + Science: Computers + Science: Mathematics + Science: Gadgets + Mythology + Sports + Geography + History + Politics + Art + Celebrities + Animals + Vehicles - - Easy - Medium - Hard + + Easy + Medium + Hard - - Multiple Choice - True / False + + Multiple Choice + True / False - - Server - File + + Server + File - - Settings - About - Play - Start Game - Any - All - True - False - Correct - Wrong - Questions - Category - Difficulty - %1$d⁄%2$d - Quit Game - Are you sure you want to quit this game? - Correct Answers - Wrong Answers - Total Questions - Time Elapsed - %.1f seconds - %.1f minutes - Return To Menu - Source - This value specifies where the game should retrieve trivia data. By default, the game gathers trivia data from a server, but you can load trivia files with the "File" source option. - Notice: when using a server as the game source, this game connects to Open Trivia Database by default to gather trivia questions. Open Trivia Database is a collection of user-contributed questions that are licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC-BY-SA 4.0) license.\n\nYou can select a custom server in the game settings.\n\nIf you want to open a trivia file instead of getting trivia questions from a server, select "File" as the trivia game source above. + + Settings + About + Play + Start Game + Any + All + True + False + Correct + Wrong + Questions + Category + Difficulty + %1$d⁄%2$d + Quit Game + Are you sure you want to quit this game? + Correct Answers + Wrong Answers + Total Questions + Time Elapsed + %.1f seconds + %.1f minutes + Return To Menu + Source + This value specifies where the game should retrieve trivia data. By default, the game gathers trivia data from a server, but you can load trivia files with the "File" source option. + Notice: when using a server as the game source, this game connects to Open Trivia Database by default to gather trivia questions. Open Trivia Database is a collection of user-contributed questions that are licensed under the Creative Commons Attribution-ShareAlike 4.0 International (CC-BY-SA 4.0) license.\n\nYou can select a custom server in the game settings.\n\nIf you want to open a trivia file instead of getting trivia questions from a server, select "File" as the trivia game source above. - - Error - Network error!\n\nCould not connect to a network. Check if your custom server address is correct. If Tor is enabled in the game settings, check if Orbot is running and then try again. - No trivia results!\n\nWas not able to find trivia questions that satisfied all options. - Server response error!\n\nCould not parse the server response. The server response may be in a unsupported version. If you are using a custom server, make sure the server address points to a valid address and then try again. - An unknown error occurred! - Trivia files are not supported in this version of Android. - Invalid trivia file!\n\nTrivia files should be in a plain text JSON format. - An unknown error occurred while attempting to read the opened file. - The selected question amount is only available for the "File" trivia game source. + + Error + Network error!\n\nCould not connect to a network. Check if your custom server address is correct. If Tor is enabled in the game settings, check if Orbot is running and then try again. + No trivia results!\n\nWas not able to find trivia questions that satisfied all options. + Server response error!\n\nCould not parse the server response. The server response may be in a unsupported version. If you are using a custom server, make sure the server address points to a valid address and then try again. + An unknown error occurred! + Trivia files are not supported in this version of Android. + Invalid trivia file!\n\nTrivia files should be in a plain text JSON format. + An unknown error occurred while attempting to read the opened file. + The selected question amount is only available for the "File" trivia game source. - Settings + Settings - - Sound - Answer Sound Effect - Toggles game sound effects. + + Sound + Answer Sound Effect + Toggles game sound effects. - Network - Connect Using Tor - Retrieves trivia data via the Tor network. Requires Orbot (recommended) or a Tor daemon with a SOCKS5 proxy listening on port 9050. - Server Address - Specifies the server location used by the game to fetch questions when using a server as the trivia source. Leave this setting empty to use the default server. + Network + Connect Using Tor + Retrieves trivia data via the Tor network. Requires Orbot (recommended) or a Tor daemon with a SOCKS5 proxy listening on port 9050. + Server Address + Specifies the server location used by the game to fetch questions when using a server as the trivia source. Leave this setting empty to use the default server. + + Interface + Theme + Defines the game theme. + + Light + Dark + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 4c35560..242f038 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -48,4 +48,14 @@ Contact us at . android:title="@string/pref_network_tor_title" android:summary="@string/pref_network_tor_summary" /> + + +