Unified Start Conversation activity
Show chatrooms and contacts together in one list and search searches both of them.
This commit is contained in:
parent
153028f574
commit
dea5a9fd9c
|
@ -153,6 +153,7 @@ public class Bookmark extends Element implements ListItem {
|
||||||
@Override
|
@Override
|
||||||
public List<Tag> getTags(Context context) {
|
public List<Tag> getTags(Context context) {
|
||||||
ArrayList<Tag> tags = new ArrayList<>();
|
ArrayList<Tag> tags = new ArrayList<>();
|
||||||
|
tags.add(new Tag("Channel", UIHelper.getColorForName("Channel",true)));
|
||||||
for (Element element : getChildren()) {
|
for (Element element : getChildren()) {
|
||||||
if (element.getName().equals("group") && element.getContent() != null) {
|
if (element.getName().equals("group") && element.getContent() != null) {
|
||||||
String group = element.getContent();
|
String group = element.getContent();
|
||||||
|
|
|
@ -97,8 +97,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
|
private final PendingItem<Intent> pendingViewIntent = new PendingItem<>();
|
||||||
private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
|
private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
|
||||||
private final AtomicBoolean oneShotKeyboardSuppress = new AtomicBoolean();
|
private final AtomicBoolean oneShotKeyboardSuppress = new AtomicBoolean();
|
||||||
public int conference_context_id;
|
public ListItem contextItem;
|
||||||
public int contact_context_id;
|
|
||||||
private ListPagerAdapter mListPagerAdapter;
|
private ListPagerAdapter mListPagerAdapter;
|
||||||
private final List<ListItem> contacts = new ArrayList<>();
|
private final List<ListItem> contacts = new ArrayList<>();
|
||||||
private ListItemAdapter mContactsAdapter;
|
private ListItemAdapter mContactsAdapter;
|
||||||
|
@ -194,7 +193,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
int pos = binding.startConversationViewPager.getCurrentItem();
|
int pos = binding.startConversationViewPager.getCurrentItem();
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
if (contacts.size() == 1) {
|
if (contacts.size() == 1) {
|
||||||
openConversationForContact((Contact) contacts.get(0));
|
openConversation(contacts.get(0));
|
||||||
return true;
|
return true;
|
||||||
} else if (contacts.size() == 0 && conferences.size() == 1) {
|
} else if (contacts.size() == 0 && conferences.size() == 1) {
|
||||||
openConversationsForBookmark((Bookmark) conferences.get(0));
|
openConversationsForBookmark((Bookmark) conferences.get(0));
|
||||||
|
@ -205,7 +204,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
openConversationsForBookmark((Bookmark) conferences.get(0));
|
openConversationsForBookmark((Bookmark) conferences.get(0));
|
||||||
return true;
|
return true;
|
||||||
} else if (conferences.size() == 0 && contacts.size() == 1) {
|
} else if (conferences.size() == 0 && contacts.size() == 1) {
|
||||||
openConversationForContact((Contact) contacts.get(0));
|
openConversation(contacts.get(0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,8 +405,15 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openConversationForContact(int position) {
|
protected void openConversationForContact(int position) {
|
||||||
Contact contact = (Contact) contacts.get(position);
|
openConversation(contacts.get(position));
|
||||||
openConversationForContact(contact);
|
}
|
||||||
|
|
||||||
|
protected void openConversation(ListItem item) {
|
||||||
|
if (item instanceof Contact) {
|
||||||
|
openConversationForContact((Contact) item);
|
||||||
|
} else {
|
||||||
|
openConversationsForBookmark((Bookmark) item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openConversationForContact(Contact contact) {
|
protected void openConversationForContact(Contact contact) {
|
||||||
|
@ -422,7 +428,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void shareBookmarkUri() {
|
protected void shareBookmarkUri() {
|
||||||
shareBookmarkUri(conference_context_id);
|
shareAsChannel(this, contextItem.getJid().asBareJid().toEscapedString());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void shareBookmarkUri(int position) {
|
protected void shareBookmarkUri(int position) {
|
||||||
|
@ -459,25 +465,19 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void openDetailsForContact() {
|
protected void openDetailsForContact() {
|
||||||
int position = contact_context_id;
|
switchToContactDetails((Contact) contextItem);
|
||||||
Contact contact = (Contact) contacts.get(position);
|
|
||||||
switchToContactDetails(contact);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showQrForContact() {
|
protected void showQrForContact() {
|
||||||
int position = contact_context_id;
|
showQrCode("xmpp:" + contextItem.getJid().asBareJid().toEscapedString());
|
||||||
Contact contact = (Contact) contacts.get(position);
|
|
||||||
showQrCode("xmpp:" + contact.getJid().asBareJid().toEscapedString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void toggleContactBlock() {
|
protected void toggleContactBlock() {
|
||||||
final int position = contact_context_id;
|
BlockContactDialog.show(this, (Contact) contextItem);
|
||||||
BlockContactDialog.show(this, (Contact) contacts.get(position));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deleteContact() {
|
protected void deleteContact() {
|
||||||
final int position = contact_context_id;
|
final Contact contact = (Contact) contextItem;
|
||||||
final Contact contact = (Contact) contacts.get(position);
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
builder.setTitle(R.string.action_delete_contact);
|
builder.setTitle(R.string.action_delete_contact);
|
||||||
|
@ -490,8 +490,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deleteConference() {
|
protected void deleteConference() {
|
||||||
int position = conference_context_id;
|
final Bookmark bookmark = (Bookmark) contextItem;
|
||||||
final Bookmark bookmark = (Bookmark) conferences.get(position);
|
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setNegativeButton(R.string.cancel, null);
|
builder.setNegativeButton(R.string.cancel, null);
|
||||||
|
@ -972,8 +971,15 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
this.contacts.add(contact);
|
this.contacts.add(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Bookmark bookmark : account.getBookmarks()) {
|
||||||
|
if (bookmark.match(this, needle)) {
|
||||||
|
this.contacts.add(bookmark);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(this.contacts);
|
Collections.sort(this.contacts);
|
||||||
mContactsAdapter.notifyDataSetChanged();
|
mContactsAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
@ -1183,17 +1189,22 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
|
||||||
if (activity == null) {
|
if (activity == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activity.getMenuInflater().inflate(mResContextMenu, menu);
|
|
||||||
final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
|
||||||
if (mResContextMenu == R.menu.conference_context) {
|
activity.contextItem = null;
|
||||||
activity.conference_context_id = acmi.position;
|
if (mResContextMenu == R.menu.contact_context) {
|
||||||
final Bookmark bookmark = (Bookmark) activity.conferences.get(acmi.position);
|
activity.contextItem = activity.contacts.get(acmi.position);
|
||||||
|
} else if (mResContextMenu == R.menu.conference_context) {
|
||||||
|
activity.contextItem = activity.conferences.get(acmi.position);
|
||||||
|
}
|
||||||
|
if (activity.contextItem instanceof Bookmark) {
|
||||||
|
activity.getMenuInflater().inflate(R.menu.conference_context, menu);
|
||||||
|
final Bookmark bookmark = (Bookmark) activity.contextItem;
|
||||||
final Conversation conversation = bookmark.getConversation();
|
final Conversation conversation = bookmark.getConversation();
|
||||||
final MenuItem share = menu.findItem(R.id.context_share_uri);
|
final MenuItem share = menu.findItem(R.id.context_share_uri);
|
||||||
share.setVisible(conversation == null || !conversation.isPrivateAndNonAnonymous());
|
share.setVisible(conversation == null || !conversation.isPrivateAndNonAnonymous());
|
||||||
} else if (mResContextMenu == R.menu.contact_context) {
|
} else if (activity.contextItem instanceof Contact) {
|
||||||
activity.contact_context_id = acmi.position;
|
activity.getMenuInflater().inflate(R.menu.contact_context, menu);
|
||||||
final Contact contact = (Contact) activity.contacts.get(acmi.position);
|
final Contact contact = (Contact) activity.contextItem;
|
||||||
final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
|
final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
|
||||||
final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details);
|
final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details);
|
||||||
final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact);
|
final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
layout="@layout/toolbar" />
|
layout="@layout/toolbar" />
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
|
android:visibility="gone"
|
||||||
android:id="@+id/tab_layout"
|
android:id="@+id/tab_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue