X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfileDetailFragment.java;h=13b6a8bae93ef11a42e9ab262a9b60d0103bc684;hb=0a73337c99e2074aa7e7228204289896342ec636;hp=aba3b0f2c4f9b9829a996b8bfca9a988046f10f1;hpb=8ee42b51c43efbd0ff6fa0fec257132d4421f53d;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index aba3b0f2..13b6a8ba 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2020 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -23,12 +23,10 @@ import android.graphics.Typeface; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.PopupMenu; import android.widget.Switch; @@ -63,9 +61,8 @@ import org.jetbrains.annotations.NotNull; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Objects; +import java.util.UUID; -import static net.ktnx.mobileledger.utils.Colors.profileThemeId; import static net.ktnx.mobileledger.utils.Logger.debug; /** @@ -111,6 +108,7 @@ public class ProfileDetailFragment extends Fragment { * fragment (e.g. upon screen orientation changes). */ public ProfileDetailFragment() { + super(R.layout.profile_detail); } @Override public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflater) { @@ -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,9 +391,8 @@ public class ProfileDetailFragment extends Fragment { }); huePickerView.setOnClickListener(v -> { - HueRingDialog d = new HueRingDialog( - Objects.requireNonNull(ProfileDetailFragment.this.getContext()), profileThemeId, - (Integer) v.getTag()); + HueRingDialog d = new HueRingDialog(ProfileDetailFragment.this.requireContext(), + model.initialThemeHue, (Integer) v.getTag()); d.show(); d.setColorSelectedListener(model::setThemeId); }); @@ -420,7 +423,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()) @@ -436,7 +439,7 @@ public class ProfileDetailFragment extends Fragment { triggerProfileChange(); } else { - mProfile = new MobileLedgerProfile(); + mProfile = new MobileLedgerProfile(String.valueOf(UUID.randomUUID())); model.updateProfile(mProfile); mProfile.storeInDB(); final ArrayList profiles = Data.profiles.getValue(); @@ -456,12 +459,6 @@ public class ProfileDetailFragment extends Fragment { if (activity != null) activity.finish(); } - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - - return inflater.inflate(R.layout.profile_detail, container, false); - } private boolean checkUrlValidity() { boolean valid = true; @@ -589,7 +586,7 @@ public class ProfileDetailFragment extends Fragment { private void setDefaultCommodity(@NonNull @NotNull String name) { defaultCommoditySet = true; defaultCommodity.setText(name); - defaultCommodity.setTypeface(defaultCommodity.getTypeface(), Typeface.BOLD); + defaultCommodity.setTypeface(Typeface.DEFAULT); } interface TextChangeSyncProc { void onTextChanged(String text);