Skip to content

Commit

Permalink
codinguser#876 - Add preference key_display_negative_signum_in_splits
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanGarf committed Mar 7, 2020
1 parent 6821ba7 commit bc27e47
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public int getTitleRes() {

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

final Intent intent = getIntent();
Expand Down Expand Up @@ -333,18 +334,29 @@ public void setCurrentTab(){
* <p>Also handles displaying the What's New dialog</p>
*/
private void init() {
PreferenceManager.setDefaultValues(this, BooksDbAdapter.getInstance().getActiveBookUID(),
Context.MODE_PRIVATE, R.xml.fragment_transaction_preferences, true);

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run), true);
PreferenceManager.setDefaultValues(this,
BooksDbAdapter.getInstance()
.getActiveBookUID(),
Context.MODE_PRIVATE,
R.xml.fragment_transaction_preferences,
true);

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean firstRun = prefs.getBoolean(getString(R.string.key_first_run),
true);

if (firstRun){
startActivity(new Intent(GnuCashApplication.getAppContext(), FirstRunWizardActivity.class));

//default to using double entry and save the preference explicitly
// Default Preference to using double entry and save the preference explicitly
prefs.edit().putBoolean(getString(R.string.key_use_double_entry), true).apply();

// Default preference not to show negative number in splits
prefs.edit().putBoolean(getString(R.string.key_display_negative_signum_in_splits), false).apply();

finish();

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,58 @@ public boolean onPreferenceClick(Preference preference) {
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference.getKey().equals(getString(R.string.key_enable_passcode))) {
public boolean onPreferenceChange(Preference preference,
Object newValue) {

if (preference.getKey()
.equals(getString(R.string.key_enable_passcode))) {

if ((Boolean) newValue) {
startActivityForResult(new Intent(getActivity(), PasscodePreferenceActivity.class),
GeneralPreferenceFragment.PASSCODE_REQUEST_CODE);

startActivityForResult(new Intent(getActivity(),
PasscodePreferenceActivity.class),
GeneralPreferenceFragment.PASSCODE_REQUEST_CODE);

} else {
Intent passIntent = new Intent(getActivity(), PasscodeLockScreenActivity.class);
passIntent.putExtra(UxArgument.DISABLE_PASSCODE, UxArgument.DISABLE_PASSCODE);
startActivityForResult(passIntent, GeneralPreferenceFragment.REQUEST_DISABLE_PASSCODE);

Intent passIntent = new Intent(getActivity(),
PasscodeLockScreenActivity.class);
passIntent.putExtra(UxArgument.DISABLE_PASSCODE,
UxArgument.DISABLE_PASSCODE);
startActivityForResult(passIntent,
GeneralPreferenceFragment.REQUEST_DISABLE_PASSCODE);
}
}

if (preference.getKey().equals(getString(R.string.key_use_account_color))) {
//
// Set Preference : use_color_in_reports
//

if (preference.getKey()
.equals(getString(R.string.key_use_account_color))) {

getPreferenceManager().getSharedPreferences()
.edit()
.putBoolean(getString(R.string.key_use_account_color), Boolean.valueOf(newValue.toString()))
.commit();
.edit()
.putBoolean(getString(R.string.key_use_account_color),
Boolean.valueOf(newValue.toString()))
.commit();
}

//
// Preference : key_display_negative_signum_in_splits
//

if (preference.getKey()
.equals(getString(R.string.key_display_negative_signum_in_splits))) {

// Store the new value of the Preference
getPreferenceManager().getSharedPreferences()
.edit()
.putBoolean(getString(R.string.key_display_negative_signum_in_splits),
Boolean.valueOf(newValue.toString()))
.commit();
}

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,6 @@
<string name="label_select_destination_after_export">Sélectionnez la destination une fois l\'exportation terminée</string>
<string name="label_dropbox_export_destination">Exporter dans le dossier \'/Apps/GnuCash Android/\' sur Dropbox</string>
<string name="title_section_preferences">Préférences</string>
<string name="title_display_negative_signum_in_splits">Afficher le signe - dans les transactions splittées</string>
<string name="summary_display_negative_signum_in_splits">Autoriser l\'affichage du signe - même lorsque le bouton Débit/Crédit est affiché</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<string name="key_use_account_color" translatable="false">use_account_color</string>
<string name="key_last_export_destination">last_export_destination</string>
<string name="key_use_compact_list">use_compact_list</string>
<string name="key_display_negative_signum_in_splits" translatable="false">key_display_negative_signum_in_splits</string>
<string name="key_prefs_header_general">prefs_header_general</string>
<string name="key_dropbox_access_token">dropbox_access_token</string>
<string name="key_backup_location">backup_location</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@
<string name="title_budgets">Budgets</string>
<string name="title_use_compact_list">Enable compact view</string>
<string name="summary_use_compact_list">Enable to always use compact view for transactions list</string>
<string name="title_display_negative_signum_in_splits">Display negative signum in splits</string>
<string name="summary_display_negative_signum_in_splits">Enable to display negative signum amount even when debit/credit toggle button is displayed</string>
<string name="error_invalid_exchange_rate">Invalid exchange rate</string>
<string name="sample_exchange_rate">e.g. 1 %1$s = x.xx %2$s</string>
<string name="error_invalid_amount">Invalid amount</string>
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/res/xml/fragment_general_preferences.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="@string/title_passcode_preferences">

<android.support.v7.preference.SwitchPreferenceCompat
android:key="@string/key_display_negative_signum_in_splits"
android:title="@string/title_display_negative_signum_in_splits"
android:summary="@string/summary_display_negative_signum_in_splits"
/>

<CheckBoxPreference android:key="@string/key_enable_passcode"
android:title="@string/title_enable_passcode"/>

<Preference android:key="@string/key_change_passcode"
android:title="@string/title_change_passcode"
android:dependency="@string/key_enable_passcode" />

</PreferenceCategory>

<PreferenceCategory android:title="@string/title_report_prefs">

<CheckBoxPreference android:key="@string/key_use_account_color"
android:title="@string/title_use_account_color"
android:summary="@string/summary_use_account_color" />
</PreferenceCategory>

</PreferenceCategory>

</PreferenceScreen>

0 comments on commit bc27e47

Please sign in to comment.