- profileName = context.findViewById(R.id.profile_name);
- profileNameLayout = context.findViewById(R.id.profile_name_layout);
- url = context.findViewById(R.id.url);
- urlLayout = context.findViewById(R.id.url_layout);
- postingPermitted = context.findViewById(R.id.profile_permit_posting);
- futureDatesLayout = context.findViewById(R.id.future_dates_layout);
- futureDatesText = context.findViewById(R.id.future_dates_text);
- context.findViewById(R.id.future_dates_layout)
- .setOnClickListener(v -> {
- MenuInflater mi = new MenuInflater(context);
- PopupMenu menu = new PopupMenu(context, v);
- menu.inflate(R.menu.future_dates);
- menu.setOnMenuItemClickListener(item -> {
- switch (item.getItemId()) {
- case R.id.menu_future_dates_30:
- futureDates = MobileLedgerProfile.FutureDates.OneMonth;
- break;
- case R.id.menu_future_dates_60:
- futureDates = MobileLedgerProfile.FutureDates.TwoMonths;
- break;
- case R.id.menu_future_dates_90:
- futureDates = MobileLedgerProfile.FutureDates.ThreeMonths;
- break;
- case R.id.menu_future_dates_180:
- futureDates = MobileLedgerProfile.FutureDates.SixMonths;
- break;
- case R.id.menu_future_dates_365:
- futureDates = MobileLedgerProfile.FutureDates.OneYear;
- break;
- case R.id.menu_future_dates_all:
- futureDates = MobileLedgerProfile.FutureDates.All;
- break;
- default:
- futureDates = MobileLedgerProfile.FutureDates.None;
- }
- futureDatesText.setText(futureDates.getText(getResources()));
- return true;
- });
- menu.show();
- });
- apiVersionLayout = context.findViewById(R.id.api_version_layout);
- apiVersionText = context.findViewById(R.id.api_version_text);
- apiVersionLayout.setOnClickListener(v -> {
+
+ hookTextChangeSyncRoutine(binding.profileName, model::setProfileName);
+ model.observeProfileName(viewLifecycleOwner, pn -> {
+ if (!Misc.equalStrings(pn, Misc.nullIsEmpty(binding.profileName.getText())))
+ binding.profileName.setText(pn);
+ });
+
+ hookTextChangeSyncRoutine(binding.url, model::setUrl);
+ model.observeUrl(viewLifecycleOwner, u -> {
+ if (!Misc.equalStrings(u, Misc.nullIsEmpty(binding.url.getText())))
+ binding.url.setText(u);
+ });
+
+ binding.defaultCommodityLayout.setOnClickListener(v -> {
+ CurrencySelectorFragment cpf = CurrencySelectorFragment.newInstance(
+ CurrencySelectorFragment.DEFAULT_COLUMN_COUNT, false);
+ cpf.setOnCurrencySelectedListener(model::setDefaultCommodity);
+ final AppCompatActivity activity = (AppCompatActivity) v.getContext();
+ cpf.show(activity.getSupportFragmentManager(), "currency-selector");
+ });
+
+ binding.profileShowCommodity.setOnCheckedChangeListener(
+ (buttonView, isChecked) -> model.setShowCommodityByDefault(isChecked));
+ model.observeShowCommodityByDefault(viewLifecycleOwner,
+ binding.profileShowCommodity::setChecked);
+
+ model.observePostingPermitted(viewLifecycleOwner, isChecked -> {
+ binding.profilePermitPosting.setChecked(isChecked);
+ binding.postingSubItems.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+ });
+ binding.profilePermitPosting.setOnCheckedChangeListener(
+ ((buttonView, isChecked) -> model.setPostingPermitted(isChecked)));
+
+ model.observeShowCommentsByDefault(viewLifecycleOwner,
+ binding.profileShowComments::setChecked);
+ binding.profileShowComments.setOnCheckedChangeListener(
+ ((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
+
+ binding.futureDatesLayout.setOnClickListener(v -> {