mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Show recently polled pending contacts as "connecting".
This commit is contained in:
@@ -6,17 +6,24 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.bramble.api.contact.PendingContactState.CONNECTING;
|
||||
import static org.briarproject.bramble.api.contact.PendingContactState.WAITING_FOR_CONNECTION;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class PendingContactItem {
|
||||
|
||||
static final int POLL_DURATION_MS = 15_000;
|
||||
|
||||
private final PendingContact pendingContact;
|
||||
private final PendingContactState state;
|
||||
private final long lastPoll;
|
||||
|
||||
PendingContactItem(PendingContact pendingContact,
|
||||
PendingContactState state) {
|
||||
PendingContactState state, long lastPoll) {
|
||||
this.pendingContact = pendingContact;
|
||||
this.state = state;
|
||||
this.lastPoll = lastPoll;
|
||||
}
|
||||
|
||||
PendingContact getPendingContact() {
|
||||
@@ -24,6 +31,10 @@ class PendingContactItem {
|
||||
}
|
||||
|
||||
PendingContactState getState() {
|
||||
if (state == WAITING_FOR_CONNECTION &&
|
||||
System.currentTimeMillis() - lastPoll < POLL_DURATION_MS) {
|
||||
return CONNECTING;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.contact.PendingContactState.FAILED;
|
||||
import static org.briarproject.briar.android.contact.add.remote.PendingContactItem.POLL_DURATION_MS;
|
||||
|
||||
@MethodsNotNullByDefault
|
||||
@ParametersNotNullByDefault
|
||||
@@ -69,7 +70,7 @@ public class PendingContactListActivity extends BriarActivity
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
list.startPeriodicUpdate();
|
||||
list.startPeriodicUpdate(POLL_DURATION_MS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,9 @@ import org.briarproject.bramble.api.event.Event;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.event.EventListener;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.plugin.TorConstants;
|
||||
import org.briarproject.bramble.api.rendezvous.RendezvousPoller;
|
||||
import org.briarproject.bramble.api.rendezvous.event.RendezvousPollEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -41,6 +44,7 @@ public class PendingContactListViewModel extends AndroidViewModel
|
||||
@DatabaseExecutor
|
||||
private final Executor dbExecutor;
|
||||
private final ContactManager contactManager;
|
||||
private final RendezvousPoller rendezvousPoller;
|
||||
private final EventBus eventBus;
|
||||
|
||||
private final MutableLiveData<Collection<PendingContactItem>>
|
||||
@@ -49,10 +53,13 @@ public class PendingContactListViewModel extends AndroidViewModel
|
||||
@Inject
|
||||
PendingContactListViewModel(Application application,
|
||||
@DatabaseExecutor Executor dbExecutor,
|
||||
ContactManager contactManager, EventBus eventBus) {
|
||||
ContactManager contactManager,
|
||||
RendezvousPoller rendezvousPoller,
|
||||
EventBus eventBus) {
|
||||
super(application);
|
||||
this.dbExecutor = dbExecutor;
|
||||
this.contactManager = contactManager;
|
||||
this.rendezvousPoller = rendezvousPoller;
|
||||
this.eventBus = eventBus;
|
||||
this.eventBus.addListener(this);
|
||||
loadPendingContacts();
|
||||
@@ -67,7 +74,8 @@ public class PendingContactListViewModel extends AndroidViewModel
|
||||
@Override
|
||||
public void eventOccurred(Event e) {
|
||||
if (e instanceof PendingContactStateChangedEvent ||
|
||||
e instanceof PendingContactRemovedEvent) {
|
||||
e instanceof PendingContactRemovedEvent ||
|
||||
e instanceof RendezvousPollEvent) {
|
||||
loadPendingContacts();
|
||||
}
|
||||
}
|
||||
@@ -75,12 +83,14 @@ public class PendingContactListViewModel extends AndroidViewModel
|
||||
private void loadPendingContacts() {
|
||||
dbExecutor.execute(() -> {
|
||||
try {
|
||||
long lastPoll =
|
||||
rendezvousPoller.getLastPollTime(TorConstants.ID);
|
||||
Collection<Pair<PendingContact, PendingContactState>> pairs =
|
||||
contactManager.getPendingContacts();
|
||||
List<PendingContactItem> items = new ArrayList<>(pairs.size());
|
||||
for (Pair<PendingContact, PendingContactState> p : pairs) {
|
||||
items.add(new PendingContactItem(p.getFirst(),
|
||||
p.getSecond()));
|
||||
p.getSecond(), lastPoll));
|
||||
}
|
||||
pendingContacts.postValue(items);
|
||||
} catch (DbException e) {
|
||||
|
||||
@@ -211,15 +211,19 @@ public class BriarRecyclerView extends FrameLayout {
|
||||
}
|
||||
|
||||
public void startPeriodicUpdate() {
|
||||
startPeriodicUpdate(MIN_DATE_RESOLUTION);
|
||||
}
|
||||
|
||||
public void startPeriodicUpdate(long interval) {
|
||||
if (recyclerView == null || recyclerView.getAdapter() == null) {
|
||||
throw new IllegalStateException("Need to call setAdapter() first!");
|
||||
}
|
||||
refresher = () -> {
|
||||
Adapter adapter = recyclerView.getAdapter();
|
||||
adapter.notifyItemRangeChanged(0, adapter.getItemCount());
|
||||
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
|
||||
handler.postDelayed(refresher, interval);
|
||||
};
|
||||
handler.postDelayed(refresher, MIN_DATE_RESOLUTION);
|
||||
handler.postDelayed(refresher, interval);
|
||||
}
|
||||
|
||||
public void stopPeriodicUpdate() {
|
||||
|
||||
Reference in New Issue
Block a user