Added multiple theme support
This commit is contained in:
parent
5ac835ce0f
commit
3acbd9a4c7
|
@ -35,6 +35,7 @@ import com.mikepenz.aboutlibraries.LibsBuilder;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import com.luca0n.joguitos.pluck.R;
|
import com.luca0n.joguitos.pluck.R;
|
||||||
import com.luca0n.joguitos.pluck.settings.SettingsActivity;
|
import com.luca0n.joguitos.pluck.settings.SettingsActivity;
|
||||||
|
import com.luca0n.joguitos.pluck.util.UiUtil;
|
||||||
|
|
||||||
@SuppressLint("Registered")
|
@SuppressLint("Registered")
|
||||||
public class BaseActivity extends AppCompatActivity {
|
public class BaseActivity extends AppCompatActivity {
|
||||||
|
@ -72,7 +73,7 @@ public class BaseActivity extends AppCompatActivity {
|
||||||
String appDescription = getResources().getString(R.string.app_description);
|
String appDescription = getResources().getString(R.string.app_description);
|
||||||
|
|
||||||
new LibsBuilder()
|
new LibsBuilder()
|
||||||
.withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
|
.withActivityStyle(UiUtil.getTheme(this).equals(getString(R.string.pref_ui_theme_entryValues_dark)) ? Libs.ActivityStyle.DARK : Libs.ActivityStyle.LIGHT)
|
||||||
.withAboutIconShown(true)
|
.withAboutIconShown(true)
|
||||||
.withAboutAppName(appName)
|
.withAboutAppName(appName)
|
||||||
.withAboutVersionShownName(true)
|
.withAboutVersionShownName(true)
|
||||||
|
|
|
@ -38,14 +38,24 @@ public class UiUtil {
|
||||||
public static void setTheme(Context context){
|
public static void setTheme(Context context){
|
||||||
SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
|
SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
|
||||||
|
|
||||||
String light = context.getString(R.string.pref_ui_theme_entryValues_light),
|
String dark = context.getString(R.string.pref_ui_theme_entryValues_dark),
|
||||||
dark = context.getString(R.string.pref_ui_theme_entryValues_dark),
|
theme = getTheme(context);
|
||||||
themeKey = context.getString(R.string.pref_ui_theme),
|
|
||||||
theme = s.getString(themeKey, light);
|
|
||||||
|
|
||||||
if (theme.equals(dark))
|
if (theme.equals(dark))
|
||||||
context.setTheme(R.style.AppTheme_Dark);
|
context.setTheme(R.style.AppTheme_Dark);
|
||||||
else
|
else
|
||||||
context.setTheme(R.style.AppTheme);
|
context.setTheme(R.style.AppTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The app theme selected by the user.
|
||||||
|
* @param context The activity context.
|
||||||
|
* @since 2021-03-17
|
||||||
|
*/
|
||||||
|
public static String getTheme(Context context){
|
||||||
|
SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
|
||||||
|
String themeKey = context.getString(R.string.pref_ui_theme),
|
||||||
|
themeLight = context.getString(R.string.pref_ui_theme_entryValues_light);
|
||||||
|
return s.getString(themeKey, themeLight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue