click on dynamic tag to filter for that tag

This commit is contained in:
Daniel Gultsch 2015-01-02 14:47:08 +01:00
parent 093c5275c6
commit f58f27a1f7
2 changed files with 34 additions and 0 deletions

View File

@ -160,6 +160,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
};
private MenuItem mMenuSearchView;
private String mInitialJid;
private ListItemAdapter.OnTagClickedListener mOnTagClickedListener = new ListItemAdapter.OnTagClickedListener() {
@Override
public void onTagClicked(String tag) {
if (mMenuSearchView != null) {
mMenuSearchView.expandActionView();
mSearchEditText.setText("");
mSearchEditText.append(tag);
filter(tag);
}
}
};
@Override
public void onRosterUpdate() {
@ -221,6 +232,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
});
mContactsAdapter = new ListItemAdapter(this, contacts);
((ListItemAdapter) mContactsAdapter).setOnTagClickedListener(this.mOnTagClickedListener);
mContactsListFragment.setListAdapter(mContactsAdapter);
mContactsListFragment.setContextMenu(R.menu.contact_context);
mContactsListFragment

View File

@ -2,6 +2,7 @@ package eu.siacs.conversations.ui.adapter;
import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.ui.XmppActivity;
@ -10,6 +11,7 @@ import eu.siacs.conversations.xmpp.jid.Jid;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -22,6 +24,17 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
protected XmppActivity activity;
protected boolean showDynamicTags = false;
private View.OnClickListener onTagTvClick = new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view instanceof TextView && mOnTagClickedListener != null) {
TextView tv = (TextView) view;
final String tag = tv.getText().toString();
mOnTagClickedListener.onTagClicked(tag);
}
}
};
private OnTagClickedListener mOnTagClickedListener = null;
public ListItemAdapter(XmppActivity activity, List<ListItem> objects) {
super(activity, 0, objects);
@ -53,6 +66,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
TextView tv = (TextView) inflater.inflate(R.layout.list_item_tag,tagLayout,false);
tv.setText(tag.getName());
tv.setBackgroundColor(tag.getColor());
tv.setOnClickListener(this.onTagTvClick);
tagLayout.addView(tv);
}
}
@ -68,4 +82,12 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
return view;
}
public void setOnTagClickedListener(OnTagClickedListener listener) {
this.mOnTagClickedListener = listener;
}
public interface OnTagClickedListener {
public void onTagClicked(String tag);
}
}