X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfileDetailFragment.java;h=9b0b60b70b00a874277a47418058c6d40068a627;hb=667ce42731c95a98926657fea359b56209f9348e;hp=b712f29da87ca248bbd6923e7407740e5b9db1a8;hpb=14f60602fa419409b68e9c41c37c6aedda3bc526;p=mobile-ledger-staging.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index b712f29d..9b0b60b7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -282,33 +282,26 @@ public class ProfileDetailFragment extends Fragment { apiVersionText = context.findViewById(R.id.api_version_text); model.observeApiVersion(viewLifecycleOwner, apiVer -> apiVersionText.setText(apiVer.getDescription(getResources()))); - 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 -> { - SendTransactionTask.API apiVer; - switch (item.getItemId()) { - case R.id.api_version_menu_html: - apiVer = SendTransactionTask.API.html; - break; - case R.id.api_version_menu_post_1_14: - apiVer = SendTransactionTask.API.post_1_14; - break; - case R.id.api_version_menu_pre_1_15: - apiVer = SendTransactionTask.API.pre_1_15; - 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(); - }); + 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()); + context.findViewById(R.id.api_version_detect_button) + .setOnClickListener(v -> model.triggerVersionDetection()); + authParams = context.findViewById(R.id.auth_params); useAuthentication = context.findViewById(R.id.enable_http_auth); @@ -386,6 +379,34 @@ public class ProfileDetailFragment extends Fragment { 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_post_1_14: + apiVer = SendTransactionTask.API.post_1_14; + break; + case R.id.api_version_menu_pre_1_15: + apiVer = SendTransactionTask.API.pre_1_15; + 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: @@ -417,22 +438,35 @@ public class ProfileDetailFragment extends Fragment { return; ProfileDetailModel model = getModel(); + final ArrayList profiles = + Objects.requireNonNull(Data.profiles.getValue()); if (mProfile != null) { + int pos = Data.profiles.getValue() + .indexOf(mProfile); + mProfile = new MobileLedgerProfile(mProfile); model.updateProfile(mProfile); -// debug("profiles", String.format("Selected item is %d", mProfile.getThemeHue())); mProfile.storeInDB(); debug("profiles", "profile stored in DB"); - triggerProfileChange(); + 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 profiles = Data.profiles.getValue(); - if (profiles == null) - throw new AssertionError(); - ArrayList newList = new ArrayList<>(profiles); + final ArrayList newList = new ArrayList<>(profiles); newList.add(mProfile); Data.profiles.setValue(newList); MobileLedgerProfile.storeProfilesOrder();