X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FNewTransactionFragment.java;h=54c55fa54863be0e11c152340bd0bcc051fdead8;hb=33b9d81eee0efad2fe1a277d5e380589b28d00a8;hp=e9d2e33134aff3fabb19a60d12f47da06656290b;hpb=6272fc07219887c4549f39777adb4ffbf389a9b0;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 e9d2e331..54c55fa5 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 @@ -30,7 +30,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; -import androidx.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -93,13 +93,12 @@ public class NewTransactionFragment extends Fragment { "getActivity() returned null within onActivityCreated()"); list = activity.findViewById(R.id.new_transaction_accounts); - viewModel = ViewModelProviders.of(activity) - .get(NewTransactionModel.class); + viewModel = new ViewModelProvider(activity).get(NewTransactionModel.class); mProfile = Data.profile.getValue(); listAdapter = new NewTransactionItemsAdapter(viewModel, mProfile); list.setAdapter(listAdapter); list.setLayoutManager(new LinearLayoutManager(activity)); - Data.profile.observe(this, profile -> { + Data.profile.observe(getViewLifecycleOwner(), profile -> { mProfile = profile; listAdapter.setProfile(profile); }); @@ -143,7 +142,7 @@ public class NewTransactionFragment extends Fragment { }).attachToRecyclerView(list); viewModel.isSubmittable() - .observe(this, isSubmittable -> { + .observe(getViewLifecycleOwner(), isSubmittable -> { if (isSubmittable) { if (fab != null) { fab.show(); @@ -205,7 +204,8 @@ public class NewTransactionFragment extends Fragment { LedgerTransactionAccount emptyAmountAccount = null; float emptyAmountAccountBalance = 0; for (int i = 0; i < viewModel.getAccountCount(); i++) { - LedgerTransactionAccount acc = viewModel.getAccount(i); + LedgerTransactionAccount acc = + new LedgerTransactionAccount(viewModel.getAccount(i)); if (acc.getAccountName() .trim() .isEmpty())