Search in sources :

Example 1 with IdentityContainer

use of com.fsck.k9.activity.compose.IdentityAdapter.IdentityContainer in project k-9 by k9mail.

the class IdentityAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Object item = mItems.get(position);
    View view = null;
    if (item instanceof Account) {
        if (convertView != null && convertView.getTag() instanceof AccountHolder) {
            view = convertView;
        } else {
            view = mLayoutInflater.inflate(R.layout.choose_account_item, parent, false);
            AccountHolder holder = new AccountHolder();
            holder.name = (TextView) view.findViewById(R.id.name);
            holder.chip = view.findViewById(R.id.chip);
            view.setTag(holder);
        }
        Account account = (Account) item;
        AccountHolder holder = (AccountHolder) view.getTag();
        holder.name.setText(account.getDescription());
        holder.chip.setBackgroundColor(account.getChipColor());
    } else if (item instanceof IdentityContainer) {
        if (convertView != null && convertView.getTag() instanceof IdentityHolder) {
            view = convertView;
        } else {
            view = mLayoutInflater.inflate(R.layout.choose_identity_item, parent, false);
            IdentityHolder holder = new IdentityHolder();
            holder.name = (TextView) view.findViewById(R.id.name);
            holder.description = (TextView) view.findViewById(R.id.description);
            view.setTag(holder);
        }
        IdentityContainer identityContainer = (IdentityContainer) item;
        Identity identity = identityContainer.identity;
        IdentityHolder holder = (IdentityHolder) view.getTag();
        holder.name.setText(identity.getDescription());
        holder.description.setText(getIdentityDescription(identity));
    }
    return view;
}
Also used : Account(com.fsck.k9.Account) TextView(android.widget.TextView) Identity(com.fsck.k9.Identity) TextView(android.widget.TextView) View(android.view.View)

Example 2 with IdentityContainer

use of com.fsck.k9.activity.compose.IdentityAdapter.IdentityContainer in project k-9 by k9mail.

the class MessageCompose method onCreateDialog.

@Override
public Dialog onCreateDialog(int id) {
    switch(id) {
        case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE:
            return new AlertDialog.Builder(this).setTitle(R.string.save_or_discard_draft_message_dlg_title).setMessage(R.string.save_or_discard_draft_message_instructions_fmt).setPositiveButton(R.string.save_draft_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
                    checkToSaveDraftAndSave();
                }
            }).setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
                    onDiscard();
                }
            }).create();
        case DIALOG_CONFIRM_DISCARD_ON_BACK:
            return new AlertDialog.Builder(this).setTitle(R.string.confirm_discard_draft_message_title).setMessage(R.string.confirm_discard_draft_message).setPositiveButton(R.string.cancel_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK);
                }
            }).setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    dismissDialog(DIALOG_CONFIRM_DISCARD_ON_BACK);
                    Toast.makeText(MessageCompose.this, getString(R.string.message_discarded_toast), Toast.LENGTH_LONG).show();
                    onDiscard();
                }
            }).create();
        case DIALOG_CHOOSE_IDENTITY:
            Context context = new ContextThemeWrapper(this, (K9.getK9Theme() == K9.Theme.LIGHT) ? R.style.Theme_K9_Dialog_Light : R.style.Theme_K9_Dialog_Dark);
            Builder builder = new AlertDialog.Builder(context);
            builder.setTitle(R.string.send_as);
            final IdentityAdapter adapter = new IdentityAdapter(context);
            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    IdentityContainer container = (IdentityContainer) adapter.getItem(which);
                    onAccountChosen(container.account, container.identity);
                }
            });
            return builder.create();
        case DIALOG_CONFIRM_DISCARD:
            {
                return new AlertDialog.Builder(this).setTitle(R.string.dialog_confirm_delete_title).setMessage(R.string.dialog_confirm_delete_message).setPositiveButton(R.string.dialog_confirm_delete_confirm_button, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        onDiscard();
                    }
                }).setNegativeButton(R.string.dialog_confirm_delete_cancel_button, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).create();
            }
    }
    return super.onCreateDialog(id);
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) IdentityAdapter(com.fsck.k9.activity.compose.IdentityAdapter) ContextThemeWrapper(android.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) PgpMessageBuilder(com.fsck.k9.message.PgpMessageBuilder) SimpleMessageBuilder(com.fsck.k9.message.SimpleMessageBuilder) MessageBuilder(com.fsck.k9.message.MessageBuilder) Builder(android.app.AlertDialog.Builder) OnClickListener(android.view.View.OnClickListener) IdentityContainer(com.fsck.k9.activity.compose.IdentityAdapter.IdentityContainer) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.app.AlertDialog)1 Builder (android.app.AlertDialog.Builder)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 TextView (android.widget.TextView)1 Account (com.fsck.k9.Account)1 Identity (com.fsck.k9.Identity)1 IdentityAdapter (com.fsck.k9.activity.compose.IdentityAdapter)1 IdentityContainer (com.fsck.k9.activity.compose.IdentityAdapter.IdentityContainer)1 MessageBuilder (com.fsck.k9.message.MessageBuilder)1 PgpMessageBuilder (com.fsck.k9.message.PgpMessageBuilder)1 SimpleMessageBuilder (com.fsck.k9.message.SimpleMessageBuilder)1