X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionFragment.java;h=e705d1c102df4a01348d77b57ac118806e4fc13d;hb=32479d6cca6ffb6b74edbd4b884b9062d42fcbff;hp=39f53a97eb2f9a0cc074d488184442b0a27d4139;hpb=7b3937e47b0b270651ad3083e467bfaaf62e9dc8;p=mobile-ledger.git 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 39f53a97..e705d1c1 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 @@ -46,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 @@ -64,7 +63,6 @@ import java.util.Date; public class NewTransactionFragment extends Fragment { private NewTransactionItemsAdapter listAdapter; private NewTransactionModel viewModel; - private RecyclerView list; private FloatingActionButton fab; private OnNewTransactionFragmentInteractionListener mListener; private MobileLedgerProfile mProfile; @@ -108,21 +106,23 @@ public class NewTransactionFragment extends Fragment { } @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); + public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); FragmentActivity activity = getActivity(); if (activity == null) throw new RSInvalidStateException( "getActivity() returned null within onActivityCreated()"); - list = activity.findViewById(R.id.new_transaction_accounts); viewModel = new ViewModelProvider(activity).get(NewTransactionModel.class); viewModel.observeDataProfile(this); - mProfile = Data.profile.getValue(); + 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); }); @@ -132,7 +132,6 @@ public class NewTransactionFragment extends Fragment { if (isSubmittable) { if (fab != null) { fab.show(); - fab.setEnabled(true); } } else { @@ -180,7 +179,7 @@ public class NewTransactionFragment extends Fragment { // p.setVisibility(View.VISIBLE); // // }, 10); - p.setVisibility(View.VISIBLE); + p.setVisibility(View.VISIBLE); } else p.setVisibility(View.INVISIBLE); @@ -194,13 +193,14 @@ public class NewTransactionFragment extends Fragment { 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++) {