private MenuItem menuTransactionListFilter;
private View vAccountFilter;
private AutoCompleteTextView accNameFilter;
+ private Observer backgroundTaskCountObserver;
private static void update(Observable o, Object arg) {
}
+ @Override
+ public void onDestroy() {
+ if (backgroundTaskCountObserver != null) {
+ Log.d("rtl", "destroying background task count observer");
+ Data.backgroundTaskCount.deleteObserver(backgroundTaskCountObserver);
+ }
+ super.onDestroy();
+ }
public void setShowOnlyAccountName(String mShowOnlyAccountName) {
this.mShowOnlyAccountName = mShowOnlyAccountName;
if (modelAdapter != null) {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
+ if (backgroundTaskCountObserver == null) {
+ Log.d("rtl", "creating background task count observer");
+ Data.backgroundTaskCount.addObserver(backgroundTaskCountObserver = new Observer() {
+ @Override
+ public void update(Observable o, Object arg) {
+ mActivity.runOnUiThread(() -> {
+ int cnt = Data.backgroundTaskCount.get();
+ Log.d("trl", String.format("background task count changed to %d", cnt));
+ swiper.setRefreshing(cnt > 0);
+ });
+ }
+ });
+ }
}
@Override
public void onAttach(Context context) {
Log.d("flow", "TransactionListFragment.onActivityCreated called");
super.onActivityCreated(savedInstanceState);
- mActivity.markDrawerItemCurrent(R.id.nav_latest_transactions);
-
swiper = mActivity.findViewById(R.id.transaction_swipe);
if (swiper == null) throw new RuntimeException("Can't get hold on the swipe layout");
root = mActivity.findViewById(R.id.transaction_root);
modelAdapter = new TransactionListAdapter();
modelAdapter.setBoldAccountName(mShowOnlyAccountName);
+ root.setAdapter(modelAdapter);
FloatingActionButton fab = mActivity.findViewById(R.id.btn_add_transaction);
- RecyclerView root = mActivity.findViewById(R.id.transaction_root);
- root.setAdapter(modelAdapter);
-
fab.show();
root.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
- if (fab != null) {
- if (dy < 0) fab.show();
- if (dy > 0) fab.hide();
- }
+ if (dy < 0) fab.show();
+ if (dy > 0) fab.hide();
}
});
swiper.setOnRefreshListener(() -> {
Log.d("ui", "refreshing transactions via swipe");
- mActivity.update_transactions();
+ mActivity.scheduleTransactionListRetrieval();
});
swiper.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
TransactionListFragment me = this;
- MLDB.hook_autocompletion_adapter(mActivity, accNameFilter, "accounts", "name");
+ MLDB.hook_autocompletion_adapter(mActivity, accNameFilter, "accounts", "name", true);
accNameFilter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("tmp", "direct onItemClick");
- ((TransactionListViewModel) model).scheduleTransactionListReload(mActivity);
+ TransactionListViewModel.scheduleTransactionListReload(mActivity);
MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position);
modelAdapter.setBoldAccountName(mc.getString(1));
modelAdapter.notifyDataSetChanged();
Log.d("flow", String.format("Account filter set to '%s'", mShowOnlyAccountName));
}
+ Data.profile.addObserver(new Observer() {
+ @Override
+ public void update(Observable o, Object arg) {
+ mActivity.runOnUiThread(() -> {
+ Log.d("transactions", "requesting list reload");
+ TransactionListViewModel.scheduleTransactionListReload(mActivity);
+ });
+ }
+ });
+
TransactionListViewModel.scheduleTransactionListReload(mActivity);
TransactionListViewModel.updating.addObserver(new Observer() {
@Override
Data.transactions.addObserver(new Observer() {
@Override
public void update(Observable o, Object arg) {
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- modelAdapter.notifyDataSetChanged();
- }
- });
+ mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged());
}
});
+
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {