public static ObservableList<MobileLedgerProfile> profiles =
new ObservableList<>(new ArrayList<>());
public static ObservableValue<Boolean> optShowOnlyStarred = new ObservableValue<>();
- public static ObservableValue<String> accountFilter = new ObservableValue<>();
+ public static MutableLiveData<String> accountFilter = new MutableLiveData<>();
public static void setCurrentProfile(MobileLedgerProfile newProfile) {
MLDB.setOption(MLDB.OPT_PROFILE_UUID, newProfile.getUuid());
profile.set(newProfile);
Log.d("flow", "MainActivity.onStart()");
mViewPager.setCurrentItem(mCurrentPage, false);
if (mAccountFilter != null) showTransactionsFragment(mAccountFilter);
- else Data.accountFilter.set(null);
+ else Data.accountFilter.setValue(null);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_CURRENT_PAGE, mViewPager.getCurrentItem());
- if (Data.accountFilter.get() != null)
- outState.putString(STATE_ACC_FILTER, Data.accountFilter.get());
+ if (mAccountFilter != null)
+ outState.putString(STATE_ACC_FILTER, mAccountFilter);
}
@Override
protected void onDestroy() {
}
private void showAccountSummaryFragment() {
mViewPager.setCurrentItem(0, true);
- Data.accountFilter.set(null);
+ Data.accountFilter.setValue(null);
// FragmentTransaction ft = fragmentManager.beginTransaction();
// accountSummaryFragment = new AccountSummaryFragment();
// ft.replace(R.id.root_frame, accountSummaryFragment);
// fragmentManager.popBackStack(0, FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
private void showTransactionsFragment(String accName) {
- Data.accountFilter.set(accName);
- Data.accountFilter.notifyObservers();
+ Data.accountFilter.setValue(accName);
mViewPager.setCurrentItem(1, true);
}
private void showTransactionsFragment(LedgerAccount account) {
}
else {
if (mBackMeansToAccountList && (mViewPager.getCurrentItem() == 1)) {
- Data.accountFilter.set(null);
+ Data.accountFilter.setValue(null);
showAccountSummaryFragment();
mBackMeansToAccountList = false;
}
TransactionLoader loader = new TransactionLoader();
loader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
- new TransactionLoaderParams(tr, holder, position, Data.accountFilter.get(),
+ new TransactionLoaderParams(tr, holder, position, Data.accountFilter.getValue(),
item.isOdd()));
// WORKAROUND what seems to be a bug in CardHolder somewhere
private View vAccountFilter;
private AutoCompleteTextView accNameFilter;
private Observer backgroundTaskCountObserver;
- private Observer accountFilterObserver;
- private static void update(Observable o, Object arg) {
- }
@Override
public void onDestroy() {
if (backgroundTaskCountObserver != null) {
}
super.onDestroy();
}
- public void setShowOnlyAccountName(String mShowOnlyAccountName) {
- }
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
accNameFilter.setOnItemClickListener((parent, view, position, id) -> {
// Log.d("tmp", "direct onItemClick");
MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position);
- Data.accountFilter.set(mc.getString(1));
+ Data.accountFilter.setValue(mc.getString(1));
Globals.hideSoftKeyboard(mActivity);
});
- if (accountFilterObserver == null) {
- accountFilterObserver = (o, arg) -> onAccountNameFilterChanged();
- Data.accountFilter.addObserver(accountFilterObserver);
- }
+ Data.accountFilter.observe(this, this::onAccountNameFilterChanged);
TransactionListViewModel.updating.addObserver(
(o, arg) -> swiper.setRefreshing(TransactionListViewModel.updating.get()));
(o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
mActivity.findViewById(R.id.clearAccountNameFilter).setOnClickListener(v -> {
- String current = Data.accountFilter.get();
- Data.accountFilter.set(null);
+ Data.accountFilter.setValue(null);
vAccountFilter.setVisibility(View.GONE);
menuTransactionListFilter.setVisible(true);
Globals.hideSoftKeyboard(mActivity);
});
-
- onAccountNameFilterChanged(false);
- }
- private void onAccountNameFilterChanged() {
- onAccountNameFilterChanged(true);
}
- private void onAccountNameFilterChanged(boolean reloadTransactions) {
- String accName = Data.accountFilter.get();
+ private void onAccountNameFilterChanged(String accName) {
if (accNameFilter != null) {
accNameFilter.setText(accName, false);
}
}
if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(!filterActive);
- if (reloadTransactions) TransactionListViewModel.scheduleTransactionListReload();
+ TransactionListViewModel.scheduleTransactionListReload();
}
@Override
menuTransactionListFilter = menu.findItem(R.id.menu_transaction_list_filter);
if ((menuTransactionListFilter == null)) throw new AssertionError();
- if (Data.accountFilter.get() != null) {
+ if (Data.accountFilter.getValue() != null) {
menuTransactionListFilter.setVisible(false);
}
public static void scheduleTransactionListReload() {
if (Data.profile.get() == null) return;
- String filter = Data.accountFilter.get();
+ String filter = Data.accountFilter.getValue();
AsyncTask<String, Void, String> task = new UTT();
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, filter);
}