]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
single observer instances, single place for reloading account/transaction lists
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryFragment.java
index dd4e4d49ae37561288fd02d00197f9f702c25f11..93975b05e59357bf40ae8f484dbe057ac7add7a6 100644 (file)
@@ -33,17 +33,15 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
 
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
-import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.ui.MobileLedgerListFragment;
-import net.ktnx.mobileledger.ui.RecyclerItemListener;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.Colors;
 
-import java.util.List;
 import java.util.Observer;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.recyclerview.widget.DividerItemDecoration;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 
@@ -52,7 +50,7 @@ import static net.ktnx.mobileledger.ui.activity.SettingsActivity.PREF_KEY_SHOW_O
 public class AccountSummaryFragment extends MobileLedgerListFragment {
 
     MenuItem mShowOnlyStarred;
-    private AccountSummaryAdapter modelAdapter;
+    public AccountSummaryAdapter modelAdapter;
     private Menu optMenu;
     private FloatingActionButton fab;
     private Observer backgroundTaskCountObserver;
@@ -67,6 +65,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
     @Override
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        Log.d("flow", "AccountSummaryFragment.onCreate()");
         setHasOptionsMenu(true);
 
         if (backgroundTaskCountObserver == null) {
@@ -84,6 +83,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
     }
     public void onAttach(Context context) {
         super.onAttach(context);
+        Log.d("flow", "AccountSummaryFragment.onAttach()");
         mActivity = (MainActivity) context;
     }
     @Override
@@ -101,48 +101,51 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
 
         modelAdapter = new AccountSummaryAdapter();
 
+        mActivity.mAccountSummaryFragment = this;
         root = mActivity.findViewById(R.id.account_root);
         LinearLayoutManager llm = new LinearLayoutManager(mActivity);
         llm.setOrientation(RecyclerView.VERTICAL);
         root.setLayoutManager(llm);
         root.setAdapter(modelAdapter);
+        DividerItemDecoration did = new DividerItemDecoration(mActivity, DividerItemDecoration.VERTICAL);
+        root.addItemDecoration(did);
 
         fab = mActivity.findViewById(R.id.btn_add_transaction);
 
-        root.addOnItemTouchListener(new RecyclerItemListener(mActivity, root,
-                new RecyclerItemListener.RecyclerTouchListener() {
-                    @Override
-                    public void onClickItem(View v, int position) {
-                        Log.d("value", String.format("item %d clicked", position));
-                        if (modelAdapter.isSelectionActive()) {
-                            modelAdapter.selectItem(position);
-                        }
-                        else {
-                            List<LedgerAccount> accounts = Data.accounts.get();
-                            if (accounts != null) {
-                                LedgerAccount account = accounts.get(position);
-
-                                mActivity.showAccountTransactions(account);
-                            }
-                        }
-                    }
-
-                    @Override
-                    public void onLongClickItem(View v, int position) {
-                        Log.d("value", String.format("item %d long-clicked", position));
-                        modelAdapter.startSelection();
-                        if (optMenu != null) {
-                            optMenu.findItem(R.id.menu_acc_summary_cancel_selection)
-                                    .setVisible(true);
-                            optMenu.findItem(R.id.menu_acc_summary_confirm_selection)
-                                    .setVisible(true);
-                            optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(false);
-                        }
-                        {
-                            if (fab != null) fab.hide();
-                        }
-                    }
-                }));
+//        root.addOnItemTouchListener(new RecyclerItemListener(mActivity, root,
+//                new RecyclerItemListener.RecyclerTouchListener() {
+//                    @Override
+//                    public void onClickItem(View v, int position) {
+//                        Log.d("value", String.format("item %d clicked", position));
+//                        if (modelAdapter.isSelectionActive()) {
+//                            modelAdapter.selectItem(position);
+//                        }
+//                        else {
+//                            List<LedgerAccount> accounts = Data.accounts.get();
+//                            if (accounts != null) {
+//                                LedgerAccount account = accounts.get(position);
+//
+//                                mActivity.showAccountTransactions(account);
+//                            }
+//                        }
+//                    }
+//
+//                    @Override
+//                    public void onLongClickItem(View v, int position) {
+//                        Log.d("value", String.format("item %d long-clicked", position));
+//                        modelAdapter.startSelection();
+//                        if (optMenu != null) {
+//                            optMenu.findItem(R.id.menu_acc_summary_cancel_selection)
+//                                    .setVisible(true);
+//                            optMenu.findItem(R.id.menu_acc_summary_confirm_selection)
+//                                    .setVisible(true);
+//                            optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(false);
+//                        }
+//                        {
+//                            if (fab != null) fab.hide();
+//                        }
+//                    }
+//                }));
 
         mActivity.fabShouldShow();
         root.addOnScrollListener(new RecyclerView.OnScrollListener() {
@@ -155,8 +158,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
             }
         });
         swiper = mActivity.findViewById(R.id.account_swiper);
-        Colors.themeWatch.addObserver(
-                (o, arg) -> swiper.setColorSchemeColors(Colors.primary));
+        Colors.themeWatch.addObserver((o, arg) -> swiper.setColorSchemeColors(Colors.primary));
         swiper.setColorSchemeColors(Colors.primary);
         swiper.setOnRefreshListener(() -> {
             Log.d("ui", "refreshing accounts via swipe");
@@ -165,9 +167,6 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
 
         Data.accounts.addObserver(
                 (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
-        Data.profile.addObserver((o, arg) -> mActivity.runOnUiThread(
-                AccountSummaryViewModel::scheduleAccountListReload));
-        update_account_table();
     }
     private void update_account_table() {
         if (this.getContext() == null) return;