mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 21:29:54 +01:00
[android] Use ordinary HashMap for to be received attachments
Also don't do list stacking from end for now.
This commit is contained in:
@@ -260,7 +260,6 @@ public class ConversationActivity extends BriarActivity
|
|||||||
adapter = new ConversationAdapter(this, this);
|
adapter = new ConversationAdapter(this, this);
|
||||||
list = findViewById(R.id.conversationView);
|
list = findViewById(R.id.conversationView);
|
||||||
layoutManager = new LinearLayoutManager(this);
|
layoutManager = new LinearLayoutManager(this);
|
||||||
layoutManager.setStackFromEnd(true);
|
|
||||||
list.setLayoutManager(layoutManager);
|
list.setLayoutManager(layoutManager);
|
||||||
list.setAdapter(adapter);
|
list.setAdapter(adapter);
|
||||||
list.setEmptyText(getString(R.string.no_private_messages));
|
list.setEmptyText(getString(R.string.no_private_messages));
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ import java.io.InputStream;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -60,9 +60,9 @@ public class ImageViewModel extends AndroidViewModel implements EventListener {
|
|||||||
@IoExecutor
|
@IoExecutor
|
||||||
private final Executor ioExecutor;
|
private final Executor ioExecutor;
|
||||||
|
|
||||||
private volatile boolean receivedAttachmentsInitialized = false;
|
private boolean receivedAttachmentsInitialized = false;
|
||||||
private ConcurrentHashMap<MessageId, MutableLiveEvent<Boolean>>
|
private HashMap<MessageId, MutableLiveEvent<Boolean>> receivedAttachments =
|
||||||
receivedAttachments = new ConcurrentHashMap<>();
|
new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true means there was an error saving the image, false if image was saved.
|
* true means there was an error saving the image, false if image was saved.
|
||||||
@@ -93,6 +93,7 @@ public class ImageViewModel extends AndroidViewModel implements EventListener {
|
|||||||
eventBus.removeListener(this);
|
eventBus.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UiThread
|
||||||
@Override
|
@Override
|
||||||
public void eventOccurred(Event e) {
|
public void eventOccurred(Event e) {
|
||||||
if (e instanceof AttachmentReceivedEvent) {
|
if (e instanceof AttachmentReceivedEvent) {
|
||||||
@@ -100,11 +101,10 @@ public class ImageViewModel extends AndroidViewModel implements EventListener {
|
|||||||
MutableLiveEvent<Boolean> oldEvent;
|
MutableLiveEvent<Boolean> oldEvent;
|
||||||
if (receivedAttachmentsInitialized) {
|
if (receivedAttachmentsInitialized) {
|
||||||
oldEvent = receivedAttachments.get(id);
|
oldEvent = receivedAttachments.get(id);
|
||||||
|
if (oldEvent != null) oldEvent.postEvent(true);
|
||||||
} else {
|
} else {
|
||||||
oldEvent = receivedAttachments
|
receivedAttachments.put(id, new MutableLiveEvent<>(true));
|
||||||
.putIfAbsent(id, new MutableLiveEvent<>(true));
|
|
||||||
}
|
}
|
||||||
if (oldEvent != null) oldEvent.postEvent(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,18 +113,21 @@ public class ImageViewModel extends AndroidViewModel implements EventListener {
|
|||||||
for (AttachmentItem item : attachments) {
|
for (AttachmentItem item : attachments) {
|
||||||
// no need to track items that are in a final state already
|
// no need to track items that are in a final state already
|
||||||
if (item.getState().isFinal()) continue;
|
if (item.getState().isFinal()) continue;
|
||||||
// add new live events, if not added concurrently by Event
|
// add new live events, if not already added by eventOccurred()
|
||||||
MessageId id = item.getMessageId();
|
MessageId id = item.getMessageId();
|
||||||
receivedAttachments.putIfAbsent(id, new MutableLiveEvent<>());
|
if (!receivedAttachments.containsKey(id)) {
|
||||||
|
receivedAttachments.put(id, new MutableLiveEvent<>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
receivedAttachmentsInitialized = true;
|
receivedAttachmentsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a LiveData for attachments in a non-final state.
|
||||||
|
* Note that you need to call {@link #expectAttachments(List)} first.
|
||||||
|
*/
|
||||||
@UiThread
|
@UiThread
|
||||||
LiveEvent<Boolean> getOnAttachmentReceived(MessageId messageId) {
|
LiveEvent<Boolean> getOnAttachmentReceived(MessageId messageId) {
|
||||||
if (receivedAttachments.size() == 0) {
|
|
||||||
throw new IllegalStateException("expectAttachments() not called");
|
|
||||||
}
|
|
||||||
return requireNonNull(receivedAttachments.get(messageId));
|
return requireNonNull(receivedAttachments.get(messageId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user