+ userName = context.findViewById(R.id.auth_user_name);
+ model.observeUserName(viewLifecycleOwner, text -> {
+ if (!Misc.equalStrings(text, userName.getText()))
+ userName.setText(text);
+ });
+ hookTextChangeSyncRoutine(userName, model::setAuthUserName);
+ userNameLayout = context.findViewById(R.id.auth_user_name_layout);
+
+ password = context.findViewById(R.id.password);
+ model.observePassword(viewLifecycleOwner, text -> {
+ if (!Misc.equalStrings(text, password.getText()))
+ password.setText(text);
+ });
+ hookTextChangeSyncRoutine(password, model::setAuthPassword);
+ passwordLayout = context.findViewById(R.id.password_layout);
+
+ huePickerView = context.findViewById(R.id.btn_pick_ring_color);
+ model.observeThemeId(viewLifecycleOwner, themeId -> {
+ final int hue = (themeId == -1) ? Colors.DEFAULT_HUE_DEG : themeId;
+ final int profileColor = Colors.getPrimaryColorForHue(hue);
+ huePickerView.setBackgroundColor(profileColor);
+ huePickerView.setTag(hue);
+ });
+
+ preferredAccountsFilter = context.findViewById(R.id.preferred_accounts_filter_filter);
+ model.observePreferredAccountsFilter(viewLifecycleOwner, text -> {
+ if (!Misc.equalStrings(text, preferredAccountsFilter.getText()))
+ preferredAccountsFilter.setText(text);
+ });
+ hookTextChangeSyncRoutine(preferredAccountsFilter, model::setPreferredAccountsFilter);
+ preferredAccountsFilterLayout =
+ context.findViewById(R.id.preferred_accounts_accounts_filter_layout);
+
+ insecureWarningText = context.findViewById(R.id.insecure_scheme_text);
+
+ hookClearErrorOnFocusListener(profileName, profileNameLayout);
+ hookClearErrorOnFocusListener(url, urlLayout);
+ hookClearErrorOnFocusListener(userName, userNameLayout);
+ hookClearErrorOnFocusListener(password, passwordLayout);
+
+ if (savedInstanceState == null) {
+ model.setValuesFromProfile(mProfile, getArguments().getInt(ARG_HUE, -1));
+ }
+ checkInsecureSchemeWithAuth();
+
+ 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();
+ }
+ });
+
+ huePickerView.setOnClickListener(v -> {
+ HueRingDialog d = new HueRingDialog(ProfileDetailFragment.this.requireContext(),
+ model.initialThemeHue,
+ (Integer) v.getTag());
+ d.show();
+ d.setColorSelectedListener(model::setThemeId);
+ });
+
+ profileName.requestFocus();
+ }
+ private MobileLedgerProfile.FutureDates futureDatesSettingFromMenuItemId(int itemId) {
+ switch (itemId) {
+ case R.id.menu_future_dates_7:
+ return MobileLedgerProfile.FutureDates.OneWeek;
+ case R.id.menu_future_dates_14:
+ return MobileLedgerProfile.FutureDates.TwoWeeks;
+ case R.id.menu_future_dates_30:
+ return MobileLedgerProfile.FutureDates.OneMonth;
+ case R.id.menu_future_dates_60:
+ return MobileLedgerProfile.FutureDates.TwoMonths;
+ case R.id.menu_future_dates_90:
+ return MobileLedgerProfile.FutureDates.ThreeMonths;
+ case R.id.menu_future_dates_180:
+ return MobileLedgerProfile.FutureDates.SixMonths;
+ case R.id.menu_future_dates_365:
+ return MobileLedgerProfile.FutureDates.OneYear;
+ case R.id.menu_future_dates_all:
+ return MobileLedgerProfile.FutureDates.All;
+ default:
+ return MobileLedgerProfile.FutureDates.None;
+ }
+ }
+ @NotNull
+ private ProfileDetailModel getModel() {
+ return new ViewModelProvider(requireActivity()).get(ProfileDetailModel.class);
+ }
+ private void onSaveFabClicked() {
+ if (!checkValidity())
+ return;
+
+ ProfileDetailModel model = getModel();
+
+ if (mProfile != null) {
+ model.updateProfile(mProfile);
+// debug("profiles", String.format("Selected item is %d", mProfile.getThemeHue()));
+ mProfile.storeInDB();
+ debug("profiles", "profile stored in DB");
+ triggerProfileChange();