proile editor: fix passing of initial theme hue to the hue ring
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 15 May 2020 11:40:35 +0000 (14:40 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 16 May 2020 10:39:12 +0000 (13:39 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java

index 7daa3d3..1bc17ec 100644 (file)
@@ -23,13 +23,17 @@ import android.view.MenuItem;
 
 import androidx.appcompat.app.ActionBar;
 import androidx.appcompat.widget.Toolbar;
+import androidx.lifecycle.ViewModelProvider;
 
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment;
+import net.ktnx.mobileledger.ui.profiles.ProfileDetailModel;
 import net.ktnx.mobileledger.utils.Colors;
 
+import org.jetbrains.annotations.NotNull;
+
 import java.util.ArrayList;
 import java.util.Locale;
 
@@ -44,6 +48,10 @@ import static net.ktnx.mobileledger.utils.Logger.debug;
 public class ProfileDetailActivity extends CrashReportingActivity {
     private MobileLedgerProfile profile = null;
     private ProfileDetailFragment mFragment;
+    @NotNull
+    private ProfileDetailModel getModel() {
+        return new ViewModelProvider(this).get(ProfileDetailModel.class);
+    }
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         final int index = getIntent().getIntExtra(ProfileDetailFragment.ARG_ITEM_ID, -1);
@@ -70,10 +78,13 @@ public class ProfileDetailActivity extends CrashReportingActivity {
             themeHue = Colors.getNewProfileThemeHue(Data.profiles.getValue());
         }
         Colors.setupTheme(this, themeHue);
+        final ProfileDetailModel model = getModel();
+        model.initialThemeHue = themeHue;
         setContentView(R.layout.activity_profile_detail);
         Toolbar toolbar = findViewById(R.id.detail_toolbar);
         setSupportActionBar(toolbar);
 
+
         // Show the Up button in the action bar.
         ActionBar actionBar = getSupportActionBar();
         if (actionBar != null) {
index f6323d5..6875840 100644 (file)
@@ -63,9 +63,7 @@ import org.jetbrains.annotations.NotNull;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Objects;
 
-import static net.ktnx.mobileledger.utils.Colors.profileThemeId;
 import static net.ktnx.mobileledger.utils.Logger.debug;
 
 /**
@@ -393,8 +391,8 @@ public class ProfileDetailFragment extends Fragment {
         });
 
         huePickerView.setOnClickListener(v -> {
-            HueRingDialog d = new HueRingDialog(
-                    Objects.requireNonNull(ProfileDetailFragment.this.getContext()), profileThemeId,
+            HueRingDialog d = new HueRingDialog(ProfileDetailFragment.this.requireContext(),
+                    model.initialThemeHue,
                     (Integer) v.getTag());
             d.show();
             d.setColorSelectedListener(model::setThemeId);
@@ -426,7 +424,7 @@ public class ProfileDetailFragment extends Fragment {
     }
     @NotNull
     private ProfileDetailModel getModel() {
-        return new ViewModelProvider(this).get(ProfileDetailModel.class);
+        return new ViewModelProvider(requireActivity()).get(ProfileDetailModel.class);
     }
     private void onSaveFabClicked() {
         if (!checkValidity())
index 2a655dc..57c9921 100644 (file)
@@ -25,6 +25,7 @@ import androidx.lifecycle.ViewModel;
 import net.ktnx.mobileledger.async.SendTransactionTask;
 import net.ktnx.mobileledger.model.Currency;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.utils.Colors;
 import net.ktnx.mobileledger.utils.Misc;
 
 public class ProfileDetailModel extends ViewModel {
@@ -44,6 +45,7 @@ public class ProfileDetailModel extends ViewModel {
     private final MutableLiveData<String> authPassword = new MutableLiveData<>(null);
     private final MutableLiveData<String> preferredAccountsFilter = new MutableLiveData<>(null);
     private final MutableLiveData<Integer> themeId = new MutableLiveData<>(-1);
+    public int initialThemeHue = Colors.DEFAULT_HUE_DEG;
     public ProfileDetailModel() {
     }
     String getProfileName() {