]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
drop unused code/comments
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / account_summary / AccountSummaryFragment.java
1 /*
2  * Copyright © 2019 Damyan Ivanov.
3  * This file is part of MoLe.
4  * MoLe is free software: you can distribute it and/or modify it
5  * under the term of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your opinion), any later version.
8  *
9  * MoLe is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License terms for details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
16  */
17
18 package net.ktnx.mobileledger.ui.account_summary;
19
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25
26 import androidx.annotation.NonNull;
27 import androidx.annotation.Nullable;
28 import androidx.recyclerview.widget.DividerItemDecoration;
29 import androidx.recyclerview.widget.LinearLayoutManager;
30 import androidx.recyclerview.widget.RecyclerView;
31
32 import net.ktnx.mobileledger.R;
33 import net.ktnx.mobileledger.model.Data;
34 import net.ktnx.mobileledger.ui.MobileLedgerListFragment;
35 import net.ktnx.mobileledger.ui.activity.MainActivity;
36 import net.ktnx.mobileledger.utils.Colors;
37
38 import org.jetbrains.annotations.NotNull;
39
40 import static net.ktnx.mobileledger.utils.Logger.debug;
41
42 public class AccountSummaryFragment extends MobileLedgerListFragment {
43     public AccountSummaryAdapter modelAdapter;
44     @Override
45     public void onCreate(@Nullable Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47         debug("flow", "AccountSummaryFragment.onCreate()");
48         setHasOptionsMenu(true);
49
50         Data.backgroundTasksRunning.observe(this.getViewLifecycleOwner(),
51                 this::onBackgroundTaskRunningChanged);
52     }
53     public void onAttach(@NotNull Context context) {
54         super.onAttach(context);
55         debug("flow", "AccountSummaryFragment.onAttach()");
56         mActivity = (MainActivity) context;
57     }
58     @Override
59     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
60                              @Nullable Bundle savedInstanceState) {
61         debug("flow", "AccountSummaryFragment.onCreateView()");
62         return inflater.inflate(R.layout.account_summary_fragment, container, false);
63     }
64
65     @Override
66
67     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
68         debug("flow", "AccountSummaryFragment.onActivityCreated()");
69         super.onActivityCreated(savedInstanceState);
70
71         modelAdapter = new AccountSummaryAdapter();
72
73         mActivity.mAccountSummaryFragment = this;
74         root = mActivity.findViewById(R.id.account_root);
75         LinearLayoutManager llm = new LinearLayoutManager(mActivity);
76         llm.setOrientation(RecyclerView.VERTICAL);
77         root.setLayoutManager(llm);
78         root.setAdapter(modelAdapter);
79         DividerItemDecoration did =
80                 new DividerItemDecoration(mActivity, DividerItemDecoration.VERTICAL);
81         root.addItemDecoration(did);
82
83         mActivity.fabShouldShow();
84
85         manageFabOnScroll();
86
87         swiper = mActivity.findViewById(R.id.account_swiper);
88         Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged);
89         swiper.setOnRefreshListener(() -> {
90             debug("ui", "refreshing accounts via swipe");
91             Data.scheduleTransactionListRetrieval(mActivity);
92         });
93
94         Data.accounts.addObserver(
95                 (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
96     }
97 /*
98     void stopSelection() {
99         modelAdapter.stopSelection();
100         if (optMenu != null) {
101             optMenu.findItem(R.id.menu_acc_summary_cancel_selection).setVisible(false);
102             optMenu.findItem(R.id.menu_acc_summary_confirm_selection).setVisible(false);
103             optMenu.findItem(R.id.menu_acc_summary_only_starred).setVisible(true);
104         }
105         {
106             if (fab != null) fab.show();
107         }
108     }
109     public void onCancelAccSelection(MenuItem item) {
110         stopSelection();
111     }
112     public void onConfirmAccSelection(MenuItem item) {
113         AccountSummaryViewModel.commitSelections(mActivity);
114         stopSelection();
115     }
116     @Override
117     public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflater) {
118         // Inflate the menu; this adds items to the action bar if it is present.
119         inflater.inflate(R.menu.account_summary, menu);
120         optMenu = menu;
121
122         mShowOnlyStarred = menu.findItem(R.id.menu_acc_summary_only_starred);
123         if (mShowOnlyStarred == null) throw new AssertionError();
124         MenuItem mCancelSelection = menu.findItem(R.id.menu_acc_summary_cancel_selection);
125         if (mCancelSelection == null) throw new AssertionError();
126         MenuItem mConfirmSelection = menu.findItem(R.id.menu_acc_summary_confirm_selection);
127         if (mConfirmSelection == null) throw new AssertionError();
128
129         Data.optShowOnlyStarred.addObserver((o, arg) -> {
130             boolean newValue = Data.optShowOnlyStarred.get();
131             debug("pref", String.format("pref change came (%s)", newValue ? "true" : "false"));
132             mShowOnlyStarred.setChecked(newValue);
133             update_account_table();
134         });
135
136         mShowOnlyStarred.setChecked(Data.optShowOnlyStarred.get());
137
138         debug("menu", "Accounts: onCreateOptionsMenu called");
139
140         mShowOnlyStarred.setOnMenuItemClickListener(item -> {
141             SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mActivity);
142             SharedPreferences.Editor editor = pref.edit();
143             boolean flag = item.isChecked();
144             editor.putBoolean(PREF_KEY_SHOW_ONLY_STARRED_ACCOUNTS, !flag);
145             debug("pref",
146                     "Setting show only starred accounts pref to " + (flag ? "false" : "true"));
147             editor.apply();
148
149             return true;
150         });
151
152         mCancelSelection.setOnMenuItemClickListener(item -> {
153             stopSelection();
154             return true;
155         });
156
157         mConfirmSelection.setOnMenuItemClickListener(item -> {
158             AccountSummaryViewModel.commitSelections(mActivity);
159             stopSelection();
160
161             return true;
162         });
163     }
164 */
165 }