]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix creation of a new profile after Room-y of Profile adoption
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 18 Apr 2021 09:42:54 +0000 (12:42 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 18 Apr 2021 09:42:54 +0000 (12:42 +0300)
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java

index 35f39358c46efa6d0634bea443c6a5bb01501af5..c14bc3f15c3bdd122aee8cbb45ec066b7015aa3d 100644 (file)
@@ -18,6 +18,7 @@
 package net.ktnx.mobileledger.model;
 
 import androidx.annotation.NonNull;
 package net.ktnx.mobileledger.model;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 import androidx.lifecycle.LifecycleOwner;
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
 import androidx.lifecycle.LifecycleOwner;
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
@@ -35,7 +36,6 @@ import java.text.ParsePosition;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
-import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import static net.ktnx.mobileledger.utils.Logger.debug;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import static net.ktnx.mobileledger.utils.Logger.debug;
@@ -45,7 +45,9 @@ public final class Data {
             new MutableLiveData<>(false);
     public static final MutableLiveData<RetrieveTransactionsTask.Progress> backgroundTaskProgress =
             new MutableLiveData<>();
             new MutableLiveData<>(false);
     public static final MutableLiveData<RetrieveTransactionsTask.Progress> backgroundTaskProgress =
             new MutableLiveData<>();
-    public static final LiveData<List<Profile>> profiles = DB.get().getProfileDAO().getAllOrdered();
+    public static final LiveData<List<Profile>> profiles = DB.get()
+                                                             .getProfileDAO()
+                                                             .getAllOrdered();
     public static final MutableLiveData<Currency.Position> currencySymbolPosition =
             new MutableLiveData<>();
     public static final MutableLiveData<Boolean> currencyGap = new MutableLiveData<>(true);
     public static final MutableLiveData<Currency.Position> currencySymbolPosition =
             new MutableLiveData<>();
     public static final MutableLiveData<Boolean> currencyGap = new MutableLiveData<>(true);
@@ -58,8 +60,7 @@ public final class Data {
     public static final MutableLiveData<String> lastTransactionsUpdateText =
             new MutableLiveData<>();
     public static final MutableLiveData<String> lastAccountsUpdateText = new MutableLiveData<>();
     public static final MutableLiveData<String> lastTransactionsUpdateText =
             new MutableLiveData<>();
     public static final MutableLiveData<String> lastAccountsUpdateText = new MutableLiveData<>();
-    private static final MutableLiveData<Profile> profile =
-            new InertMutableLiveData<>();
+    private static final MutableLiveData<Profile> profile = new InertMutableLiveData<>();
     private static final AtomicInteger backgroundTaskCount = new AtomicInteger(0);
     private static final Locker profilesLocker = new Locker();
     private static NumberFormat numberFormatter;
     private static final AtomicInteger backgroundTaskCount = new AtomicInteger(0);
     private static final Locker profilesLocker = new Locker();
     private static NumberFormat numberFormatter;
@@ -68,9 +69,9 @@ public final class Data {
         locale.setValue(Locale.getDefault());
     }
 
         locale.setValue(Locale.getDefault());
     }
 
-    @NonNull
+    @Nullable
     public static Profile getProfile() {
     public static Profile getProfile() {
-        return Objects.requireNonNull(profile.getValue());
+        return profile.getValue();
     }
     public static void backgroundTaskStarted() {
         int cnt = backgroundTaskCount.incrementAndGet();
     }
     public static void backgroundTaskStarted() {
         int cnt = backgroundTaskCount.incrementAndGet();
@@ -135,8 +136,7 @@ public final class Data {
     public static String formatNumber(float number) {
         return numberFormatter.format(number);
     }
     public static String formatNumber(float number) {
         return numberFormatter.format(number);
     }
-    public static void observeProfile(LifecycleOwner lifecycleOwner,
-                                      Observer<Profile> observer) {
+    public static void observeProfile(LifecycleOwner lifecycleOwner, Observer<Profile> observer) {
         profile.observe(lifecycleOwner, observer);
     }
     public static void removeProfileObservers(LifecycleOwner owner) {
         profile.observe(lifecycleOwner, observer);
     }
     public static void removeProfileObservers(LifecycleOwner owner) {
index d389dd8ab9a52cd55e4e56eb610b1ca2ab77524c..1b88f480254b5129bbd921ba8efdd65395dc0634 100644 (file)
@@ -65,9 +65,6 @@ public class ProfileDetailActivity extends CrashReportingActivity {
     protected void onCreate(Bundle savedInstanceState) {
         final long id = getIntent().getLongExtra(ProfileDetailFragment.ARG_ITEM_ID, -1);
 
     protected void onCreate(Bundle savedInstanceState) {
         final long id = getIntent().getLongExtra(ProfileDetailFragment.ARG_ITEM_ID, -1);
 
-        if (id == -1)
-            throw new RuntimeException("Invalid or missing profile ID");
-
         DB.get()
           .getProfileDAO()
           .getById(id)
         DB.get()
           .getProfileDAO()
           .getById(id)
index 688cd6d42f69deee4ab5d518d73b5445e0d284e6..d1cceb42f15ebed28dc5f446da7cc7323ac4a69e 100644 (file)
@@ -175,7 +175,8 @@ public class ProfilesRecyclerViewAdapter
             ProfileDetailActivity.start(view.getContext(), p);
         });
 
             ProfileDetailActivity.start(view.getContext(), p);
         });
 
-        final boolean sameProfile = currentProfile.getId() == profile.getId();
+        final boolean sameProfile =
+                currentProfile != null && currentProfile.getId() == profile.getId();
         holder.itemView.setBackground(
                 sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null);
         if (editingProfiles()) {
         holder.itemView.setBackground(
                 sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null);
         if (editingProfiles()) {