+ 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 -> {
+ MenuInflater mi = new MenuInflater(context);
+ PopupMenu menu = new PopupMenu(context, v);
+ menu.inflate(R.menu.future_dates);
+ menu.setOnMenuItemClickListener(item -> {
+ model.setFutureDates(futureDatesSettingFromMenuItemId(item.getItemId()));
+ return true;
+ });
+ menu.show();
+ });
+ model.observeFutureDates(viewLifecycleOwner,
+ v -> binding.futureDatesText.setText(v.getText(getResources())));
+
+ model.observeApiVersion(viewLifecycleOwner,
+ apiVer -> binding.apiVersionText.setText(apiVer.getDescription(getResources())));
+ binding.apiVersionLabel.setOnClickListener(this::chooseAPIVersion);
+ binding.apiVersionText.setOnClickListener(this::chooseAPIVersion);
+
+ binding.serverVersionLabel.setOnClickListener(v -> model.triggerVersionDetection());
+ model.observeDetectedVersion(viewLifecycleOwner, ver -> {
+ if (ver == null)
+ binding.detectedServerVersionText.setText(context.getResources()
+ .getString(
+ R.string.server_version_unknown_label));
+ else if (ver.isPre_1_20_1())
+ binding.detectedServerVersionText.setText(context.getResources()
+ .getString(
+ R.string.detected_server_pre_1_20_1));
+ else
+ binding.detectedServerVersionText.setText(ver.toString());
+ });
+ binding.detectedServerVersionText.setOnClickListener(v -> model.triggerVersionDetection());
+ binding.serverVersionDetectButton.setOnClickListener(v -> model.triggerVersionDetection());
+ model.observeDetectingHledgerVersion(viewLifecycleOwner,
+ running -> binding.serverVersionDetectButton.setVisibility(
+ running ? View.VISIBLE : View.INVISIBLE));
+
+ binding.enableHttpAuth.setOnCheckedChangeListener((buttonView, isChecked) -> {
+ boolean wasOn = model.getUseAuthentication();
+ model.setUseAuthentication(isChecked);
+ if (!wasOn && isChecked)
+ binding.authUserName.requestFocus();
+ });
+ model.observeUseAuthentication(viewLifecycleOwner, isChecked -> {
+ binding.enableHttpAuth.setChecked(isChecked);
+ binding.authParams.setVisibility(isChecked ? View.VISIBLE : View.GONE);
+ checkInsecureSchemeWithAuth();
+ });
+
+ model.observeUserName(viewLifecycleOwner, text -> {
+ if (!Misc.equalStrings(text, Misc.nullIsEmpty(binding.authUserName.getText())))
+ binding.authUserName.setText(text);
+ });
+ hookTextChangeSyncRoutine(binding.authUserName, model::setAuthUserName);
+
+ model.observePassword(viewLifecycleOwner, text -> {
+ if (!Misc.equalStrings(text, Misc.nullIsEmpty(binding.password.getText())))
+ binding.password.setText(text);
+ });
+ hookTextChangeSyncRoutine(binding.password, model::setAuthPassword);
+
+ model.observeThemeId(viewLifecycleOwner, themeId -> {
+ final int hue = (themeId == -1) ? Colors.DEFAULT_HUE_DEG : themeId;
+ final int profileColor = Colors.getPrimaryColorForHue(hue);
+ binding.btnPickRingColor.setBackgroundColor(profileColor);
+ binding.btnPickRingColor.setTag(hue);
+ });
+
+ model.observePreferredAccountsFilter(viewLifecycleOwner, text -> {
+ if (!Misc.equalStrings(text,
+ Misc.nullIsEmpty(binding.preferredAccountsFilter.getText())))
+ binding.preferredAccountsFilter.setText(text);
+ });
+ hookTextChangeSyncRoutine(binding.preferredAccountsFilter,
+ model::setPreferredAccountsFilter);
+
+ hookClearErrorOnFocusListener(binding.profileName, binding.profileNameLayout);
+ hookClearErrorOnFocusListener(binding.url, binding.urlLayout);
+ hookClearErrorOnFocusListener(binding.authUserName, binding.authUserNameLayout);
+ hookClearErrorOnFocusListener(binding.password, binding.passwordLayout);
+
+ binding.url.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+ @Override
+ public void afterTextChanged(Editable s) {
+ checkInsecureSchemeWithAuth();