mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 14:19:53 +01:00
Remove PartialItem interface and the need for casting ConversationItems
This commit is contained in:
@@ -29,7 +29,6 @@ import org.briarproject.android.ActivityComponent;
|
|||||||
import org.briarproject.android.BriarActivity;
|
import org.briarproject.android.BriarActivity;
|
||||||
import org.briarproject.android.api.AndroidNotificationManager;
|
import org.briarproject.android.api.AndroidNotificationManager;
|
||||||
import org.briarproject.android.contact.ConversationAdapter.RequestListener;
|
import org.briarproject.android.contact.ConversationAdapter.RequestListener;
|
||||||
import org.briarproject.android.contact.ConversationItem.PartialItem;
|
|
||||||
import org.briarproject.android.introduction.IntroductionActivity;
|
import org.briarproject.android.introduction.IntroductionActivity;
|
||||||
import org.briarproject.android.view.BriarRecyclerView;
|
import org.briarproject.android.view.BriarRecyclerView;
|
||||||
import org.briarproject.android.view.TextInputView;
|
import org.briarproject.android.view.TextInputView;
|
||||||
@@ -413,7 +412,7 @@ public class ConversationActivity extends BriarActivity
|
|||||||
ConversationItem item = ConversationItem.from(h);
|
ConversationItem item = ConversationItem.from(h);
|
||||||
String body = bodyCache.get(h.getId());
|
String body = bodyCache.get(h.getId());
|
||||||
if (body == null) loadMessageBody(h.getId());
|
if (body == null) loadMessageBody(h.getId());
|
||||||
else ((PartialItem) item).setText(body);
|
else item.setBody(body);
|
||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
for (IntroductionMessage m : introductions) {
|
for (IntroductionMessage m : introductions) {
|
||||||
@@ -474,7 +473,7 @@ public class ConversationActivity extends BriarActivity
|
|||||||
for (int i = 0; i < messages.size(); i++) {
|
for (int i = 0; i < messages.size(); i++) {
|
||||||
ConversationItem item = messages.valueAt(i);
|
ConversationItem item = messages.valueAt(i);
|
||||||
if (item.getId().equals(m)) {
|
if (item.getId().equals(m)) {
|
||||||
((PartialItem) item).setText(body);
|
item.setBody(body);
|
||||||
adapter.notifyItemChanged(messages.keyAt(i));
|
adapter.notifyItemChanged(messages.keyAt(i));
|
||||||
list.scrollToPosition(adapter.getItemCount() - 1);
|
list.scrollToPosition(adapter.getItemCount() - 1);
|
||||||
return;
|
return;
|
||||||
@@ -681,7 +680,7 @@ public class ConversationActivity extends BriarActivity
|
|||||||
groupId, m.getMessage().getTimestamp(),
|
groupId, m.getMessage().getTimestamp(),
|
||||||
m.getContentType(), true, false, false, false);
|
m.getContentType(), true, false, false, false);
|
||||||
ConversationItem item = ConversationItem.from(h);
|
ConversationItem item = ConversationItem.from(h);
|
||||||
((PartialItem) item).setText(body);
|
item.setBody(body);
|
||||||
bodyCache.put(id, body);
|
bodyCache.put(id, body);
|
||||||
addConversationItem(item);
|
addConversationItem(item);
|
||||||
} catch (DbException e) {
|
} catch (DbException e) {
|
||||||
|
|||||||
@@ -33,16 +33,16 @@ import static org.briarproject.android.contact.ConversationRequestItem.RequestTy
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
abstract class ConversationItem {
|
abstract class ConversationItem {
|
||||||
|
|
||||||
protected @Nullable String text;
|
protected @Nullable String body;
|
||||||
final private MessageId id;
|
final private MessageId id;
|
||||||
final private GroupId groupId;
|
final private GroupId groupId;
|
||||||
final private long time;
|
final private long time;
|
||||||
|
|
||||||
ConversationItem(MessageId id, GroupId groupId,
|
ConversationItem(MessageId id, GroupId groupId,
|
||||||
@Nullable String text, long time) {
|
@Nullable String body, long time) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.groupId = groupId;
|
this.groupId = groupId;
|
||||||
this.text = text;
|
this.body = body;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +54,13 @@ abstract class ConversationItem {
|
|||||||
return groupId;
|
return groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setBody(String body) {
|
||||||
|
this.body = body;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getText() {
|
public String getBody() {
|
||||||
return text;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getTime() {
|
long getTime() {
|
||||||
@@ -279,13 +283,4 @@ abstract class ConversationItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PartialItem {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
String getText();
|
|
||||||
|
|
||||||
void setText(String text);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ class ConversationItemViewHolder extends ViewHolder {
|
|||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
void bind(ConversationItem item) {
|
void bind(ConversationItem item) {
|
||||||
if (item.getText() == null) {
|
if (item.getBody() == null) {
|
||||||
text.setText("\u2026");
|
text.setText("\u2026");
|
||||||
} else {
|
} else {
|
||||||
text.setText(StringUtils.trim(item.getText()));
|
text.setText(StringUtils.trim(item.getBody()));
|
||||||
}
|
}
|
||||||
|
|
||||||
long timestamp = item.getTime();
|
long timestamp = item.getTime();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.android.contact;
|
package org.briarproject.android.contact;
|
||||||
|
|
||||||
import org.briarproject.android.contact.ConversationItem.PartialItem;
|
|
||||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
@@ -8,15 +7,10 @@ import javax.annotation.concurrent.NotThreadSafe;
|
|||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ConversationMessageInItem extends ConversationInItem
|
class ConversationMessageInItem extends ConversationInItem {
|
||||||
implements PartialItem {
|
|
||||||
|
|
||||||
ConversationMessageInItem(PrivateMessageHeader h) {
|
ConversationMessageInItem(PrivateMessageHeader h) {
|
||||||
super(h.getId(), h.getGroupId(), null, h.getTimestamp(), h.isRead());
|
super(h.getId(), h.getGroupId(), null, h.getTimestamp(), h.isRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String body) {
|
|
||||||
text = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.briarproject.android.contact;
|
package org.briarproject.android.contact;
|
||||||
|
|
||||||
import org.briarproject.android.contact.ConversationItem.PartialItem;
|
|
||||||
import org.briarproject.api.messaging.PrivateMessageHeader;
|
import org.briarproject.api.messaging.PrivateMessageHeader;
|
||||||
import org.briarproject.api.nullsafety.NotNullByDefault;
|
import org.briarproject.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
@@ -8,16 +7,11 @@ import javax.annotation.concurrent.NotThreadSafe;
|
|||||||
|
|
||||||
@NotThreadSafe
|
@NotThreadSafe
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
class ConversationMessageOutItem extends ConversationOutItem
|
class ConversationMessageOutItem extends ConversationOutItem {
|
||||||
implements PartialItem {
|
|
||||||
|
|
||||||
ConversationMessageOutItem(PrivateMessageHeader h) {
|
ConversationMessageOutItem(PrivateMessageHeader h) {
|
||||||
super(h.getId(), h.getGroupId(), null, h.getTimestamp(), h.isSent(),
|
super(h.getId(), h.getGroupId(), null, h.getTimestamp(), h.isSent(),
|
||||||
h.isSeen());
|
h.isSeen());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String body) {
|
|
||||||
text = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user