/*
- * Copyright © 2018 Damyan Ivanov.
+ * Copyright © 2019 Damyan Ivanov.
* This file is part of Mobile-Ledger.
* Mobile-Ledger is free software: you can distribute it and/or modify it
* under the term of the GNU General Public License as published by
package net.ktnx.mobileledger;
import android.app.Application;
+import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
+import android.preference.PreferenceManager;
+import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.utils.Globals;
import net.ktnx.mobileledger.utils.MLDB;
+import static net.ktnx.mobileledger.ui.activity.SettingsActivity.PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS;
+
public class MobileLedgerApplication extends Application {
@Override
super.onCreate();
updateColorValues();
MLDB.init(this);
+ SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
+ Data.optShowOnlyStarred.set(p.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
+ SharedPreferences.OnSharedPreferenceChangeListener handler = (preference, value) -> {
+ Data.optShowOnlyStarred
+ .set(preference.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
+ };
+ p.registerOnSharedPreferenceChangeListener(handler);
}
@Override
public void onTerminate() {
public static ObservableValue<MobileLedgerProfile> profile = new ObservableValue<>();
public static ObservableList<MobileLedgerProfile> profiles =
new ObservableList<>(new ArrayList<>());
+ public static ObservableValue<Boolean> optShowOnlyStarred = new ObservableValue<>();
}
public class AccountSummaryFragment extends MobileLedgerListFragment {
- private static long account_list_last_updated;
- private static boolean account_list_needs_update = true;
- MenuItem mShowHiddenAccounts;
+ MenuItem mShowOnlyStarred;
SharedPreferences.OnSharedPreferenceChangeListener sBindPreferenceSummaryToValueListener;
private AccountSummaryViewModel model;
private AccountSummaryAdapter modelAdapter;
private Observer backgroundTaskCountObserver;
@Override
public void onDestroy() {
- if(backgroundTaskCountObserver!= null) {
+ if (backgroundTaskCountObserver != null) {
Log.d("acc", "destroying background task count observer");
Data.backgroundTaskCount.deleteObserver(backgroundTaskCountObserver);
}
model.scheduleAccountListReload(this.getContext());
}
- public void onShowOnlyStarredClicked(MenuItem mi) {
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mActivity);
- boolean flag = pref.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false);
-
- SharedPreferences.Editor editor = pref.edit();
- editor.putBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, !flag);
- Log.d("pref", "Setting show only starred accounts pref to " + (flag ? "false" : "true"));
- editor.apply();
-
- update_account_table();
- }
-
void stopSelection() {
modelAdapter.stopSelection();
if (optMenu != null) {
inflater.inflate(R.menu.account_summary, menu);
optMenu = menu;
- mShowHiddenAccounts = menu.findItem(R.id.menu_acc_summary_only_starred);
- if (mShowHiddenAccounts == null) throw new AssertionError();
+ mShowOnlyStarred = menu.findItem(R.id.menu_acc_summary_only_starred);
+ if (mShowOnlyStarred == null) throw new AssertionError();
- sBindPreferenceSummaryToValueListener = (preference, value) -> mShowHiddenAccounts
- .setChecked(preference.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mActivity);
- pref.registerOnSharedPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
+ Data.optShowOnlyStarred.addObserver(new Observer() {
+ @Override
+ public void update(Observable o, Object arg) {
+ boolean newValue = Data.optShowOnlyStarred.get();
+ Log.d("pref", String.format("pref change came (%s)", newValue ? "true" : "false"));
+ mShowOnlyStarred.setChecked(newValue);
+ update_account_table();
+ }
+ });
+
+ mShowOnlyStarred.setChecked(Data.optShowOnlyStarred.get());
- mShowHiddenAccounts.setChecked(pref.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
+ Log.d("menu", "Accounts: onCreateOptionsMenu called");
- Log.d("menu", "MainActivity: onCreateOptionsMenu called");
+ mShowOnlyStarred.setOnMenuItemClickListener(item -> {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mActivity);
+ SharedPreferences.Editor editor = pref.edit();
+ boolean flag = item.isChecked();
+ editor.putBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, !flag);
+ Log.d("pref",
+ "Setting show only starred accounts pref to " + (flag ? "false" : "true"));
+ editor.apply();
+
+
+ return true;
+ });
}
}
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
-import android.view.ContextMenu;
-import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
}
}
}
- public void onOptionsMenuClicked(MenuItem menuItem) {
- ContextMenu.ContextMenuInfo info = menuItem.getMenuInfo();
- switch (menuItem.getItemId()) {
- case R.id.menu_acc_summary_cancel_selection:
- if (accountSummaryFragment != null)
- accountSummaryFragment.onCancelAccSelection(menuItem);
- break;
- case R.id.menu_acc_summary_confirm_selection:
- if (accountSummaryFragment != null)
- accountSummaryFragment.onConfirmAccSelection(menuItem);
- break;
- case R.id.menu_acc_summary_only_starred:
- if (accountSummaryFragment != null)
- accountSummaryFragment.onShowOnlyStarredClicked(menuItem);
- break;
- case R.id.menu_transaction_list_filter:
- if (transactionListFragment != null)
- transactionListFragment.onShowFilterClick(menuItem);
- break;
- default:
- Log.e("menu", String.format("Menu item %d not handled", menuItem.getItemId()));
- }
- }
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.clearAccountNameFilter:
<?xml version="1.0" encoding="utf-8"?>
<!--
- ~ Copyright © 2018 Damyan Ivanov.
+ ~ Copyright © 2019 Damyan Ivanov.
~ This file is part of Mobile-Ledger.
~ Mobile-Ledger is free software: you can distribute it and/or modify it
~ under the term of the GNU General Public License as published by
android:id="@+id/menu_acc_summary_only_starred"
android:checkable="true"
android:checked="false"
- android:onClick="onOptionsMenuClicked"
android:title="@string/menu_acc_summary_show_only_starred_title"
app:actionLayout="@layout/switch_item"
app:showAsAction="never" />
android:title="@string/menu_acc_summary_hide_selected_title"
app:showAsAction="always"
android:visible="false"
- android:onClick="onOptionsMenuClicked"
/>
<item android:id="@+id/menu_acc_summary_cancel_selection"
android:title="@string/menu_acc_summary_cancel_selection_title"
app:showAsAction="always"
android:visible="false"
- android:onClick="onOptionsMenuClicked"
android:icon="@drawable/ic_cancel_white_24dp" />
<item android:id="@+id/menu_acc_summary_confirm_selection"
android:title="@string/menu_acc_summary_confirm_selection_title"
app:showAsAction="always"
android:visible="false"
- android:onClick="onOptionsMenuClicked"
android:icon="@drawable/ic_check_white_24dp" />
</menu>
\ No newline at end of file