- }
- @Override
- public void onActivityCreated(@Nullable Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- Activity context = getActivity();
- if (context == null) return;
-
- fab = context.findViewById(R.id.fab);
- fab.setOnClickListener(v -> {
- if (!checkValidity()) return;
-
- if (mProfile != null) {
- mProfile.setName(profileName.getText());
- mProfile.setUrl(url.getText());
- mProfile.setPostingPermitted(postingPermitted.isChecked());
- mProfile.setAuthEnabled(useAuthentication.isChecked());
- mProfile.setAuthUserName(userName.getText());
- mProfile.setAuthPassword(password.getText());
- mProfile.setThemeId(colorSpinner.getSelectedItem());
-// Log.d("profiles", String.format("Selected item is %d", mProfile.getThemeId()));
- mProfile.storeInDB();
- Log.d("profiles", "profile stored in DB");
- Data.profiles.triggerItemChangedNotification(mProfile);
-
-
- if (mProfile.getUuid().equals(Data.profile.get().getUuid())) {
- // dummy update to notify the observers of the possibly new name/URL
- Data.profile.set(mProfile);
- }
- }
- else {
- mProfile =
- new MobileLedgerProfile(profileName.getText(), postingPermitted.isChecked(),
- url.getText(), useAuthentication.isChecked(), userName.getText(),
- password.getText(),
- Integer.valueOf((String) colorSpinner.getSelectedItem()));
- mProfile.storeInDB();
- Data.profiles.add(mProfile);
- MobileLedgerProfile.storeProfilesOrder();
-
- // first profile ever?
- if (Data.profiles.getList().size() == 1) Data.profile.set(mProfile);
- }
-
- Activity activity = getActivity();
- if (activity != null) activity.finish();
- });
-
- profileName.requestFocus();
- }
- @Override
- public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.profile_detail, container, false);
-
- profileName = rootView.findViewById(R.id.profile_name);
- profileNameLayout = rootView.findViewById(R.id.profile_name_layout);
- url = rootView.findViewById(R.id.url);
- urlLayout = rootView.findViewById(R.id.url_layout);
- postingPermitted = rootView.findViewById(R.id.profile_permit_posting);
- authParams = rootView.findViewById(R.id.auth_params);
- useAuthentication = rootView.findViewById(R.id.enable_http_auth);
- userName = rootView.findViewById(R.id.auth_user_name);
- userNameLayout = rootView.findViewById(R.id.auth_user_name_layout);
- password = rootView.findViewById(R.id.password);
- passwordLayout = rootView.findViewById(R.id.password_layout);
- colorSpinner = rootView.findViewById(R.id.colorSpinner);
-
- ArrayAdapter<CharSequence> adapter = ColorListAdapter
- .createFromResource(rootView.getContext(), R.array.profile_colors,
- R.layout.color_selector_item);
-// Log.d("profiles", String.format("color count: %s", adapter.getCount()));
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- colorSpinner.setAdapter(adapter);
- colorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onNothingSelected(AdapterView<?> parent) {