Search in sources :

Example 1 with ListItem

use of de.pixart.messenger.entities.ListItem in project Pix-Art-Messenger by kriztan.

the class ChooseContactActivity method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    filterContacts = new HashSet<>();
    String[] contacts = getIntent().getStringArrayExtra("filter_contacts");
    if (contacts != null) {
        Collections.addAll(filterContacts, contacts);
    }
    if (getIntent().getBooleanExtra("multiple", false)) {
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() {

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.select_multiple, menu);
                selected = new HashSet<>();
                return true;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch(item.getItemId()) {
                    case R.id.selection_submit:
                        final Intent request = getIntent();
                        final Intent data = new Intent();
                        data.putExtra("conversation", request.getStringExtra("conversation"));
                        String[] selection = getSelectedContactJids();
                        data.putExtra("contacts", selection);
                        data.putExtra("multiple", true);
                        data.putExtra(EXTRA_ACCOUNT, request.getStringExtra(EXTRA_ACCOUNT));
                        data.putExtra("subject", request.getStringExtra("subject"));
                        setResult(RESULT_OK, data);
                        finish();
                        return true;
                }
                return false;
            }

            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
                Contact item = (Contact) getListItems().get(position);
                if (checked) {
                    selected.add(item);
                } else {
                    selected.remove(item);
                }
                int numSelected = selected.size();
                MenuItem selectButton = mode.getMenu().findItem(R.id.selection_submit);
                String buttonText = getResources().getQuantityString(R.plurals.select_contact, numSelected, numSelected);
                selectButton.setTitle(buttonText);
            }
        });
    }
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
            final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
            final Intent request = getIntent();
            final Intent data = new Intent();
            final ListItem mListItem = getListItems().get(position);
            data.putExtra("contact", mListItem.getJid().toString());
            String account = request.getStringExtra(EXTRA_ACCOUNT);
            if (account == null && mListItem instanceof Contact) {
                account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString();
            }
            data.putExtra(EXTRA_ACCOUNT, account);
            data.putExtra("conversation", request.getStringExtra("conversation"));
            data.putExtra("multiple", false);
            data.putExtra("subject", request.getStringExtra("subject"));
            setResult(RESULT_OK, data);
            finish();
        }
    });
}
Also used : MenuInflater(android.view.MenuInflater) InputMethodManager(android.view.inputmethod.InputMethodManager) MenuItem(android.view.MenuItem) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Contact(de.pixart.messenger.entities.Contact) ActionMode(android.view.ActionMode) AdapterView(android.widget.AdapterView) Menu(android.view.Menu) ListItem(de.pixart.messenger.entities.ListItem) MultiChoiceModeListener(android.widget.AbsListView.MultiChoiceModeListener) HashSet(java.util.HashSet)

Example 2 with ListItem

use of de.pixart.messenger.entities.ListItem in project Pix-Art-Messenger by kriztan.

the class ListItemAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    LayoutInflater inflater = activity.getLayoutInflater();
    ListItem item = getItem(position);
    ViewHolder viewHolder;
    if (view == null) {
        ContactBinding binding = DataBindingUtil.inflate(inflater, R.layout.contact, parent, false);
        viewHolder = ViewHolder.get(binding);
        view = binding.getRoot();
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }
    List<ListItem.Tag> tags = item.getTags(activity);
    if (tags.size() == 0 || !this.showDynamicTags) {
        viewHolder.tags.setVisibility(View.GONE);
    } else {
        viewHolder.tags.setVisibility(View.VISIBLE);
        viewHolder.tags.removeAllViewsInLayout();
        for (ListItem.Tag tag : tags) {
            TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag, viewHolder.tags, false);
            tv.setText(tag.getName());
            tv.setBackgroundColor(tag.getColor());
            tv.setOnClickListener(this.onTagTvClick);
            viewHolder.tags.addView(tv);
        }
    }
    final String jid = item.getDisplayJid();
    if (jid != null) {
        viewHolder.jid.setVisibility(View.VISIBLE);
        viewHolder.jid.setText(jid);
    } else {
        viewHolder.jid.setVisibility(View.GONE);
    }
    viewHolder.name.setText(item.getDisplayName());
    if (tags.size() != 0) {
        for (ListItem.Tag tag : tags) {
            offline = tag.getOffline() == 1;
            color = tag.getColor();
        }
    }
    if (offline) {
        viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.black87));
        viewHolder.name.setAlpha(INACTIVE_ALPHA);
        viewHolder.jid.setAlpha(INACTIVE_ALPHA);
        viewHolder.avatar.setAlpha(INACTIVE_ALPHA);
        viewHolder.tags.setAlpha(INACTIVE_ALPHA);
    } else {
        if (ShowPresenceColoredNames()) {
            viewHolder.name.setTextColor(color);
        } else {
            viewHolder.name.setTextColor(ContextCompat.getColor(activity, R.color.black87));
        }
        viewHolder.name.setAlpha(ACTIVE_ALPHA);
        viewHolder.jid.setAlpha(ACTIVE_ALPHA);
        viewHolder.avatar.setAlpha(ACTIVE_ALPHA);
        viewHolder.tags.setAlpha(ACTIVE_ALPHA);
    }
    loadAvatar(item, viewHolder.avatar);
    return view;
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ListItem(de.pixart.messenger.entities.ListItem) ContactBinding(de.pixart.messenger.databinding.ContactBinding)

Aggregations

ListItem (de.pixart.messenger.entities.ListItem)2 Intent (android.content.Intent)1 ActionMode (android.view.ActionMode)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 MultiChoiceModeListener (android.widget.AbsListView.MultiChoiceModeListener)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 ContactBinding (de.pixart.messenger.databinding.ContactBinding)1 Contact (de.pixart.messenger.entities.Contact)1 HashSet (java.util.HashSet)1