2014-02-15 11:28:07 -08:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2020-03-03 18:34:55 -04:00
|
|
|
import androidx.annotation.NonNull;
|
2019-06-05 15:47:14 -04:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2020-04-22 16:25:28 -03:00
|
|
|
import androidx.fragment.app.FragmentActivity;
|
2020-04-30 15:38:58 -03:00
|
|
|
import androidx.lifecycle.LiveData;
|
2014-02-15 11:28:07 -08:00
|
|
|
|
2020-04-27 16:27:31 -03:00
|
|
|
import org.thoughtcrime.securesms.groups.LiveGroup;
|
2020-04-30 15:38:58 -03:00
|
|
|
import org.thoughtcrime.securesms.groups.ui.GroupMemberEntry;
|
2020-03-03 18:34:55 -04:00
|
|
|
import org.thoughtcrime.securesms.groups.ui.GroupMemberListView;
|
2014-02-15 11:28:07 -08:00
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
2020-04-22 16:25:28 -03:00
|
|
|
import org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment;
|
2014-02-15 11:28:07 -08:00
|
|
|
|
2020-04-30 15:38:58 -03:00
|
|
|
import java.util.List;
|
|
|
|
|
2020-03-03 18:34:55 -04:00
|
|
|
public final class GroupMembersDialog {
|
2014-02-15 11:28:07 -08:00
|
|
|
|
2020-04-22 16:25:28 -03:00
|
|
|
private final FragmentActivity fragmentActivity;
|
|
|
|
private final Recipient groupRecipient;
|
2014-02-15 11:28:07 -08:00
|
|
|
|
2020-04-22 16:25:28 -03:00
|
|
|
public GroupMembersDialog(@NonNull FragmentActivity activity,
|
2020-04-27 16:27:31 -03:00
|
|
|
@NonNull Recipient groupRecipient)
|
2020-03-03 18:34:55 -04:00
|
|
|
{
|
2020-04-22 16:25:28 -03:00
|
|
|
this.fragmentActivity = activity;
|
|
|
|
this.groupRecipient = groupRecipient;
|
2014-02-15 11:28:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void display() {
|
2020-04-30 15:38:58 -03:00
|
|
|
AlertDialog dialog = new AlertDialog.Builder(fragmentActivity)
|
|
|
|
.setTitle(R.string.ConversationActivity_group_members)
|
2020-11-10 10:20:54 -05:00
|
|
|
.setIcon(R.drawable.ic_group_24)
|
2020-04-30 15:38:58 -03:00
|
|
|
.setCancelable(true)
|
|
|
|
.setView(R.layout.dialog_group_members)
|
|
|
|
.setPositiveButton(android.R.string.ok, null)
|
|
|
|
.show();
|
2020-03-03 18:34:55 -04:00
|
|
|
|
2020-04-30 15:38:58 -03:00
|
|
|
GroupMemberListView memberListView = dialog.findViewById(R.id.list_members);
|
2021-11-17 11:39:12 -04:00
|
|
|
memberListView.initializeAdapter(fragmentActivity);
|
2020-03-03 18:34:55 -04:00
|
|
|
|
2020-04-30 15:38:58 -03:00
|
|
|
LiveGroup liveGroup = new LiveGroup(groupRecipient.requireGroupId());
|
|
|
|
LiveData<List<GroupMemberEntry.FullMember>> fullMembers = liveGroup.getFullMembers();
|
2020-03-03 18:34:55 -04:00
|
|
|
|
2020-04-30 15:38:58 -03:00
|
|
|
//noinspection ConstantConditions
|
|
|
|
fullMembers.observe(fragmentActivity, memberListView::setMembers);
|
2020-03-03 18:34:55 -04:00
|
|
|
|
2020-04-30 15:38:58 -03:00
|
|
|
dialog.setOnDismissListener(d -> fullMembers.removeObservers(fragmentActivity));
|
2015-04-21 11:54:46 +02:00
|
|
|
|
2020-04-30 15:38:58 -03:00
|
|
|
memberListView.setRecipientClickListener(recipient -> {
|
|
|
|
dialog.dismiss();
|
|
|
|
contactClick(recipient);
|
|
|
|
});
|
2020-03-03 18:34:55 -04:00
|
|
|
}
|
2019-10-31 13:20:55 -03:00
|
|
|
|
2020-03-03 18:34:55 -04:00
|
|
|
private void contactClick(@NonNull Recipient recipient) {
|
2020-04-27 13:08:06 -03:00
|
|
|
RecipientBottomSheetDialogFragment.create(recipient.getId(), groupRecipient.requireGroupId())
|
|
|
|
.show(fragmentActivity.getSupportFragmentManager(), "BOTTOM");
|
2014-11-28 10:46:50 -08:00
|
|
|
}
|
2014-02-15 11:28:07 -08:00
|
|
|
}
|