X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Ftransaction_list%2FTransactionListFragment.java;h=c09c5c4a6e50c102073f91d6630df2a802e8739e;hp=088fd0bd94527f37107de03c1489e8a31c750e5c;hb=b1c8ac231f53cba9fbac1783f36d6814ef7c7840;hpb=138706a5444b5b9b3b4038b69b27338793dbeb6b diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index 088fd0bd..c09c5c4a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -20,7 +20,6 @@ package net.ktnx.mobileledger.ui.transaction_list; import android.content.Context; import android.database.MatrixCursor; import android.os.Bundle; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -43,41 +42,23 @@ import net.ktnx.mobileledger.utils.MLDB; import org.jetbrains.annotations.NotNull; -import java.util.Observer; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import static android.content.Context.INPUT_METHOD_SERVICE; +import static net.ktnx.mobileledger.utils.Logger.debug; public class TransactionListFragment extends MobileLedgerListFragment { private MenuItem menuTransactionListFilter; private View vAccountFilter; private AutoCompleteTextView accNameFilter; - private Observer backgroundTaskCountObserver; - @Override - public void onDestroy() { - if (backgroundTaskCountObserver != null) { - Log.d("rtl", "destroying background task count observer"); - Data.backgroundTaskCount.deleteObserver(backgroundTaskCountObserver); - } - super.onDestroy(); - } @Override 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 = (o, arg) -> mActivity.runOnUiThread(() -> { - int cnt = Data.backgroundTaskCount.get(); - Log.d("trl", String.format("background task count changed to %d", cnt)); - swiper.setRefreshing(cnt > 0); - })); - } + Data.backgroundTasksRunning.observe(this, this::onBackgroundTaskRunningChanged); } @Override public void onAttach(@NotNull Context context) { @@ -93,21 +74,21 @@ public class TransactionListFragment extends MobileLedgerListFragment { @Override public void onResume() { super.onResume(); - Log.d("flow", "TransactionListFragment.onResume()"); + debug("flow", "TransactionListFragment.onResume()"); } @Override public void onStop() { super.onStop(); - Log.d("flow", "TransactionListFragment.onStop()"); + debug("flow", "TransactionListFragment.onStop()"); } @Override public void onPause() { super.onPause(); - Log.d("flow", "TransactionListFragment.onPause()"); + debug("flow", "TransactionListFragment.onPause()"); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { - Log.d("flow", "TransactionListFragment.onActivityCreated called"); + debug("flow", "TransactionListFragment.onActivityCreated called"); super.onActivityCreated(savedInstanceState); swiper = mActivity.findViewById(R.id.transaction_swipe); @@ -135,19 +116,18 @@ public class TransactionListFragment extends MobileLedgerListFragment { root.setLayoutManager(llm); swiper.setOnRefreshListener(() -> { - Log.d("ui", "refreshing transactions via swipe"); + debug("ui", "refreshing transactions via swipe"); mActivity.scheduleTransactionListRetrieval(); }); Colors.themeWatch.observe(this, this::themeChanged); - swiper.setColorSchemeColors(Colors.primary); vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter); accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name); MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name", true); accNameFilter.setOnItemClickListener((parent, view, position, id) -> { -// Log.d("tmp", "direct onItemClick"); +// debug("tmp", "direct onItemClick"); MatrixCursor mc = (MatrixCursor) parent.getItemAtPosition(position); Data.accountFilter.setValue(mc.getString(1)); Globals.hideSoftKeyboard(mActivity); @@ -175,6 +155,9 @@ public class TransactionListFragment extends MobileLedgerListFragment { }); } private void onAccountNameFilterChanged(String accName) { + final String fieldText = accNameFilter.getText().toString(); + if ((accName == null) && (fieldText.equals(""))) return; + if (accNameFilter != null) { accNameFilter.setText(accName, false); }