X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionFragment.java;h=e4ac7792eaa7579aa5ec756b909ef1913a9e8b53;hp=f212bc0902eda6c7efb3cabadf8486f95d722419;hb=217da55a224e2ae899d0b50604e2e54f882ec04f;hpb=c8a46620566a9027fe620cb16cf1aefa708085a3 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java index f212bc09..e4ac7792 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java @@ -1,5 +1,5 @@ /* - * 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 @@ -23,8 +23,10 @@ import android.renderscript.RSInvalidStateException; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -44,11 +46,10 @@ import net.ktnx.mobileledger.model.LedgerTransactionAccount; 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 @@ -57,6 +58,7 @@ import java.util.Date; */ // TODO: offer to undo account remove-on-swipe +// TODO: transaction-level comment public class NewTransactionFragment extends Fragment { private NewTransactionItemsAdapter listAdapter; @@ -72,12 +74,30 @@ public class NewTransactionFragment extends Fragment { @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; + }); + 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, @@ -96,6 +116,7 @@ public class NewTransactionFragment extends Fragment { list = activity.findViewById(R.id.new_transaction_accounts); viewModel = new ViewModelProvider(activity).get(NewTransactionModel.class); + viewModel.observeDataProfile(this); mProfile = Data.profile.getValue(); listAdapter = new NewTransactionItemsAdapter(viewModel, mProfile); list.setAdapter(listAdapter); @@ -119,7 +140,7 @@ public class NewTransactionFragment extends Fragment { } } }); - viewModel.checkTransactionSubmittable(listAdapter); +// viewModel.checkTransactionSubmittable(listAdapter); fab = activity.findViewById(R.id.fab); fab.setOnClickListener(v -> onFabPressed()); @@ -148,6 +169,21 @@ public class NewTransactionFragment extends Fragment { 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) { @@ -160,10 +196,11 @@ public class NewTransactionFragment extends Fragment { fab.setEnabled(false); 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++) {