Convert dark mode preference to select theme preference

This commit is contained in:
Michael Schättgen 2019-03-28 00:56:29 +01:00
parent 17204cc026
commit a7ac1adb80
2 changed files with 34 additions and 0 deletions

View file

@ -9,11 +9,16 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference; import androidx.preference.Preference;
import android.view.Gravity;
import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Toast; import android.widget.Toast;
import com.beemdevelopment.aegis.Preferences; import com.beemdevelopment.aegis.Preferences;
import com.beemdevelopment.aegis.Theme;
import com.beemdevelopment.aegis.db.DatabaseFileCredentials; import com.beemdevelopment.aegis.db.DatabaseFileCredentials;
import com.beemdevelopment.aegis.helpers.FingerprintHelper; import com.beemdevelopment.aegis.helpers.FingerprintHelper;
import com.beemdevelopment.aegis.helpers.PermissionHelper; import com.beemdevelopment.aegis.helpers.PermissionHelper;
@ -87,6 +92,34 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
setResult(new Intent()); setResult(new Intent());
Preference darkModePreference = findPreference("pref_dark_mode"); Preference darkModePreference = findPreference("pref_dark_mode");
darkModePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String[] themeNames = {"Light theme", "Dark theme", "Amoled theme"};
int checkedTheme = app.getPreferences().getCurrentTheme();
Dialogs.showSecureDialog(new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.choose_theme))
.setSingleChoiceItems(themeNames, checkedTheme, (dialog, which) -> {
int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
Theme selectedTheme = Theme.fromInteger(i);
app.getPreferences().setCurrentTheme(selectedTheme);
if (selectedTheme == Theme.AMOLED)
{
Toast.makeText(app, "Due to a bug in a third party library, the amoled theme is not visible here.", Toast.LENGTH_LONG).show();
}
_result.putExtra("needsRecreate", true);
getActivity().recreate();
})
.setPositiveButton(android.R.string.ok, null)
.create());
return true;
}
});
darkModePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { darkModePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {

View file

@ -120,6 +120,7 @@
<string name="encrypting_error">An error occurred while enabling encryption</string> <string name="encrypting_error">An error occurred while enabling encryption</string>
<string name="permission_denied">Permission denied</string> <string name="permission_denied">Permission denied</string>
<string name="choose_application">Select the application you\'d like to import a database from</string> <string name="choose_application">Select the application you\'d like to import a database from</string>
<string name="choose_theme">Select your desired theme</string>
<string name="parsing_file_error">An error occurred while trying to parse the file</string> <string name="parsing_file_error">An error occurred while trying to parse the file</string>
<string name="file_not_found">Error: File not found</string> <string name="file_not_found">Error: File not found</string>
<string name="reading_file_error">An error occurred while trying to read the file</string> <string name="reading_file_error">An error occurred while trying to read the file</string>