click on avatars in message search opens contact details

This commit is contained in:
Daniel Gultsch 2018-04-26 18:53:09 +02:00
parent e6feb91390
commit 3d243866a4
7 changed files with 45 additions and 27 deletions

View file

@ -62,7 +62,7 @@
android:label="@string/title_activity_share_location"/> android:label="@string/title_activity_share_location"/>
<activity <activity
android:name=".ui.SearchActivity" android:name=".ui.SearchActivity"
android:label="@string/title_activity_search"/> android:label="@string/search_messages"/>
<activity <activity
android:name=".ui.RecordingActivity" android:name=".ui.RecordingActivity"
android:theme="@style/ConversationsTheme.Dialog" android:theme="@style/ConversationsTheme.Dialog"

View file

@ -931,6 +931,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList); messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList);
messageListAdapter.setOnContactPictureClicked(message -> { messageListAdapter.setOnContactPictureClicked(message -> {
String fingerprint;
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
} else {
fingerprint = message.getFingerprint();
}
final boolean received = message.getStatus() <= Message.STATUS_RECEIVED; final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
if (received) { if (received) {
if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) { if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
@ -949,30 +955,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return; return;
} else { } else {
if (!message.getContact().isSelf()) { if (!message.getContact().isSelf()) {
String fingerprint;
if (message.getEncryption() == Message.ENCRYPTION_PGP
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
} else {
fingerprint = message.getFingerprint();
}
activity.switchToContactDetails(message.getContact(), fingerprint); activity.switchToContactDetails(message.getContact(), fingerprint);
return; return;
} }
} }
} }
Account account = message.getConversation().getAccount(); activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
Intent intent = new Intent(activity, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().asBareJid().toString());
String fingerprint;
if (message.getEncryption() == Message.ENCRYPTION_PGP
|| message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
} else {
fingerprint = message.getFingerprint();
}
intent.putExtra("fingerprint", fingerprint);
startActivity(intent);
}); });
messageListAdapter.setOnContactPictureLongClicked(message -> { messageListAdapter.setOnContactPictureLongClicked(message -> {
if (message.getStatus() <= Message.STATUS_RECEIVED) { if (message.getStatus() <= Message.STATUS_RECEIVED) {

View file

@ -46,6 +46,7 @@ import java.util.List;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivitySearchBinding; import eu.siacs.conversations.databinding.ActivitySearchBinding;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.MessageSearchTask; import eu.siacs.conversations.services.MessageSearchTask;
import eu.siacs.conversations.ui.adapter.MessageAdapter; import eu.siacs.conversations.ui.adapter.MessageAdapter;
@ -57,7 +58,7 @@ import eu.siacs.conversations.ui.util.ListViewUtils;
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard; import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.showKeyboard; import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.showKeyboard;
public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable { public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable, MessageAdapter.OnContactPictureClicked {
private ActivitySearchBinding binding; private ActivitySearchBinding binding;
private MessageAdapter messageListAdapter; private MessageAdapter messageListAdapter;
@ -70,6 +71,7 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
setSupportActionBar((Toolbar) this.binding.toolbar); setSupportActionBar((Toolbar) this.binding.toolbar);
configureActionBar(getSupportActionBar()); configureActionBar(getSupportActionBar());
this.messageListAdapter = new MessageAdapter(this, this.messages); this.messageListAdapter = new MessageAdapter(this, this.messages);
this.messageListAdapter.setOnContactPictureClicked(this);
this.binding.searchResults.setAdapter(messageListAdapter); this.binding.searchResults.setAdapter(messageListAdapter);
} }
@ -148,4 +150,26 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
ListViewUtils.scrollToBottom(this.binding.searchResults); ListViewUtils.scrollToBottom(this.binding.searchResults);
}); });
} }
@Override
public void onContactPictureClicked(Message message) {
String fingerprint;
if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
fingerprint = "pgp";
} else {
fingerprint = message.getFingerprint();
}
if (message.getStatus() == Message.STATUS_RECEIVED) {
final Contact contact = message.getContact();
if (contact != null) {
if (contact.isSelf()) {
switchToAccount(message.getConversation().getAccount(), fingerprint);
} else {
switchToContactDetails(contact, fingerprint);
}
}
} else {
switchToAccount(message.getConversation().getAccount(), fingerprint);
}
}
} }

View file

@ -521,17 +521,24 @@ public abstract class XmppActivity extends ActionBarActivity {
startActivity(intent); startActivity(intent);
} }
public void switchToAccount(Account account) { public void switchToAccount(Account account, String fingerprint) {
switchToAccount(account, false); switchToAccount(account, false, fingerprint);
} }
public void switchToAccount(Account account, boolean init) { public void switchToAccount(Account account) {
switchToAccount(account, false, null);
}
public void switchToAccount(Account account, boolean init, String fingerprint) {
Intent intent = new Intent(this, EditAccountActivity.class); Intent intent = new Intent(this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().asBareJid().toString()); intent.putExtra("jid", account.getJid().asBareJid().toString());
intent.putExtra("init", init); intent.putExtra("init", init);
if (init) { if (init) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
} }
if (fingerprint != null) {
intent.putExtra("fingerprint", fingerprint);
}
startActivity(intent); startActivity(intent);
if (init) { if (init) {
overridePendingTransition(0, 0); overridePendingTransition(0, 0);

View file

@ -36,7 +36,7 @@ import android.widget.ListView;
public class ListViewUtils { public class ListViewUtils {
public static void scrollToBottom(final ListView listView) { public static void scrollToBottom(final ListView listView) {
int count = listView.getAdapter().getCount(); final int count = listView.getAdapter().getCount();
if (count > 0) { if (count > 0) {
setSelection(listView, count - 1, true); setSelection(listView, count - 1, true);
} }

View file

@ -31,7 +31,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_search" android:id="@+id/action_search"
android:title="@string/title_activity_search" android:title="@string/search_messages"
android:orderInCategory="50" android:orderInCategory="50"
app:showAsAction="never"/> app:showAsAction="never"/>
</menu> </menu>

View file

@ -703,6 +703,5 @@
<string name="unable_to_start_recording">Unable to start recording</string> <string name="unable_to_start_recording">Unable to start recording</string>
<string name="please_wait">Please wait…</string> <string name="please_wait">Please wait…</string>
<string name="no_microphone_permission">Conversations needs access to the microphone</string> <string name="no_microphone_permission">Conversations needs access to the microphone</string>
<string name="title_activity_search">Search</string>
<string name="search_messages">Search messages</string> <string name="search_messages">Search messages</string>
</resources> </resources>