Signal-Android/app/src/main/java/org/thoughtcrime/securesms/GroupMembersDialog.java

79 lines
3 KiB
Java
Raw Normal View History

2014-02-15 11:28:07 -08:00
package org.thoughtcrime.securesms;
import android.content.Intent;
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-03-03 18:34:55 -04:00
import androidx.lifecycle.Lifecycle;
2014-02-15 11:28:07 -08:00
import org.thoughtcrime.securesms.database.DatabaseFactory;
2020-03-27 15:55:44 -03:00
import org.thoughtcrime.securesms.database.GroupDatabase;
2020-04-22 16:25:28 -03:00
import org.thoughtcrime.securesms.groups.GroupId;
2020-03-03 18:34:55 -04:00
import org.thoughtcrime.securesms.groups.ui.GroupMemberEntry;
import org.thoughtcrime.securesms.groups.ui.GroupMemberListView;
2014-02-15 11:28:07 -08:00
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientExporter;
2020-04-22 16:25:28 -03:00
import org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment;
2020-03-03 18:34:55 -04:00
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
2020-03-03 18:34:55 -04:00
import java.util.ArrayList;
2014-02-15 11:28:07 -08:00
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;
private final Lifecycle lifecycle;
2014-02-15 11:28:07 -08:00
2020-04-22 16:25:28 -03:00
public GroupMembersDialog(@NonNull FragmentActivity activity,
2020-03-03 18:34:55 -04:00
@NonNull Recipient groupRecipient,
@NonNull Lifecycle lifecycle)
{
2020-04-22 16:25:28 -03:00
this.fragmentActivity = activity;
this.groupRecipient = groupRecipient;
this.lifecycle = lifecycle;
2014-02-15 11:28:07 -08:00
}
public void display() {
2020-03-03 18:34:55 -04:00
SimpleTask.run(
lifecycle,
2020-04-22 16:25:28 -03:00
() -> DatabaseFactory.getGroupDatabase(fragmentActivity).getGroupMembers(groupRecipient.requireGroupId(), GroupDatabase.MemberSet.FULL_MEMBERS_INCLUDING_SELF),
2020-03-03 18:34:55 -04:00
members -> {
2020-04-22 16:25:28 -03:00
AlertDialog dialog = new AlertDialog.Builder(fragmentActivity)
2020-03-03 18:34:55 -04:00
.setTitle(R.string.ConversationActivity_group_members)
.setIconAttribute(R.attr.group_members_dialog_icon)
.setCancelable(true)
.setView(R.layout.dialog_group_members)
.setPositiveButton(android.R.string.ok, null)
.show();
GroupMemberListView memberListView = dialog.findViewById(R.id.list_members);
ArrayList<GroupMemberEntry.FullMember> pendingMembers = new ArrayList<>(members.size());
for (Recipient member : members) {
GroupMemberEntry.FullMember entry = new GroupMemberEntry.FullMember(member);
entry.setOnClick(() -> {
dialog.dismiss();
contactClick(member);
});
2020-03-03 18:34:55 -04:00
if (member.isLocalNumber()) {
pendingMembers.add(0, entry);
} else {
pendingMembers.add(entry);
}
}
2020-03-03 18:34:55 -04:00
//noinspection ConstantConditions
memberListView.setMembers(pendingMembers);
}
2020-03-03 18:34:55 -04:00
);
}
2020-03-03 18:34:55 -04:00
private void contactClick(@NonNull Recipient recipient) {
RecipientBottomSheetDialogFragment.create(recipient.getId(), groupRecipient.requireGroupId())
.show(fragmentActivity.getSupportFragmentManager(), "BOTTOM");
}
2014-02-15 11:28:07 -08:00
}