]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
proile editor: fix passing of initial theme hue to the hue ring
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailFragment.java
index aba3b0f2c4f9b9829a996b8bfca9a988046f10f1..68758402379ee5af316be287e0041861a2514618 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;
 
 /**
@@ -256,17 +254,23 @@ public class ProfileDetailFragment extends Fragment {
                 (buttonView, isChecked) -> model.setShowCommodityByDefault(isChecked));
         model.observeShowCommodityByDefault(viewLifecycleOwner, showCommodityByDefault::setChecked);
 
+        View postingSubItems = context.findViewById(R.id.posting_sub_items);
+
         Switch postingPermitted = context.findViewById(R.id.profile_permit_posting);
         model.observePostingPermitted(viewLifecycleOwner, isChecked -> {
             postingPermitted.setChecked(isChecked);
-            defaultCommodityLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
-            showCommodityByDefault.setVisibility(isChecked ? View.VISIBLE : View.GONE);
-            preferredAccountsFilterLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
-            futureDatesLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+            postingSubItems.setVisibility(isChecked ? View.VISIBLE : View.GONE);
         });
         postingPermitted.setOnCheckedChangeListener(
                 ((buttonView, isChecked) -> model.setPostingPermitted(isChecked)));
 
+        Switch showCommentsByDefault = context.findViewById(R.id.profile_show_comments);
+        model.observeShowCommentsByDefault(viewLifecycleOwner, isChecked -> {
+            showCommentsByDefault.setChecked(isChecked);
+        });
+        showCommentsByDefault.setOnCheckedChangeListener(
+                ((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
+
         defaultCommodity = context.findViewById(R.id.default_commodity_text);
 
         futureDatesLayout = context.findViewById(R.id.future_dates_layout);
@@ -387,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);
@@ -420,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())