- prepare_db();
-// update_account_table();
- update_accounts(false);
-
- }
- private void prepare_db() {
- account_list_last_updated = MLDB.get_option_value(MLDB.OPT_LAST_REFRESH, (long) 0);
- }
-
- private void update_accounts(boolean force) {
- long now = new Date().getTime();
- if ((now > (account_list_last_updated + (24 * 3600 * 1000))) || force) {
- Log.d("db",
- "accounts last updated at " + account_list_last_updated + " and now is " + now +
- ". re-fetching");
- update_accounts();
- }
- }
-
- private void update_accounts() {
- RetrieveAccountsTask task = new RetrieveAccountsTask(new WeakReference<>(mActivity));
-
- task.setPref(PreferenceManager.getDefaultSharedPreferences(mActivity));
- task.execute();
-
- }
- private void update_account_table() {
- if (this.getContext() == null) return;
-
- model.reloadAccounts(this.getContext());
- modelAdapter.notifyDataSetChanged();
- }
- 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) {
- optMenu.findItem(R.id.menu_acc_summary_cancel_selection).setVisible(false);
- optMenu.findItem(R.id.menu_acc_summary_confirm_selection).setVisible(false);
- optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(true);
- }
- {
- if (fab != null) fab.show();
- }
- }
- public void onCancelAccSelection(MenuItem item) {
- stopSelection();
- }
- public void onConfirmAccSelection(MenuItem item) {
- model.commitSelections(mActivity);
- stopSelection();
- }
- @Override
- public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
- // Inflate the menu; this adds items to the action bar if it is present.
- 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();
-
- sBindPreferenceSummaryToValueListener = (preference, value) -> mShowHiddenAccounts
- .setChecked(preference.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mActivity);
- pref.registerOnSharedPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
-
- mShowHiddenAccounts.setChecked(pref.getBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, false));