2014-02-15 11:28:07 -08:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2015-04-21 11:54:46 +02:00
|
|
|
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;
|
2019-03-11 16:40:26 -03:00
|
|
|
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;
|
2014-11-28 10:46:50 -08:00
|
|
|
|
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);
|
|
|
|
|
2020-04-22 14:19:44 -03:00
|
|
|
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);
|
|
|
|
}
|
2015-04-21 11:54:46 +02:00
|
|
|
}
|
|
|
|
|
2020-03-03 18:34:55 -04:00
|
|
|
//noinspection ConstantConditions
|
|
|
|
memberListView.setMembers(pendingMembers);
|
2019-10-31 13:20:55 -03:00
|
|
|
}
|
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
|
|
|
}
|