Skip to content

Commit 324ce56

Browse files
committed
Improved turning on/off passcode in preferences
1 parent b8d95a2 commit 324ce56

4 files changed

Lines changed: 15 additions & 4 deletions

File tree

app/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@
278278
<string name="toast_no_transactions_to_export">There are no transactions available to export</string>
279279
<string name="header_passcode_settings">Passcode</string>
280280
<string name="title_passcode_preferences">Passcode Preferences</string>
281-
<string name="title_enable_passcode">Turn On/Off Passcode</string>
281+
<string name="title_passcode_enabled">Passcode Turned On</string>
282+
<string name="title_passcode_disabled">Passcode Turned Off</string>
282283
<string name="title_change_passcode">Change Passcode</string>
283284
<string name="title_about_gnucash">About GnuCash</string>
284285
<string name="summary_about_gnucash">Gnucash is a mobile finance expense tracker application for Android.\n

app/res/xml/fragment_passcode_preferences.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
1919
<PreferenceCategory android:title="@string/title_passcode_preferences"/>
20-
<CheckBoxPreference android:title="@string/title_enable_passcode"
21-
android:key="@string/key_enable_passcode" />
20+
<CheckBoxPreference android:key="@string/key_enable_passcode" />
2221
<Preference android:key="@string/key_change_passcode"
2322
android:title="@string/title_change_passcode"
2423
android:dependency="@string/key_enable_passcode" />

app/src/org/gnucash/android/ui/settings/PasscodePreferenceFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ public void onResume() {
6767
final Intent intent = new Intent(getActivity(), PasscodePreferenceActivity.class);
6868

6969
checkBoxPreference = (CheckBoxPreference) findPreference(getString(R.string.key_enable_passcode));
70+
final String passcodeEnabled = getString(R.string.title_passcode_enabled);
71+
final String passcodeDisabled = getString(R.string.title_passcode_disabled);
72+
checkBoxPreference.setTitle(checkBoxPreference.isChecked() ? passcodeEnabled : passcodeDisabled);
7073
checkBoxPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
7174
@Override
7275
public boolean onPreferenceChange(Preference preference, Object newValue) {
7376
if ((Boolean) newValue) {
7477
startActivityForResult(intent, PASSCODE_REQUEST_CODE);
78+
} else {
79+
checkBoxPreference.setTitle(passcodeDisabled);
7580
}
7681
editor.putBoolean(UxArgument.ENABLED_PASSCODE, (Boolean) newValue);
7782
editor.commit();
@@ -95,6 +100,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
95100
if (resultCode == Activity.RESULT_OK && requestCode == PASSCODE_REQUEST_CODE && data!= null) {
96101
editor.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE));
97102
Toast.makeText(getActivity(), R.string.toast_passcode_set, Toast.LENGTH_SHORT).show();
103+
checkBoxPreference.setTitle(getString(R.string.title_passcode_enabled));
98104
} else {
99105
editor.putBoolean(UxArgument.ENABLED_PASSCODE, false);
100106
checkBoxPreference.setChecked(false);

app/src/org/gnucash/android/ui/settings/SettingsActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ protected void onCreate(Bundle savedInstanceState) {
149149

150150
pref = findPreference(getString(R.string.key_enable_passcode));
151151
pref.setOnPreferenceChangeListener(this);
152-
}
152+
pref.setTitle(((CheckBoxPreference) pref).isChecked() ?
153+
getString(R.string.title_passcode_enabled) : getString(R.string.title_passcode_disabled));
154+
}
153155
}
154156

155157
@Override
@@ -195,6 +197,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
195197
if ((Boolean) newValue) {
196198
startActivityForResult(new Intent(this, PasscodePreferenceActivity.class),
197199
PasscodePreferenceFragment.PASSCODE_REQUEST_CODE);
200+
} else {
201+
preference.setTitle(getString(R.string.title_passcode_disabled));
198202
}
199203
PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
200204
.edit()
@@ -357,6 +361,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
357361
.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE))
358362
.commit();
359363
Toast.makeText(getApplicationContext(), R.string.toast_passcode_set, Toast.LENGTH_SHORT).show();
364+
findPreference(getString(R.string.key_enable_passcode)).setTitle(getString(R.string.title_passcode_enabled));
360365
}
361366
break;
362367
}

0 commit comments

Comments
 (0)