Search in sources :

Example 1 with Role

use of org.wordpress.android.models.Role in project WordPress-Android by wordpress-mobile.

the class PeopleInviteFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mUsernamesContainer = (ViewGroup) view.findViewById(R.id.usernames);
    mUsernamesContainer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            EditTextUtils.showSoftInput(mUsernameEditText);
        }
    });
    Role role = mRole;
    if (role == null) {
        role = getDefaultRole();
    }
    mUsernameEditText = (MultiUsernameEditText) view.findViewById(R.id.invite_usernames);
    //handle key preses from hardware keyboard
    mUsernameEditText.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            return keyEvent.getKeyCode() == KeyEvent.KEYCODE_DEL && keyEvent.getAction() == KeyEvent.ACTION_DOWN && removeLastEnteredUsername();
        }
    });
    mUsernameEditText.setOnBackspacePressedListener(new MultiUsernameEditText.OnBackspacePressedListener() {

        @Override
        public boolean onBackspacePressed() {
            return removeLastEnteredUsername();
        }
    });
    mUsernameEditText.addTextChangedListener(new TextWatcher() {

        private boolean shouldIgnoreChanges = false;

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (shouldIgnoreChanges) {
                //used to avoid double call after calling setText from this method
                return;
            }
            shouldIgnoreChanges = true;
            if (mUsernameButtons.size() >= MAX_NUMBER_OF_INVITEES && !TextUtils.isEmpty(s)) {
                resetEditTextContent(mUsernameEditText);
            } else if (endsWithDelimiter(mUsernameEditText.getText().toString())) {
                addUsername(mUsernameEditText, null);
            }
            shouldIgnoreChanges = false;
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    mUsernameEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                addUsername(mUsernameEditText, null);
                return true;
            } else {
                return false;
            }
        }
    });
    mUsernameEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus && mUsernameEditText.getText().toString().length() > 0) {
                addUsername(mUsernameEditText, null);
            }
        }
    });
    if (mUsernameButtons.size() > 0) {
        ArrayList<String> usernames = new ArrayList<>(mUsernameButtons.keySet());
        populateUsernameButtons(usernames);
    }
    mRoleTextView = (TextView) view.findViewById(R.id.role);
    setRole(role);
    ImageView imgRoleInfo = (ImageView) view.findViewById(R.id.imgRoleInfo);
    imgRoleInfo.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ActivityLauncher.openUrlExternal(v.getContext(), URL_USER_ROLES_DOCUMENTATION);
        }
    });
    if (Role.inviteRoles(mSite).length > 1) {
        view.findViewById(R.id.role_container).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                RoleSelectDialogFragment.show(PeopleInviteFragment.this, 0, mSite);
            }
        });
    } else {
        // Don't show drop-down arrow or role selector if there's only one role available
        mRoleTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    }
    final int MAX_CHARS = getResources().getInteger(R.integer.invite_message_char_limit);
    final TextView remainingCharsTextView = (TextView) view.findViewById(R.id.message_remaining);
    mCustomMessageEditText = (EditText) view.findViewById(R.id.message);
    mCustomMessageEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mCustomMessage = mCustomMessageEditText.getText().toString();
            updateRemainingCharsView(remainingCharsTextView, mCustomMessage, MAX_CHARS);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    updateRemainingCharsView(remainingCharsTextView, mCustomMessage, MAX_CHARS);
}
Also used : ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Role(org.wordpress.android.models.Role) KeyEvent(android.view.KeyEvent) MultiUsernameEditText(org.wordpress.android.widgets.MultiUsernameEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 2 with Role

use of org.wordpress.android.models.Role in project WordPress-Android by wordpress-mobile.

the class RoleChangeDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final SiteModel site = (SiteModel) getArguments().getSerializable(WordPress.SITE);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Calypso_AlertDialog);
    builder.setTitle(R.string.role);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Role role = mRoleListAdapter.getSelectedRole();
            Bundle args = getArguments();
            if (args != null) {
                long personID = args.getLong(PERSON_ID_TAG);
                if (site != null) {
                    EventBus.getDefault().post(new RoleChangeEvent(personID, site.getId(), role));
                }
            }
        }
    });
    if (mRoleListAdapter == null) {
        final Role[] userRoles = Role.userRoles(site);
        mRoleListAdapter = new RoleListAdapter(getActivity(), R.layout.role_list_row, userRoles);
    }
    if (savedInstanceState != null) {
        Role savedRole = (Role) savedInstanceState.getSerializable(ROLE_TAG);
        mRoleListAdapter.setSelectedRole(savedRole);
    } else {
        Bundle args = getArguments();
        if (args != null) {
            Role role = (Role) args.getSerializable(ROLE_TAG);
            mRoleListAdapter.setSelectedRole(role);
        }
    }
    builder.setAdapter(mRoleListAdapter, null);
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Role(org.wordpress.android.models.Role)

Example 3 with Role

use of org.wordpress.android.models.Role in project WordPress-Android by wordpress-mobile.

the class RoleChangeDialogFragment method onSaveInstanceState.

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Role role = mRoleListAdapter.getSelectedRole();
    outState.putSerializable(ROLE_TAG, role);
}
Also used : Role(org.wordpress.android.models.Role)

Example 4 with Role

use of org.wordpress.android.models.Role in project WordPress-Android by wordpress-mobile.

the class RoleSelectDialogFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    SiteModel site = (SiteModel) getArguments().getSerializable(WordPress.SITE);
    final Role[] roles = Role.inviteRoles(site);
    final String[] stringRoles = new String[roles.length];
    for (int i = 0; i < roles.length; i++) {
        stringRoles[i] = roles[i].toDisplayString();
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Calypso_AlertDialog);
    builder.setTitle(R.string.role);
    builder.setItems(stringRoles, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (!isAdded()) {
                return;
            }
            if (getTargetFragment() instanceof OnRoleSelectListener) {
                ((OnRoleSelectListener) getTargetFragment()).onRoleSelected(roles[which]);
            } else if (getActivity() instanceof OnRoleSelectListener) {
                ((OnRoleSelectListener) getActivity()).onRoleSelected(roles[which]);
            }
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Role(org.wordpress.android.models.Role)

Aggregations

Role (org.wordpress.android.models.Role)4 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 SiteModel (org.wordpress.android.fluxc.model.SiteModel)2 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ArrayList (java.util.ArrayList)1 MultiUsernameEditText (org.wordpress.android.widgets.MultiUsernameEditText)1