Do not cache locale in each conversation object.

Fixes #9751
This commit is contained in:
Fumiaki Yoshimatsu 2020-06-18 09:40:23 -04:00 committed by Greyson Parrelli
parent b262efc24c
commit 66f2668326
3 changed files with 6 additions and 19 deletions

View File

@ -141,7 +141,7 @@ class ConversationListAdapter extends PagedListAdapter<Conversation, RecyclerVie
casted.getConversationListItem().bind(conversation.getThreadRecord(), casted.getConversationListItem().bind(conversation.getThreadRecord(),
glideRequests, glideRequests,
conversation.getLocale(), Locale.getDefault(),
typingSet, typingSet,
getBatchSelectionIds(), getBatchSelectionIds(),
batchMode); batchMode);

View File

@ -20,7 +20,6 @@ import org.thoughtcrime.securesms.util.paging.SizeFixResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
abstract class ConversationListDataSource extends PositionalDataSource<Conversation> { abstract class ConversationListDataSource extends PositionalDataSource<Conversation> {
@ -60,14 +59,13 @@ abstract class ConversationListDataSource extends PositionalDataSource<Conversat
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
List<Conversation> conversations = new ArrayList<>(params.requestedLoadSize); List<Conversation> conversations = new ArrayList<>(params.requestedLoadSize);
Locale locale = Locale.getDefault();
int totalCount = getTotalCount(); int totalCount = getTotalCount();
int effectiveCount = params.requestedStartPosition; int effectiveCount = params.requestedStartPosition;
try (ThreadDatabase.Reader reader = threadDatabase.readerFor(getCursor(params.requestedStartPosition, params.requestedLoadSize))) { try (ThreadDatabase.Reader reader = threadDatabase.readerFor(getCursor(params.requestedStartPosition, params.requestedLoadSize))) {
ThreadRecord record; ThreadRecord record;
while ((record = reader.getNext()) != null && effectiveCount < totalCount && !isInvalid()) { while ((record = reader.getNext()) != null && effectiveCount < totalCount && !isInvalid()) {
conversations.add(new Conversation(record, locale)); conversations.add(new Conversation(record));
effectiveCount++; effectiveCount++;
} }
} }
@ -86,12 +84,11 @@ abstract class ConversationListDataSource extends PositionalDataSource<Conversat
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
List<Conversation> conversations = new ArrayList<>(params.loadSize); List<Conversation> conversations = new ArrayList<>(params.loadSize);
Locale locale = Locale.getDefault();
try (ThreadDatabase.Reader reader = threadDatabase.readerFor(getCursor(params.startPosition, params.loadSize))) { try (ThreadDatabase.Reader reader = threadDatabase.readerFor(getCursor(params.startPosition, params.loadSize))) {
ThreadRecord record; ThreadRecord record;
while ((record = reader.getNext()) != null && !isInvalid()) { while ((record = reader.getNext()) != null && !isInvalid()) {
conversations.add(new Conversation(record, locale)); conversations.add(new Conversation(record));
} }
} }

View File

@ -4,37 +4,27 @@ import androidx.annotation.NonNull;
import org.thoughtcrime.securesms.database.model.ThreadRecord; import org.thoughtcrime.securesms.database.model.ThreadRecord;
import java.util.Locale;
import java.util.Objects;
public class Conversation { public class Conversation {
private final ThreadRecord threadRecord; private final ThreadRecord threadRecord;
private final Locale locale;
public Conversation(@NonNull ThreadRecord threadRecord, @NonNull Locale locale) { public Conversation(@NonNull ThreadRecord threadRecord) {
this.threadRecord = threadRecord; this.threadRecord = threadRecord;
this.locale = locale;
} }
public @NonNull ThreadRecord getThreadRecord() { public @NonNull ThreadRecord getThreadRecord() {
return threadRecord; return threadRecord;
} }
public @NonNull Locale getLocale() {
return locale;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Conversation that = (Conversation) o; Conversation that = (Conversation) o;
return threadRecord.equals(that.threadRecord) && return threadRecord.equals(that.threadRecord);
locale.equals(that.locale);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(threadRecord, locale); return threadRecord.hashCode();
} }
} }