mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 04:18:53 +01:00
Show when private messages have been delivered.
This commit is contained in:
@@ -24,8 +24,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -52,6 +54,7 @@ import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.event.MessageAddedEvent;
|
||||
import org.briarproject.api.event.MessageExpiredEvent;
|
||||
import org.briarproject.api.event.MessagesAckedEvent;
|
||||
import org.briarproject.api.messaging.Group;
|
||||
import org.briarproject.api.messaging.GroupId;
|
||||
import org.briarproject.api.messaging.Message;
|
||||
@@ -381,9 +384,33 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
} else if(e instanceof MessageExpiredEvent) {
|
||||
LOG.info("Message expired, reloading");
|
||||
loadHeaders();
|
||||
} else if(e instanceof MessagesAckedEvent) {
|
||||
MessagesAckedEvent m = (MessagesAckedEvent) e;
|
||||
if(m.getContactId().equals(contactId)) {
|
||||
LOG.info("Messages acked");
|
||||
markMessagesDelivered(m.getMessageIds());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void markMessagesDelivered(final Collection<MessageId> acked) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
Set<MessageId> ackedSet = new HashSet<MessageId>(acked);
|
||||
boolean changed = false;
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
ConversationItem item = adapter.getItem(i);
|
||||
if(ackedSet.contains(item.getHeader().getId())) {
|
||||
item.setDelivered(true);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if(changed) adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
String message = content.getText().toString();
|
||||
if(message.equals("")) return;
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package org.briarproject.android.contact;
|
||||
|
||||
import static android.view.Gravity.BOTTOM;
|
||||
import static android.view.Gravity.LEFT;
|
||||
import static android.view.Gravity.RIGHT;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.widget.LinearLayout.HORIZONTAL;
|
||||
import static android.widget.LinearLayout.VERTICAL;
|
||||
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.briarproject.R;
|
||||
import org.briarproject.android.util.ElasticHorizontalSpace;
|
||||
import org.briarproject.android.util.LayoutUtils;
|
||||
import org.briarproject.api.db.MessageHeader;
|
||||
import org.briarproject.util.StringUtils;
|
||||
@@ -19,6 +22,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -60,23 +64,45 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
||||
attachment.setImageResource(R.drawable.content_attachment);
|
||||
content = attachment;
|
||||
}
|
||||
content.setId(2);
|
||||
content.setLayoutParams(MATCH_WRAP);
|
||||
content.setBackgroundColor(background);
|
||||
content.setPadding(pad, pad, pad, 0);
|
||||
layout.addView(content);
|
||||
|
||||
TextView date = new TextView(ctx);
|
||||
date.setId(1);
|
||||
date.setLayoutParams(MATCH_WRAP);
|
||||
if(header.isLocal()) date.setGravity(RIGHT);
|
||||
else date.setGravity(LEFT);
|
||||
date.setTextColor(res.getColor(R.color.private_message_date));
|
||||
date.setBackgroundColor(background);
|
||||
date.setPadding(pad, 0, pad, pad);
|
||||
long timestamp = header.getTimestamp();
|
||||
date.setText(DateUtils.getRelativeTimeSpanString(ctx, timestamp));
|
||||
layout.addView(date);
|
||||
if(header.isLocal()) {
|
||||
LinearLayout footer = new LinearLayout(ctx);
|
||||
footer.setLayoutParams(MATCH_WRAP);
|
||||
footer.setOrientation(HORIZONTAL);
|
||||
footer.setGravity(BOTTOM);
|
||||
footer.setPadding(pad, 0, pad, pad);
|
||||
footer.setBackgroundColor(background);
|
||||
|
||||
footer.addView(new ElasticHorizontalSpace(ctx));
|
||||
|
||||
ImageView delivered = new ImageView(ctx);
|
||||
delivered.setPadding(0, 0, pad, 0);
|
||||
delivered.setImageResource(R.drawable.message_delivered);
|
||||
if(!item.isDelivered()) delivered.setVisibility(INVISIBLE);
|
||||
footer.addView(delivered);
|
||||
|
||||
TextView date = new TextView(ctx);
|
||||
date.setTextColor(res.getColor(R.color.private_message_date));
|
||||
long timestamp = header.getTimestamp();
|
||||
date.setText(DateUtils.getRelativeTimeSpanString(ctx, timestamp));
|
||||
footer.addView(date);
|
||||
|
||||
layout.addView(footer);
|
||||
} else {
|
||||
TextView date = new TextView(ctx);
|
||||
date.setLayoutParams(MATCH_WRAP);
|
||||
date.setGravity(LEFT);
|
||||
date.setTextColor(res.getColor(R.color.private_message_date));
|
||||
date.setBackgroundColor(background);
|
||||
date.setPadding(pad, 0, pad, pad);
|
||||
long timestamp = header.getTimestamp();
|
||||
date.setText(DateUtils.getRelativeTimeSpanString(ctx, timestamp));
|
||||
layout.addView(date);
|
||||
}
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ class ConversationItem {
|
||||
|
||||
private final MessageHeader header;
|
||||
private byte[] body;
|
||||
private boolean delivered;
|
||||
|
||||
ConversationItem(MessageHeader header) {
|
||||
this.header = header;
|
||||
body = null;
|
||||
delivered = header.isDelivered();
|
||||
}
|
||||
|
||||
MessageHeader getHeader() {
|
||||
@@ -24,4 +26,12 @@ class ConversationItem {
|
||||
void setBody(byte[] body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
boolean isDelivered() {
|
||||
return delivered;
|
||||
}
|
||||
|
||||
void setDelivered(boolean delivered) {
|
||||
this.delivered = delivered;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user