Move the theme setup to a base activity class
This commit is contained in:
parent
3244ed3887
commit
a5f9ec4efb
5 changed files with 33 additions and 68 deletions
|
@ -23,13 +23,10 @@
|
|||
package org.shadowice.flocke.andotp;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.view.ViewStub;
|
||||
|
@ -38,7 +35,7 @@ import android.widget.TextView;
|
|||
|
||||
import de.psdev.licensesdialog.LicensesDialog;
|
||||
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
public class AboutActivity extends BaseActivity {
|
||||
private static final String GITHUB_URI = "https://github.com/flocke/andOTP";
|
||||
private static final String CHANGELOG_URI = GITHUB_URI + "/blob/master/CHANGELOG.md";
|
||||
private static final String MIT_URI = GITHUB_URI + "/blob/master/LICENSE.txt";
|
||||
|
@ -51,25 +48,13 @@ public class AboutActivity extends AppCompatActivity {
|
|||
|
||||
private static final String BUGREPORT_URI = GITHUB_URI + "/issues";
|
||||
|
||||
private void setThemeFromPrefs() {
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String theme = sharedPref.getString(getString(R.string.settings_key_theme), getString(R.string.settings_default_theme));
|
||||
|
||||
if (theme.equals("light")) {
|
||||
setTheme(R.style.AppTheme_NoActionBar);
|
||||
} else if (theme.equals("dark")) {
|
||||
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setThemeFromPrefs();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setTitle(R.string.about_activity_title);
|
||||
setContentView(R.layout.activity_container);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
|
@ -160,7 +145,6 @@ public class AboutActivity extends AppCompatActivity {
|
|||
openURI(BUGREPORT_URI);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Go back to the main activity
|
||||
|
|
|
@ -36,7 +36,6 @@ import android.preference.PreferenceManager;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
@ -59,7 +58,7 @@ import java.util.ArrayList;
|
|||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
public class BackupActivity extends AppCompatActivity {
|
||||
public class BackupActivity extends BaseActivity {
|
||||
private final static int INTENT_OPEN_DOCUMENT_PLAIN = 100;
|
||||
private final static int INTENT_SAVE_DOCUMENT_PLAIN = 101;
|
||||
private final static int INTENT_OPEN_DOCUMENT_CRYPT = 102;
|
||||
|
@ -93,25 +92,13 @@ public class BackupActivity extends AppCompatActivity {
|
|||
|
||||
private boolean reload = false;
|
||||
|
||||
private void setThemeFromPrefs() {
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String theme = sharedPref.getString(getString(R.string.settings_key_theme), getString(R.string.settings_default_theme));
|
||||
|
||||
if (theme.equals("light")) {
|
||||
setTheme(R.style.AppTheme_NoActionBar);
|
||||
} else if (theme.equals("dark")) {
|
||||
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setThemeFromPrefs();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setTitle(R.string.backup_activity_title);
|
||||
setContentView(R.layout.activity_container);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.shadowice.flocke.andotp;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
public class BaseActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String theme = sharedPref.getString(getString(R.string.settings_key_theme), getString(R.string.settings_default_theme));
|
||||
|
||||
if (theme.equals("light")) {
|
||||
setTheme(R.style.AppTheme_NoActionBar);
|
||||
} else if (theme.equals("dark")) {
|
||||
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
|
@ -35,7 +35,6 @@ import android.preference.PreferenceManager;
|
|||
import android.provider.Settings;
|
||||
import android.support.constraint.ConstraintLayout;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SearchView;
|
||||
|
@ -58,7 +57,7 @@ import com.google.zxing.integration.android.IntentResult;
|
|||
|
||||
import org.shadowice.flocke.andotp.ItemTouchHelper.SimpleItemTouchHelperCallback;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
public class MainActivity extends BaseActivity
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private EntriesCardAdapter adapter;
|
||||
|
@ -141,25 +140,9 @@ public class MainActivity extends AppCompatActivity
|
|||
.show();
|
||||
}
|
||||
|
||||
private void setThemeFromPrefs() {
|
||||
String theme = sharedPref.getString(getString(R.string.settings_key_theme), getString(R.string.settings_default_theme));
|
||||
|
||||
if (theme.equals("light")) {
|
||||
setTheme(R.style.AppTheme_NoActionBar);
|
||||
} else if (theme.equals("dark")) {
|
||||
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the main application
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
sharedPref.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
setThemeFromPrefs();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setTitle(R.string.app_name);
|
||||
|
@ -169,6 +152,10 @@ public class MainActivity extends AppCompatActivity
|
|||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
|
||||
sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
sharedPref.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
if(sharedPref.getBoolean(getString(R.string.settings_key_auth_device), false)) {
|
||||
|
|
|
@ -24,40 +24,25 @@ package org.shadowice.flocke.andotp;
|
|||
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.ViewStub;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpAppPreference;
|
||||
import org.openintents.openpgp.util.OpenPgpKeyPreference;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
public class SettingsActivity extends BaseActivity {
|
||||
SettingsFragment fragement;
|
||||
|
||||
private void setThemeFromPrefs() {
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String theme = sharedPref.getString(getString(R.string.settings_key_theme), getString(R.string.settings_default_theme));
|
||||
|
||||
if (theme.equals("light")) {
|
||||
setTheme(R.style.AppTheme_NoActionBar);
|
||||
} else if (theme.equals("dark")) {
|
||||
setTheme(R.style.AppTheme_Dark_NoActionBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setThemeFromPrefs();
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setTitle(R.string.settings_activity_title);
|
||||
setContentView(R.layout.activity_container);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.container_toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
|
|
Loading…
Reference in a new issue