import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
-import android.widget.AdapterView;
import android.widget.AutoCompleteTextView;
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.ui.activity.MainActivity;
import net.ktnx.mobileledger.utils.Globals;
import net.ktnx.mobileledger.utils.MLDB;
+import net.ktnx.mobileledger.utils.ObservableValue;
import java.util.Observable;
import java.util.Observer;
public class TransactionListFragment extends MobileLedgerListFragment {
public static final String BUNDLE_KEY_FILTER_ACCOUNT_NAME = "filter_account_name";
+ public static ObservableValue<String> accountFilter = new ObservableValue<>();
private String mShowOnlyAccountName;
private MenuItem menuTransactionListFilter;
private View vAccountFilter;
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.transaction_list_fragment, container, false);
}
-
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
Log.d("flow", "TransactionListFragment.onActivityCreated called");
TransactionListFragment me = this;
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) {
+ accNameFilter.setOnItemClickListener((parent, view, position, id) -> {
// Log.d("tmp", "direct onItemClick");
- TransactionListViewModel.scheduleTransactionListReload(mActivity);
- MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position);
- modelAdapter.setBoldAccountName(mc.getString(1));
- modelAdapter.notifyDataSetChanged();
- Globals.hideSoftKeyboard(mActivity);
- }
+ TransactionListViewModel.scheduleTransactionListReload();
+ MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position);
+ accountFilter.set(mc.getString(1));
+ Globals.hideSoftKeyboard(mActivity);
});
- if (mShowOnlyAccountName != null) {
- accNameFilter.setText(mShowOnlyAccountName, false);
- onShowFilterClick(null);
- 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);
- });
- }
+ accountFilter.addObserver((o, arg) -> {
+ String accountName = accountFilter.get();
+ modelAdapter.setBoldAccountName(accountName);
+ setShowOnlyAccountName(accountName);
+ TransactionListViewModel.scheduleTransactionListReload();
+ if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(false);
});
- TransactionListViewModel.scheduleTransactionListReload(mActivity);
- TransactionListViewModel.updating.addObserver(new Observer() {
- @Override
- public void update(Observable o, Object arg) {
- swiper.setRefreshing(TransactionListViewModel.updating.get());
- }
+ Data.profile.addObserver((o, arg) -> mActivity.runOnUiThread(() -> {
+ Log.d("transactions", "requesting list reload");
+ TransactionListViewModel.scheduleTransactionListReload();
+ }));
+
+ TransactionListViewModel.scheduleTransactionListReload();
+ TransactionListViewModel.updating.addObserver(
+ (o, arg) -> swiper.setRefreshing(TransactionListViewModel.updating.get()));
+
+ Data.transactions.addObserver(
+ (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
+
+ mActivity.findViewById(R.id.clearAccountNameFilter).setOnClickListener(v -> {
+ vAccountFilter.setVisibility(View.GONE);
+ if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(true);
+ accountFilter.set(null);
+ accNameFilter.setText(null);
+ TransactionListViewModel.scheduleTransactionListReload();
+ Globals.hideSoftKeyboard(mActivity);
});
-
- Data.transactions.addObserver(new Observer() {
- @Override
- public void update(Observable o, Object arg) {
- mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged());
- }
- });
-
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
}
super.onCreateOptionsMenu(menu, inflater);
- }
- public void onClearAccountNameClick(View view) {
- vAccountFilter.setVisibility(View.GONE);
- if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(true);
- accNameFilter.setText(null);
- mShowOnlyAccountName = null;
- modelAdapter.resetBoldAccountName();
- TransactionListViewModel.scheduleTransactionListReload(mActivity);
- Globals.hideSoftKeyboard(mActivity);
- }
- public void onShowFilterClick(MenuItem menuItem) {
- vAccountFilter.setVisibility(View.VISIBLE);
- if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(false);
- if (menuItem != null) {
+ menuTransactionListFilter.setOnMenuItemClickListener(item -> {
+ vAccountFilter.setVisibility(View.VISIBLE);
+ if (menuTransactionListFilter != null) menuTransactionListFilter.setVisible(false);
accNameFilter.requestFocus();
InputMethodManager imm =
(InputMethodManager) mActivity.getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(accNameFilter, 0);
- }
+
+ return true;
+ });
}
}
\ No newline at end of file
package net.ktnx.mobileledger.ui.transaction_list;
-import android.app.Activity;
import android.arch.lifecycle.ViewModel;
import android.os.AsyncTask;
-import android.view.View;
-import android.widget.AutoCompleteTextView;
-import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.async.UpdateTransactionsTask;
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerTransaction;
public class TransactionListViewModel extends ViewModel {
public static ObservableValue<Boolean> updating = new ObservableValue<>();
- public static void scheduleTransactionListReload(Activity act) {
- View filter = act.findViewById(R.id.transaction_list_account_name_filter);
- if (filter == null) return;
- boolean hasFilter = filter.getVisibility() == View.VISIBLE;
- String accFilter = hasFilter ? String.valueOf(
- ((AutoCompleteTextView) act.findViewById(R.id.transaction_filter_account_name))
- .getText()) : null;
+ public static void scheduleTransactionListReload() {
+ String filter = TransactionListFragment.accountFilter.get();
AsyncTask<String, Void, List<LedgerTransaction>> task = new UTT();
- task.execute(accFilter);
+ task.execute(filter);
}
public static LedgerTransaction getTransaction(int position) {
List<LedgerTransaction> transactions = Data.transactions.get();