]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java
fix a bunch of spelling mistakes all around
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / transaction_list / TransactionListFragment.java
index 68e243a891d4662cdfc76d4e9ef5a0e12fdb4dc3..fd13bc60ee70a825227ec47495df64baf0f9b1fa 100644 (file)
@@ -17,7 +17,6 @@
 
 package net.ktnx.mobileledger.ui.transaction_list;
 
-import android.content.Context;
 import android.database.Cursor;
 import android.os.AsyncTask;
 import android.os.Bundle;
@@ -68,11 +67,6 @@ public class TransactionListFragment extends MobileLedgerListFragment
         super.onCreate(savedInstanceState);
         setHasOptionsMenu(true);
     }
-    @Override
-    public void onAttach(@NotNull Context context) {
-        super.onAttach(context);
-        mActivity = (MainActivity) context;
-    }
     @Nullable
     @Override
     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@@ -102,46 +96,48 @@ public class TransactionListFragment extends MobileLedgerListFragment
         Data.backgroundTasksRunning.observe(getViewLifecycleOwner(),
                 this::onBackgroundTaskRunningChanged);
 
-        swiper = mActivity.findViewById(R.id.transaction_swipe);
-        if (swiper == null)
+        MainActivity mainActivity = getMainActivity();
+
+        refreshLayout = mainActivity.findViewById(R.id.transaction_swipe);
+        if (refreshLayout == null)
             throw new RuntimeException("Can't get hold on the swipe layout");
-        root = mActivity.findViewById(R.id.transaction_root);
+        root = mainActivity.findViewById(R.id.transaction_root);
         if (root == null)
             throw new RuntimeException("Can't get hold on the transaction value view");
         modelAdapter = new TransactionListAdapter();
         root.setAdapter(modelAdapter);
 
-        mActivity.fabShouldShow();
+        mainActivity.fabShouldShow();
 
         manageFabOnScroll();
 
-        LinearLayoutManager llm = new LinearLayoutManager(mActivity);
+        LinearLayoutManager llm = new LinearLayoutManager(mainActivity);
 
         llm.setOrientation(RecyclerView.VERTICAL);
         root.setLayoutManager(llm);
 
-        swiper.setOnRefreshListener(() -> {
+        refreshLayout.setOnRefreshListener(() -> {
             debug("ui", "refreshing transactions via swipe");
-            Data.scheduleTransactionListRetrieval(mActivity);
+            Data.scheduleTransactionListRetrieval(mainActivity);
         });
 
         Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged);
 
-        vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter);
-        accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
+        vAccountFilter = mainActivity.findViewById(R.id.transaction_list_account_name_filter);
+        accNameFilter = mainActivity.findViewById(R.id.transaction_filter_account_name);
 
-        MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name");
+        MLDB.hookAutocompletionAdapter(mainActivity, accNameFilter, "accounts", "name");
         accNameFilter.setOnItemClickListener((parent, view, position, id) -> {
 //                debug("tmp", "direct onItemClick");
             Cursor c = (Cursor) parent.getItemAtPosition(position);
             Data.accountFilter.setValue(c.getString(1));
-            Globals.hideSoftKeyboard(mActivity);
+            Globals.hideSoftKeyboard(mainActivity);
         });
 
         Data.accountFilter.observe(getViewLifecycleOwner(), this::onAccountNameFilterChanged);
 
         TransactionListViewModel.updating.addObserver(
-                (o, arg) -> swiper.setRefreshing(TransactionListViewModel.updating.get()));
+                (o, arg) -> refreshLayout.setRefreshing(TransactionListViewModel.updating.get()));
         TransactionListViewModel.updateError.addObserver((o, arg) -> {
             String err = TransactionListViewModel.updateError.get();
             if (err == null)
@@ -152,20 +148,23 @@ public class TransactionListFragment extends MobileLedgerListFragment
             TransactionListViewModel.updateError.set(null);
         });
         Data.transactions.addObserver(
-                (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
+                (o, arg) -> mainActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
 
-        mActivity.findViewById(R.id.clearAccountNameFilter)
-                 .setOnClickListener(v -> {
-                     Data.accountFilter.setValue(null);
-                     vAccountFilter.setVisibility(View.GONE);
-                     menuTransactionListFilter.setVisible(true);
-                     Globals.hideSoftKeyboard(mActivity);
-                 });
+        mainActivity.findViewById(R.id.clearAccountNameFilter)
+                    .setOnClickListener(v -> {
+                        Data.accountFilter.setValue(null);
+                        vAccountFilter.setVisibility(View.GONE);
+                        menuTransactionListFilter.setVisible(true);
+                        Globals.hideSoftKeyboard(mainActivity);
+                    });
 
         Data.foundTransactionItemIndex.observe(getViewLifecycleOwner(), pos -> {
             Logger.debug("go-to-date", String.format(Locale.US, "Found pos %d", pos));
-            if (pos != null)
+            if (pos != null) {
                 root.scrollToPosition(pos);
+                // reset the value to avoid re-notification upon reconfiguration or app restart
+                Data.foundTransactionItemIndex.setValue(null);
+            }
         });
     }
     private void onAccountNameFilterChanged(String accName) {
@@ -209,7 +208,7 @@ public class TransactionListFragment extends MobileLedgerListFragment
                 menuTransactionListFilter.setVisible(false);
             accNameFilter.requestFocus();
             InputMethodManager imm =
-                    (InputMethodManager) mActivity.getSystemService(INPUT_METHOD_SERVICE);
+                    (InputMethodManager) getMainActivity().getSystemService(INPUT_METHOD_SERVICE);
             imm.showSoftInput(accNameFilter, 0);
 
             return true;