- }
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- final int primaryColor;
- final int degrees =
- Integer.valueOf((String) (parent.getAdapter().getItem(position)));
- if (degrees < 0) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (getActivity() != null) primaryColor = getResources()
- .getColor(R.color.colorPrimary, getActivity().getTheme());
- else primaryColor = Colors.getPrimaryColorForHue(Colors.DEFAULT_HUE_DEG);
- }
- else {
- primaryColor = getResources().getColor(R.color.colorPrimary);
- }
- }
- else primaryColor = Colors.getPrimaryColorForHue(degrees);
-
- if (colorSpinner != null) {
- colorSpinner.setBackgroundColor(primaryColor);
-// for (int i = 0; i < colorSpinner.getChildCount(); i++) {
-// View v = colorSpinner.getChildAt(i);
-//
-// if (v instanceof TextView) {
-// ((TextView) v).setTextColor(Color.TRANSPARENT);
-// }
-// }
- }
- }
+ profileName = context.findViewById(R.id.profile_name);
+ hookTextChangeSyncRoutine(profileName, model::setProfileName);
+ model.observeProfileName(viewLifecycleOwner, pn -> {
+ if (!Misc.equalStrings(pn, profileName.getText()))
+ profileName.setText(pn);
+ });
+
+ profileNameLayout = context.findViewById(R.id.profile_name_layout);
+
+ url = context.findViewById(R.id.url);
+ hookTextChangeSyncRoutine(url, model::setUrl);
+ model.observeUrl(viewLifecycleOwner, u -> {
+ if (!Misc.equalStrings(u, url.getText()))
+ url.setText(u);
+ });
+
+ urlLayout = context.findViewById(R.id.url_layout);
+
+ context.findViewById(R.id.default_commodity_layout)
+ .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");
+ });
+
+ Switch showCommodityByDefault = context.findViewById(R.id.profile_show_commodity);
+ showCommodityByDefault.setOnCheckedChangeListener(
+ (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);
+ 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, showCommentsByDefault::setChecked);
+ showCommentsByDefault.setOnCheckedChangeListener(
+ ((buttonView, isChecked) -> model.setShowCommentsByDefault(isChecked)));
+
+ defaultCommodity = context.findViewById(R.id.default_commodity_text);
+
+ 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 -> {
+ model.setFutureDates(futureDatesSettingFromMenuItemId(item.getItemId()));
+ return true;
+ });
+ menu.show();
+ });
+ model.observeFutureDates(viewLifecycleOwner,
+ v -> futureDatesText.setText(v.getText(getResources())));
+
+ apiVersionText = context.findViewById(R.id.api_version_text);
+ model.observeApiVersion(viewLifecycleOwner,
+ apiVer -> apiVersionText.setText(apiVer.getDescription(getResources())));
+ context.findViewById(R.id.api_version_label)
+ .setOnClickListener(this::chooseAPIVersion);
+ context.findViewById(R.id.api_version_text)
+ .setOnClickListener(this::chooseAPIVersion);
+
+ TextView detectedApiVersion = context.findViewById(R.id.detected_version_text);
+ model.observeDetectedVersion(viewLifecycleOwner, ver -> {
+ if (ver == null)
+ detectedApiVersion.setText(context.getResources()
+ .getString(R.string.api_version_unknown_label));
+ else if (ver.isPre_1_20())
+ detectedApiVersion.setText(context.getResources()
+ .getString(R.string.api_pre_1_19));
+ else
+ detectedApiVersion.setText(ver.toString());
+ });
+ detectedApiVersion.setOnClickListener(v -> model.triggerVersionDetection());
+ final View detectButton = context.findViewById(R.id.api_version_detect_button);
+ detectButton.setOnClickListener(v -> model.triggerVersionDetection());
+ model.observeDetectingHledgerVersion(viewLifecycleOwner, running -> {
+ detectButton.setVisibility(running ? View.VISIBLE : View.INVISIBLE);