mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| deb4e356bd | |||
| 88d6992a9e | |||
| 5e6b09031a | |||
| 115ebf52b6 |
@@ -23,7 +23,9 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Activity container for selecting a list of contacts.
|
||||
@@ -34,6 +36,9 @@ import java.util.List;
|
||||
public class ContactMultiSelectionActivity extends ContactSelectionActivity {
|
||||
|
||||
public static final String CONTACTS_EXTRA = "contacts_extra";
|
||||
public static final String REMOVED_CONTACTS_EXTRA = "removed_contacts_extra";
|
||||
|
||||
private ArrayList<Integer> preselectedContacts;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle, boolean ready) {
|
||||
@@ -44,6 +49,9 @@ public class ContactMultiSelectionActivity extends ContactSelectionActivity {
|
||||
// it's a bit confusing having one "X" button on the left and one on the right -
|
||||
// and the "clear search" button is not that important.
|
||||
getToolbar().setUseClearButton(false);
|
||||
|
||||
// Store preselected contacts to track which ones were removed
|
||||
preselectedContacts = getIntent().getIntegerArrayListExtra(ContactSelectionListFragment.PRESELECTED_CONTACTS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,6 +80,19 @@ public class ContactMultiSelectionActivity extends ContactSelectionActivity {
|
||||
Intent resultIntent = getIntent();
|
||||
List<Integer> selectedContacts = contactsFragment.getSelectedContacts();
|
||||
resultIntent.putIntegerArrayListExtra(CONTACTS_EXTRA, new ArrayList<>(selectedContacts));
|
||||
|
||||
// Calculate which contacts were removed (preselected but not in final selection)
|
||||
if (preselectedContacts != null) {
|
||||
Set<Integer> selectedSet = new HashSet<>(selectedContacts);
|
||||
ArrayList<Integer> removedContacts = new ArrayList<>();
|
||||
for (Integer preselectedId : preselectedContacts) {
|
||||
if (!selectedSet.contains(preselectedId)) {
|
||||
removedContacts.add(preselectedId);
|
||||
}
|
||||
}
|
||||
resultIntent.putIntegerArrayListExtra(REMOVED_CONTACTS_EXTRA, removedContacts);
|
||||
}
|
||||
|
||||
setResult(RESULT_OK, resultIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,13 +310,24 @@ public class ProfileFragment extends Fragment
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode==REQUEST_CODE_PICK_CONTACT && resultCode==Activity.RESULT_OK && data!=null) {
|
||||
List<Integer> selected = data.getIntegerArrayListExtra(ContactMultiSelectionActivity.CONTACTS_EXTRA);
|
||||
List<Integer> removed = data.getIntegerArrayListExtra(ContactMultiSelectionActivity.REMOVED_CONTACTS_EXTRA);
|
||||
if(selected == null) return;
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
// Add new members
|
||||
for (Integer contactId : selected) {
|
||||
if (contactId!=null) {
|
||||
if (contactId != null) {
|
||||
dcContext.addContactToChat(chatId, contactId);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove members that were explicitly unchecked
|
||||
if (removed != null) {
|
||||
for (Integer contactId : removed) {
|
||||
if (contactId != null) {
|
||||
dcContext.removeContactFromChat(chatId, contactId);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user