Fixes, start with right theme

This commit is contained in:
Sylvia van Os
2019-12-02 18:03:36 +01:00
parent 4240fd55ba
commit 0de50e72a6
4 changed files with 43 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
android:required="false" />
<application
android:name=".LoyaltyCardLockerApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

View File

@@ -0,0 +1,15 @@
package protect.card_locker;
import android.app.Application;
import android.support.v7.app.AppCompatDelegate;
import protect.card_locker.preferences.Settings;
public class LoyaltyCardLockerApplication extends Application {
public void onCreate() {
super.onCreate();
Settings settings = new Settings(getApplicationContext());
AppCompatDelegate.setDefaultNightMode(settings.getTheme());
}
}

View File

@@ -14,6 +14,7 @@ import android.database.Cursor;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
@@ -34,6 +35,7 @@ import java.util.Calendar;
import java.util.Map;
import protect.card_locker.intro.IntroActivity;
import protect.card_locker.preferences.Settings;
import protect.card_locker.preferences.SettingsActivity;
public class MainActivity extends AppCompatActivity
@@ -89,6 +91,9 @@ public class MainActivity extends AppCompatActivity
MenuItem searchItem = menu.findItem(R.id.action_search);
searchItem.collapseActionView();
}
// In case the theme changed
recreate();
}
}

View File

@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.IntegerRes;
import android.support.annotation.StringRes;
import android.support.v7.app.AppCompatDelegate;
import protect.card_locker.R;
@@ -29,6 +30,11 @@ public class Settings
return context.getResources().getInteger(resId);
}
private String getString(@StringRes int keyId, String defaultValue)
{
return settings.getString(getResString(keyId), defaultValue);
}
private int getInt(@StringRes int keyId, @IntegerRes int defaultId)
{
return settings.getInt(getResString(keyId), getResInt(defaultId));
@@ -39,6 +45,22 @@ public class Settings
return settings.getBoolean(getResString(keyId), defaultValue);
}
public int getTheme()
{
String value = getString(R.string.settings_key_theme, getResString(R.string.settings_key_system_theme));
if(value.equals(getResString(R.string.settings_key_light_theme)))
{
return AppCompatDelegate.MODE_NIGHT_NO;
}
else if(value.equals(getResString(R.string.settings_key_dark_theme)))
{
return AppCompatDelegate.MODE_NIGHT_YES;
}
return AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
}
public int getCardTitleListFontSize()
{
return getInt(R.string.settings_key_card_title_list_font_size, R.integer.settings_card_title_list_font_size_sp);