+ FloatingActionButton fab = context.findViewById(R.id.fab);
+ fab.setOnClickListener(v -> onSaveFabClicked());
+
+ profileName.requestFocus();
+ }
+ private void onSaveFabClicked() {
+ if (!checkValidity()) return;
+
+ if (mProfile != null) {
+ updateProfileFromUI();
+// debug("profiles", String.format("Selected item is %d", mProfile.getThemeId()));
+ mProfile.storeInDB();
+ debug("profiles", "profile stored in DB");
+ triggerProfileChange();
+ }
+ else {
+ mProfile = new MobileLedgerProfile();
+ updateProfileFromUI();
+ mProfile.storeInDB();
+ final ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
+ assert profiles != null;
+ ArrayList<MobileLedgerProfile> newList =
+ (ArrayList<MobileLedgerProfile>) profiles.clone();
+ newList.add(mProfile);
+ Data.profiles.setValue(newList);
+ MobileLedgerProfile.storeProfilesOrder();
+
+ // first profile ever?
+ if (newList.size() == 1) Data.profile.setValue(mProfile);
+ }
+
+ Activity activity = getActivity();
+ if (activity != null) activity.finish();
+ }
+ private void updateProfileFromUI() {
+ mProfile.setName(profileName.getText());
+ mProfile.setUrl(url.getText());
+ mProfile.setPostingPermitted(postingPermitted.isChecked());
+ mProfile.setPreferredAccountsFilter(preferredAccountsFilter.getText());
+ mProfile.setAuthEnabled(useAuthentication.isChecked());
+ mProfile.setAuthUserName(userName.getText());
+ mProfile.setAuthPassword(password.getText());
+ mProfile.setThemeId(huePickerView.getTag());