]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java
NT TODO: undo account removal after swipe
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / NewTransactionFragment.java
index e9d2e33134aff3fabb19a60d12f47da06656290b..f9e8a2637de27ff5195044249bc0604c5186f5fa 100644 (file)
@@ -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;
@@ -56,6 +56,9 @@ import java.util.Date;
  * {@link OnNewTransactionFragmentInteractionListener} interface
  * to handle interaction events.
  */
+
+// TODO: offer to undo account remove-on-swipe
+
 public class NewTransactionFragment extends Fragment {
     private NewTransactionItemsAdapter listAdapter;
     private NewTransactionModel viewModel;
@@ -93,13 +96,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 +145,7 @@ public class NewTransactionFragment extends Fragment {
         }).attachToRecyclerView(list);
 
         viewModel.isSubmittable()
-                 .observe(this, isSubmittable -> {
+                 .observe(getViewLifecycleOwner(), isSubmittable -> {
                      if (isSubmittable) {
                          if (fab != null) {
                              fab.show();
@@ -167,7 +169,6 @@ public class NewTransactionFragment extends Fragment {
         if (args != null) {
             String error = args.getString("error");
             if (error != null) {
-                // TODO display error
                 Logger.debug("new-trans-f", String.format("Got error: %s", error));
                 Snackbar.make(list, error, Snackbar.LENGTH_LONG)
                         .show();
@@ -205,7 +206,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())