- 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_7:
- futureDates = MobileLedgerProfile.FutureDates.OneWeek;
- break;
- case R.id.menu_future_dates_14:
- futureDates = MobileLedgerProfile.FutureDates.TwoWeeks;
- break;
- 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();
- });
- apiVersionText = context.findViewById(R.id.api_version_text);
- context.findViewById(R.id.api_version_layout)
- .setOnClickListener(v -> {
- MenuInflater mi = new MenuInflater(context);
- PopupMenu menu = new PopupMenu(context, v);
- menu.inflate(R.menu.api_version);
- menu.setOnMenuItemClickListener(item -> {
- switch (item.getItemId()) {
- case R.id.api_version_menu_html:
- apiVersion = SendTransactionTask.API.html;
- break;
- case R.id.api_version_menu_post_1_14:
- apiVersion = SendTransactionTask.API.post_1_14;
- break;
- case R.id.api_version_menu_pre_1_15:
- apiVersion = SendTransactionTask.API.pre_1_15;
- break;
- case R.id.api_version_menu_auto:
- default:
- apiVersion = SendTransactionTask.API.auto;
- }
- apiVersionText.setText(apiVersion.getDescription(getResources()));
- return true;
- });
- menu.show();
- });
- authParams = context.findViewById(R.id.auth_params);
- useAuthentication = context.findViewById(R.id.enable_http_auth);
- userName = context.findViewById(R.id.auth_user_name);
- userNameLayout = context.findViewById(R.id.auth_user_name_layout);
- password = context.findViewById(R.id.password);
- passwordLayout = context.findViewById(R.id.password_layout);
- huePickerView = context.findViewById(R.id.btn_pick_ring_color);
- preferredAccountsFilter = context.findViewById(R.id.preferred_accounts_filter_filter);
- preferredAccountsFilterLayout =
- context.findViewById(R.id.preferred_accounts_accounts_filter_layout);
- insecureWarningText = context.findViewById(R.id.insecure_scheme_text);
-
- useAuthentication.setOnCheckedChangeListener((buttonView, isChecked) -> {
- debug("profiles", isChecked ? "auth enabled " : "auth disabled");
- authParams.setVisibility(isChecked ? View.VISIBLE : View.GONE);
- if (isChecked)
- userName.requestFocus();
+
+ 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);