add contact details for channels

(cherry picked from commit d8611fb838)
This commit is contained in:
Christian Schneppe 2022-09-19 17:48:30 +02:00 committed by Arne
parent f8fb3c07a8
commit c42d57a022
6 changed files with 262 additions and 1 deletions

View file

@ -322,6 +322,10 @@
android:name=".ui.ContactDetailsActivity"
android:label="@string/contact_details"
android:windowSoftInputMode="stateHidden" />
<activity
android:name=".ui.ConferenceContactDetailsActivity"
android:label="@string/contact_details"
android:windowSoftInputMode="stateHidden" />
<activity
android:name=".ui.PublishProfilePictureActivity"
android:label="@string/mgmt_account_publish_avatar"

View file

@ -0,0 +1,113 @@
package eu.siacs.conversations.ui;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;
import androidx.databinding.DataBindingUtil;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityMucContactDetailsBinding;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.ui.util.AvatarWorkerTask;
import eu.siacs.conversations.utils.IrregularUnicodeDetector;
import eu.siacs.conversations.xmpp.Jid;
public class ConferenceContactDetailsActivity extends XmppActivity {
public static final String ACTION_VIEW_CONTACT = "view_contact";
private Conversation mConversation;
ActivityMucContactDetailsBinding binding;
private Jid accountJid;
private Jid contactJid;
private MucOptions.User user = null;
@Override
protected void refreshUiReal() {
invalidateOptionsMenu();
populateView();
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
try {
this.accountJid = Jid.ofEscaped(getIntent().getExtras().getString(EXTRA_ACCOUNT));
} catch (final IllegalArgumentException ignored) {
}
try {
this.contactJid = Jid.ofEscaped(getIntent().getExtras().getString("user"));
} catch (final IllegalArgumentException ignored) {
}
}
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_muc_contact_details);
setSupportActionBar((Toolbar) binding.toolbar);
configureActionBar(getSupportActionBar());
}
@Override
public void onSaveInstanceState(final Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
}
}
private void populateView() {
if (getSupportActionBar() != null) {
final ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setCustomView(R.layout.ab_title);
ab.setDisplayShowCustomEnabled(true);
TextView abtitle = findViewById(android.R.id.text1);
TextView absubtitle = findViewById(android.R.id.text2);
abtitle.setText(R.string.contact_details);
abtitle.setSelected(true);
abtitle.setClickable(false);
absubtitle.setVisibility(View.GONE);
absubtitle.setClickable(false);
}
}
if (user == null) {
return;
}
binding.contactDisplayName.setText(user.getName());
binding.jid.setText(IrregularUnicodeDetector.style(this, contactJid));
String account = accountJid.asBareJid().toEscapedString();
binding.detailsAccount.setText(getString(R.string.using_account, account));
AvatarWorkerTask.loadAvatar(user, binding.detailsContactBadge, R.dimen.avatar_on_details_screen_size);
binding.detailsContactBadge.setOnLongClickListener(v -> {
ShowAvatarPopup(ConferenceContactDetailsActivity.this, user);
return true;
});
if (xmppConnectionService.multipleAccounts()) {
binding.detailsAccount.setVisibility(View.VISIBLE);
} else {
binding.detailsAccount.setVisibility(View.GONE);
}
}
public void onBackendConnected() {
if (accountJid != null && contactJid != null) {
Account account = xmppConnectionService.findAccountByJid(accountJid);
if (account == null) {
return;
}
this.mConversation = xmppConnectionService.findConversation(account, contactJid, false);
final MucOptions mucOptions = ((Conversation) this.mConversation).getMucOptions();
this.user = mucOptions.findUserByFullJid(contactJid);
populateView();
}
}
}

View file

@ -82,6 +82,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.AvatarService;
import eu.siacs.conversations.services.BarcodeProvider;
@ -653,6 +654,15 @@ public abstract class XmppActivity extends ActionBarActivity {
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
}
public void switchToMucContactDetails(MucOptions.User user) {
Intent intent = new Intent(this, ConferenceContactDetailsActivity.class);
intent.setAction(ContactDetailsActivity.ACTION_VIEW_CONTACT);
intent.putExtra(EXTRA_ACCOUNT, user.getAccount().getJid().asBareJid().toEscapedString());
intent.putExtra("user", user.getFullJid().toEscapedString());
startActivity(intent);
overridePendingTransition(R.animator.fade_in, R.animator.fade_out);
}
public void switchToAccount(Account account, String fingerprint) {
switchToAccount(account, false, fingerprint);
}

View file

@ -68,6 +68,8 @@ public final class MucDetailsContextMenuHelper {
MenuItem title = menu.findItem(R.id.title);
MenuItem showAvatar = menu.findItem(R.id.action_show_avatar);
showAvatar.setVisible(user != null);
MenuItem showMucContactDetails = menu.findItem(R.id.action_muc_contact_details);
showMucContactDetails.setVisible(user != null && user.getRealJid() == null);
if (forceContextMenu && username != null) {
SpannableStringBuilder menuTitle = new SpannableStringBuilder(username);
menuTitle.setSpan(new ForegroundColorSpan(titleColor), 0, menuTitle.length(), 0);
@ -182,6 +184,11 @@ public final class MucDetailsContextMenuHelper {
activity.switchToContactDetails(contact, fingerprint);
}
return true;
case R.id.action_muc_contact_details:
if (user != null) {
activity.switchToMucContactDetails(user);
}
return true;
case R.id.start_conversation:
startConversation(user, activity);
return true;
@ -217,7 +224,7 @@ public final class MucDetailsContextMenuHelper {
return true;
}
}
activity.privateMsgInMuc(conversation, user.getName());
activity.privateMsgInMuc(conversation, user.getAvatarName());
return true;
case R.id.invite:
if (user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) {

View file

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_tertiary"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/details_main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
card_view:cardBackgroundColor="?attr/color_background_secondary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/card_padding_regular">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/details_display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/details_contact_badge"
android:layout_width="@dimen/avatar_on_details_screen_size"
android:layout_height="@dimen/avatar_on_details_screen_size"
android:layout_marginEnd="@dimen/avatar_item_distance"
android:layout_marginRight="@dimen/avatar_item_distance"
android:padding="1dp"
android:scaleType="centerCrop"
app:riv_corner_radius="@dimen/rounded_image_border" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/contact_display_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Conversations.Title" />
<TextView
android:id="@+id/jid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account_settings_example_jabber_id"
android:textAppearance="@style/TextAppearance.Conversations.Body1"
android:textIsSelectable="true"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/card_padding_list">
<TextView
android:id="@+id/details_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="24dp"
android:text="@string/using_account"
android:textAppearance="@style/TextAppearance.Conversations.Caption"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
</ScrollView>
</LinearLayout>
</layout>

View file

@ -31,6 +31,11 @@
android:orderInCategory="100"
android:title="@string/action_contact_details"
android:visible="false" />
<item
android:id="@+id/action_muc_contact_details"
android:orderInCategory="100"
android:title="@string/action_contact_details"
android:visible="false" />
<item
android:id="@+id/invite"
android:orderInCategory="100"