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"/>
<activity
android:name=".ui.SearchActivity"
android:label="@string/title_activity_search"/>
android:label="@string/search_messages"/>
<activity
android:name=".ui.RecordingActivity"
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);
messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList);
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;
if (received) {
if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
@ -949,30 +955,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return;
} else {
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);
return;
}
}
}
Account account = message.getConversation().getAccount();
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);
activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
});
messageListAdapter.setOnContactPictureLongClicked(message -> {
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.R;
import eu.siacs.conversations.databinding.ActivitySearchBinding;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.MessageSearchTask;
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.showKeyboard;
public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable {
public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable, MessageAdapter.OnContactPictureClicked {
private ActivitySearchBinding binding;
private MessageAdapter messageListAdapter;
@ -70,6 +71,7 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
setSupportActionBar((Toolbar) this.binding.toolbar);
configureActionBar(getSupportActionBar());
this.messageListAdapter = new MessageAdapter(this, this.messages);
this.messageListAdapter.setOnContactPictureClicked(this);
this.binding.searchResults.setAdapter(messageListAdapter);
}
@ -148,4 +150,26 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
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);
}
public void switchToAccount(Account account) {
switchToAccount(account, false);
public void switchToAccount(Account account, String fingerprint) {
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.putExtra("jid", account.getJid().asBareJid().toString());
intent.putExtra("init", init);
if (init) {
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);
if (init) {
overridePendingTransition(0, 0);

View File

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

View File

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

View File

@ -703,6 +703,5 @@
<string name="unable_to_start_recording">Unable to start recording</string>
<string name="please_wait">Please wait…</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>
</resources>