Added initial multiple theme support

This commit is contained in:
luca0N! 2021-03-17 17:38:52 -03:00
parent a5cb9430a1
commit c7e81eb66b
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
7 changed files with 231 additions and 125 deletions

View File

@ -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);

View File

@ -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);

View File

@ -31,6 +31,7 @@ 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";
@ -48,6 +49,7 @@ public class TriviaGameResultsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
UiUtil.setTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trivia_game_results);
ButterKnife.bind(this);

View File

@ -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 <https://www.gnu.org/licenses/>.
This game is a fork of LibreTrivia, and its source code is available at
<https://github.com/tryton-vanmeer/LibreTrivia>.
Contact us at <joguitos+pluck@luca0n.com>.
*/
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);
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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 <https://www.gnu.org/licenses/>.
This game is a fork of LibreTrivia, and its source code is available at
<https://github.com/tryton-vanmeer/LibreTrivia>.
Contact us at <joguitos+pluck@luca0n.com>.
-->
<resources>
<string-array name="pref_ui_theme_entryValues">
<item>pref_ui_theme_entryValues_light</item>
<item>pref_ui_theme_entryValues_dark</item>
</string-array>
</resources>

View File

@ -116,4 +116,12 @@ Contact us at <joguitos+pluck@luca0n.com>.
<string name="pref_network_tor_summary">Retrieves trivia data via the Tor network. Requires Orbot (recommended) or a Tor daemon with a SOCKS5 proxy listening on port 9050.</string>
<string name="pref_network_server_title">Server Address</string>
<string name="pref_network_server_summary">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.</string>
<string name="pref_category_ui_title">Interface</string>
<string name="pref_ui_theme_title">Theme</string>
<string name="pref_ui_theme_summary">Defines the game theme.</string>
<string-array name="pref_ui_theme_entries">
<item>Light</item>
<item>Dark</item>
</string-array>
</resources>

View File

@ -48,4 +48,14 @@ Contact us at <joguitos+pluck@luca0n.com>.
android:title="@string/pref_network_tor_title"
android:summary="@string/pref_network_tor_summary" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_category_ui_title">
<ListPreference
android:defaultValue="@string/pref_ui_theme_default"
android:key="@string/pref_ui_theme"
android:title="@string/pref_ui_theme_title"
android:summary="@string/pref_ui_theme_summary"
android:entries="@array/pref_ui_theme_entries"
android:entryValues="@array/pref_ui_theme_entryValues" />
</PreferenceCategory>
</PreferenceScreen>