Skip to content

Commit

Permalink
Improved turning on/off passcode in preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
aint committed Nov 18, 2014
1 parent b8d95a2 commit 324ce56
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@
<string name="toast_no_transactions_to_export">There are no transactions available to export</string>
<string name="header_passcode_settings">Passcode</string>
<string name="title_passcode_preferences">Passcode Preferences</string>
<string name="title_enable_passcode">Turn On/Off Passcode</string>
<string name="title_passcode_enabled">Passcode Turned On</string>
<string name="title_passcode_disabled">Passcode Turned Off</string>
<string name="title_change_passcode">Change Passcode</string>
<string name="title_about_gnucash">About GnuCash</string>
<string name="summary_about_gnucash">Gnucash is a mobile finance expense tracker application for Android.\n
Expand Down
3 changes: 1 addition & 2 deletions app/res/xml/fragment_passcode_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/title_passcode_preferences"/>
<CheckBoxPreference android:title="@string/title_enable_passcode"
android:key="@string/key_enable_passcode" />
<CheckBoxPreference android:key="@string/key_enable_passcode" />
<Preference android:key="@string/key_change_passcode"
android:title="@string/title_change_passcode"
android:dependency="@string/key_enable_passcode" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,16 @@ public void onResume() {
final Intent intent = new Intent(getActivity(), PasscodePreferenceActivity.class);

checkBoxPreference = (CheckBoxPreference) findPreference(getString(R.string.key_enable_passcode));
final String passcodeEnabled = getString(R.string.title_passcode_enabled);
final String passcodeDisabled = getString(R.string.title_passcode_disabled);
checkBoxPreference.setTitle(checkBoxPreference.isChecked() ? passcodeEnabled : passcodeDisabled);
checkBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if ((Boolean) newValue) {
startActivityForResult(intent, PASSCODE_REQUEST_CODE);
} else {
checkBoxPreference.setTitle(passcodeDisabled);
}
editor.putBoolean(UxArgument.ENABLED_PASSCODE, (Boolean) newValue);
editor.commit();
Expand All @@ -95,6 +100,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == PASSCODE_REQUEST_CODE && data!= null) {
editor.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE));
Toast.makeText(getActivity(), R.string.toast_passcode_set, Toast.LENGTH_SHORT).show();
checkBoxPreference.setTitle(getString(R.string.title_passcode_enabled));
} else {
editor.putBoolean(UxArgument.ENABLED_PASSCODE, false);
checkBoxPreference.setChecked(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ protected void onCreate(Bundle savedInstanceState) {

pref = findPreference(getString(R.string.key_enable_passcode));
pref.setOnPreferenceChangeListener(this);
}
pref.setTitle(((CheckBoxPreference) pref).isChecked() ?
getString(R.string.title_passcode_enabled) : getString(R.string.title_passcode_disabled));
}
}

@Override
Expand Down Expand Up @@ -195,6 +197,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
if ((Boolean) newValue) {
startActivityForResult(new Intent(this, PasscodePreferenceActivity.class),
PasscodePreferenceFragment.PASSCODE_REQUEST_CODE);
} else {
preference.setTitle(getString(R.string.title_passcode_disabled));
}
PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
.edit()
Expand Down Expand Up @@ -357,6 +361,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE))
.commit();
Toast.makeText(getApplicationContext(), R.string.toast_passcode_set, Toast.LENGTH_SHORT).show();
findPreference(getString(R.string.key_enable_passcode)).setTitle(getString(R.string.title_passcode_enabled));
}
break;
}
Expand Down

0 comments on commit 324ce56

Please sign in to comment.