+
+ profileName.requestFocus();
+ }
+ private void chooseAPIVersion(View v) {
+ Activity context = getActivity();
+ ProfileDetailModel model = getModel();
+ MenuInflater mi = new MenuInflater(context);
+ PopupMenu menu = new PopupMenu(context, v);
+ menu.inflate(R.menu.api_version);
+ menu.setOnMenuItemClickListener(item -> {
+ SendTransactionTask.API apiVer;
+ switch (item.getItemId()) {
+ case R.id.api_version_menu_html:
+ apiVer = SendTransactionTask.API.html;
+ break;
+ case R.id.api_version_menu_1_19_1:
+ apiVer = SendTransactionTask.API.v1_19_1;
+ break;
+ case R.id.api_version_menu_1_15:
+ apiVer = SendTransactionTask.API.v1_15;
+ break;
+ case R.id.api_version_menu_1_14:
+ apiVer = SendTransactionTask.API.v1_14;
+ break;
+ case R.id.api_version_menu_auto:
+ default:
+ apiVer = SendTransactionTask.API.auto;
+ }
+ model.setApiVersion(apiVer);
+ apiVersionText.setText(apiVer.getDescription(getResources()));
+ return true;
+ });
+ menu.show();
+ }
+ 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();
+ final ArrayList<MobileLedgerProfile> profiles =
+ Objects.requireNonNull(Data.profiles.getValue());
+
+ if (mProfile != null) {
+ int pos = Data.profiles.getValue()
+ .indexOf(mProfile);
+ mProfile = new MobileLedgerProfile(mProfile);
+ model.updateProfile(mProfile);
+ mProfile.storeInDB();
+ debug("profiles", "profile stored in DB");
+ profiles.set(pos, mProfile);
+// debug("profiles", String.format("Selected item is %d", mProfile.getThemeHue()));
+
+ final MobileLedgerProfile currentProfile = Data.getProfile();
+ if (mProfile.getUuid()
+ .equals(currentProfile.getUuid()))
+ {
+ Data.setCurrentProfile(mProfile);
+ }
+
+ ProfilesRecyclerViewAdapter viewAdapter = ProfilesRecyclerViewAdapter.getInstance();
+ if (viewAdapter != null)
+ viewAdapter.notifyItemChanged(pos);
+ }
+ else {
+ mProfile = new MobileLedgerProfile(String.valueOf(UUID.randomUUID()));
+ model.updateProfile(mProfile);
+ mProfile.storeInDB();
+ final ArrayList<MobileLedgerProfile> newList = new ArrayList<>(profiles);
+ newList.add(mProfile);
+ Data.profiles.setValue(newList);
+ MobileLedgerProfile.storeProfilesOrder();
+
+ // first profile ever?
+ if (newList.size() == 1)
+ Data.setCurrentProfile(mProfile);
+ }
+
+ Activity activity = getActivity();
+ if (activity != null)
+ activity.finish();
+ }
+ private boolean checkUrlValidity() {
+ boolean valid = true;
+
+ ProfileDetailModel model = getModel();
+
+ String val = model.getUrl()
+ .trim();
+ if (val.isEmpty()) {
+ valid = false;
+ urlLayout.setError(getResources().getText(R.string.err_profile_url_empty));
+ }
+ try {
+ URL url = new URL(val);
+ String host = url.getHost();
+ if (host == null || host.isEmpty())
+ throw new MalformedURLException("Missing host");
+ String protocol = url.getProtocol()
+ .toUpperCase();
+ if (!protocol.equals("HTTP") && !protocol.equals("HTTPS")) {
+ valid = false;
+ urlLayout.setError(getResources().getText(R.string.err_invalid_url));
+ }
+ }
+ catch (MalformedURLException e) {
+ valid = false;
+ urlLayout.setError(getResources().getText(R.string.err_invalid_url));
+ }
+
+ return valid;
+ }
+ private void checkInsecureSchemeWithAuth() {
+ boolean showWarning = false;
+
+ final ProfileDetailModel model = getModel();
+
+ if (model.getUseAuthentication()) {
+ String urlText = model.getUrl();
+ if (urlText.startsWith("http") && !urlText.startsWith("https"))
+ showWarning = true;
+ }
+
+ if (showWarning)
+ insecureWarningText.setVisibility(View.VISIBLE);
+ else
+ insecureWarningText.setVisibility(View.GONE);