/*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
* This file is part of MoLe.
* MoLe is free software: you can distribute it and/or modify it
* under the term of the GNU General Public License as published by
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.Misc;
+import net.ktnx.mobileledger.utils.SimpleDate;
import org.jetbrains.annotations.NotNull;
-import java.util.Date;
-
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
*/
// TODO: offer to undo account remove-on-swipe
+// TODO: transaction-level comment
public class NewTransactionFragment extends Fragment {
private NewTransactionItemsAdapter listAdapter;
private NewTransactionModel viewModel;
- private RecyclerView list;
private FloatingActionButton fab;
private OnNewTransactionFragmentInteractionListener mListener;
private MobileLedgerProfile mProfile;
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
+ final FragmentActivity activity = getActivity();
+
inflater.inflate(R.menu.new_transaction_fragment, menu);
menu.findItem(R.id.action_reset_new_transaction_activity)
.setOnMenuItemClickListener(item -> {
listAdapter.reset();
return true;
});
+
final MenuItem toggleCurrencyItem = menu.findItem(R.id.toggle_currency);
toggleCurrencyItem.setOnMenuItemClickListener(item -> {
viewModel.toggleCurrencyVisible();
return true;
});
- final FragmentActivity activity = getActivity();
if (activity != null)
viewModel.showCurrency.observe(activity, toggleCurrencyItem::setChecked);
+
+ final MenuItem toggleCommentsItem = menu.findItem(R.id.toggle_comments);
+ toggleCommentsItem.setOnMenuItemClickListener(item -> {
+ viewModel.toggleShowComments();
+ return true;
+ });
+ if (activity != null)
+ viewModel.showComments.observe(activity, toggleCommentsItem::setChecked);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
throw new RSInvalidStateException(
"getActivity() returned null within onActivityCreated()");
- list = activity.findViewById(R.id.new_transaction_accounts);
viewModel = new ViewModelProvider(activity).get(NewTransactionModel.class);
- mProfile = Data.profile.getValue();
+ viewModel.observeDataProfile(this);
+ mProfile = Data.getProfile();
listAdapter = new NewTransactionItemsAdapter(viewModel, mProfile);
+
+ RecyclerView list = activity.findViewById(R.id.new_transaction_accounts);
list.setAdapter(listAdapter);
list.setLayoutManager(new LinearLayoutManager(activity));
- Data.profile.observe(getViewLifecycleOwner(), profile -> {
+
+ Data.observeProfile(getViewLifecycleOwner(), profile -> {
mProfile = profile;
listAdapter.setProfile(profile);
});
if (isSubmittable) {
if (fab != null) {
fab.show();
- fab.setEnabled(true);
}
}
else {
else {
viewModel.setFocusedItem(focused);
}
+
+ ProgressBar p = activity.findViewById(R.id.progressBar);
+ viewModel.observeBusyFlag(getViewLifecycleOwner(), isBusy -> {
+ if (isBusy) {
+// Handler h = new Handler();
+// h.postDelayed(() -> {
+// if (viewModel.getBusyFlag())
+// p.setVisibility(View.VISIBLE);
+//
+// }, 10);
+ p.setVisibility(View.VISIBLE);
+ }
+ else
+ p.setVisibility(View.INVISIBLE);
+ });
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putInt("focused", focusedItem);
}
private void onFabPressed() {
- fab.setEnabled(false);
+ fab.hide();
Misc.hideSoftKeyboard(this);
if (mListener != null) {
- Date date = viewModel.getDate();
+ SimpleDate date = viewModel.getDate();
LedgerTransaction tr =
new LedgerTransaction(null, date, viewModel.getDescription(), mProfile);
+ tr.setComment(viewModel.getComment());
LedgerTransactionAccount emptyAmountAccount = null;
float emptyAmountAccountBalance = 0;
for (int i = 0; i < viewModel.getAccountCount(); i++) {