mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Use event instead of CommitAction to handle removed PendingContacts
This commit is contained in:
@@ -20,6 +20,7 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.contact.event.ContactAddedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
|
||||
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||
@@ -299,7 +300,8 @@ public class ContactListFragment extends BaseFragment implements EventListener,
|
||||
if (pe.getPendingContactState() == WAITING_FOR_CONNECTION) {
|
||||
checkForPendingContacts();
|
||||
}
|
||||
} else if (e instanceof ContactAddedRemotelyEvent) {
|
||||
} else if (e instanceof PendingContactRemovedEvent ||
|
||||
e instanceof ContactAddedRemotelyEvent) {
|
||||
checkForPendingContacts();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +86,7 @@ public class PendingContactListActivity extends BriarActivity
|
||||
|
||||
@Override
|
||||
public void onFailedPendingContactRemoved(PendingContact pendingContact) {
|
||||
viewModel.removePendingContact(pendingContact.getId(),
|
||||
() -> adapter.remove(pendingContact));
|
||||
viewModel.removePendingContact(pendingContact.getId());
|
||||
}
|
||||
|
||||
private void onPendingContactsChanged(Collection<PendingContact> contacts) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.briarproject.bramble.api.contact.ContactManager;
|
||||
import org.briarproject.bramble.api.contact.PendingContact;
|
||||
import org.briarproject.bramble.api.contact.PendingContactId;
|
||||
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent;
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent;
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
@@ -63,7 +64,8 @@ public class PendingContactListViewModel extends AndroidViewModel
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof ContactAddedRemotelyEvent ||
|
||||
e instanceof PendingContactStateChangedEvent) {
|
||||
e instanceof PendingContactStateChangedEvent ||
|
||||
e instanceof PendingContactRemovedEvent) {
|
||||
loadPendingContacts();
|
||||
}
|
||||
}
|
||||
@@ -82,16 +84,14 @@ public class PendingContactListViewModel extends AndroidViewModel
|
||||
return pendingContacts;
|
||||
}
|
||||
|
||||
void removePendingContact(PendingContactId id, Runnable commitAction) {
|
||||
void removePendingContact(PendingContactId id) {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
contactManager
|
||||
.removePendingContact(id, commitAction);
|
||||
contactManager.removePendingContact(id);
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
}
|
||||
});
|
||||
loadPendingContacts();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,8 +40,10 @@ class PendingContactViewHolder extends ViewHolder {
|
||||
avatar.setBackgroundBytes(item.getId().getBytes());
|
||||
name.setText(item.getAlias());
|
||||
time.setText(formatDate(time.getContext(), item.getTimestamp()));
|
||||
removeButton.setOnClickListener(
|
||||
v -> listener.onFailedPendingContactRemoved(item));
|
||||
removeButton.setOnClickListener(v -> {
|
||||
listener.onFailedPendingContactRemoved(item);
|
||||
removeButton.setEnabled(false);
|
||||
});
|
||||
|
||||
int color = ContextCompat
|
||||
.getColor(status.getContext(), R.color.briar_green);
|
||||
@@ -69,6 +71,7 @@ class PendingContactViewHolder extends ViewHolder {
|
||||
}
|
||||
status.setTextColor(color);
|
||||
removeButton.setVisibility(buttonVisibility);
|
||||
removeButton.setEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user