import net.ktnx.mobileledger.async.RetrieveAccountsTask;
import net.ktnx.mobileledger.model.LedgerAccount;
-import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
+import net.ktnx.mobileledger.utils.MLDB;
import java.lang.ref.WeakReference;
import java.util.Date;
private static boolean account_list_needs_update = true;
MenuItem mShowHiddenAccounts;
SharedPreferences.OnSharedPreferenceChangeListener sBindPreferenceSummaryToValueListener;
- private MobileLedgerDatabase dbh;
private AccountSummaryViewModel model;
private AccountSummaryAdapter modelAdapter;
private Menu optMenu;
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- dbh = new MobileLedgerDatabase(this);
-
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
}
model = ViewModelProviders.of(this).get(AccountSummaryViewModel.class);
- List<LedgerAccount> accounts = model.getAccounts();
+ List<LedgerAccount> accounts = model.getAccounts(getApplicationContext());
modelAdapter = new AccountSummaryAdapter(accounts);
RecyclerView root = findViewById(R.id.account_root);
if (dy > 0) ((FloatingActionButton) findViewById(R.id.btn_add_transaction)).hide();
}
});
- ((SwipeRefreshLayout) findViewById(R.id.account_swiper)).setOnRefreshListener(() -> {
+ SwipeRefreshLayout swiper = findViewById(R.id.account_swiper);
+ swiper.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
+ swiper.setOnRefreshListener(() -> {
Log.d("ui", "refreshing accounts via swipe");
update_accounts(true);
});
}
private void prepare_db() {
- account_list_last_updated = dbh.get_option_value("last_refresh", (long) 0);
+ account_list_last_updated = MLDB.get_option_value(this, "last_refresh", (long) 0);
}
private void update_accounts(boolean force) {
Snackbar.make(drawer, err_text, Snackbar.LENGTH_LONG ).show();
}
else {
- dbh.set_option_value("last_refresh", new Date().getTime() );
+ MLDB.set_option_value(this, "last_refresh", new Date().getTime());
update_account_table();
}
}
private void update_account_table() {
- model.reloadAccounts();
+ model.reloadAccounts(getApplicationContext());
modelAdapter.notifyDataSetChanged();
}
void stopSelection() {
stopSelection();
}
public void onConfirmAccSelection(MenuItem item) {
- model.commitSelections();
+ model.commitSelections(getApplicationContext());
stopSelection();
}
}