use of org.thoughtcrime.securesms.conversationlist.model.Conversation in project Signal-Android by WhisperSystems.
the class ConversationListDataSource method load.
@Override
@NonNull
public List<Conversation> load(int start, int length, @NonNull CancellationSignal cancellationSignal) {
Stopwatch stopwatch = new Stopwatch("load(" + start + ", " + length + "), " + getClass().getSimpleName());
List<Conversation> conversations = new ArrayList<>(length);
List<Recipient> recipients = new LinkedList<>();
try (ConversationReader reader = new ConversationReader(getCursor(start, length))) {
ThreadRecord record;
while ((record = reader.getNext()) != null && !cancellationSignal.isCanceled()) {
conversations.add(new Conversation(record));
recipients.add(record.getRecipient());
}
}
stopwatch.split("cursor");
ApplicationDependencies.getRecipientCache().addToCache(recipients);
stopwatch.split("cache-recipients");
stopwatch.stop(TAG);
return conversations;
}
use of org.thoughtcrime.securesms.conversationlist.model.Conversation in project Signal-Android by WhisperSystems.
the class ConversationListFragment method updateMultiSelectState.
private void updateMultiSelectState() {
int count = viewModel.currentSelectedConversations().size();
boolean hasUnread = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().isRead());
boolean hasUnpinned = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().isPinned());
boolean hasUnmuted = Stream.of(viewModel.currentSelectedConversations()).anyMatch(conversation -> !conversation.getThreadRecord().getRecipient().live().get().isMuted());
boolean canPin = viewModel.getPinnedCount() < MAXIMUM_PINNED_CONVERSATIONS;
if (actionMode != null) {
actionMode.setTitle(requireContext().getResources().getQuantityString(R.plurals.ConversationListFragment_s_selected, count, count));
}
List<ActionItem> items = new ArrayList<>();
Set<Long> selectionIds = viewModel.currentSelectedConversations().stream().map(conversation -> conversation.getThreadRecord().getThreadId()).collect(Collectors.toSet());
if (hasUnread) {
items.add(new ActionItem(R.drawable.ic_read_24, getResources().getQuantityString(R.plurals.ConversationListFragment_read_plural, count), () -> handleMarkAsRead(selectionIds)));
} else {
items.add(new ActionItem(R.drawable.ic_unread_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unread_plural, count), () -> handleMarkAsUnread(selectionIds)));
}
if (!isArchived() && hasUnpinned && canPin) {
items.add(new ActionItem(R.drawable.ic_pin_24, getResources().getQuantityString(R.plurals.ConversationListFragment_pin_plural, count), () -> handlePin(viewModel.currentSelectedConversations())));
} else if (!isArchived() && !hasUnpinned) {
items.add(new ActionItem(R.drawable.ic_unpin_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unpin_plural, count), () -> handleUnpin(selectionIds)));
}
if (isArchived()) {
items.add(new ActionItem(R.drawable.ic_unarchive_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unarchive_plural, count), () -> handleArchive(selectionIds, true)));
} else {
items.add(new ActionItem(R.drawable.ic_archive_24, getResources().getQuantityString(R.plurals.ConversationListFragment_archive_plural, count), () -> handleArchive(selectionIds, true)));
}
items.add(new ActionItem(R.drawable.ic_delete_24, getResources().getQuantityString(R.plurals.ConversationListFragment_delete_plural, count), () -> handleDelete(selectionIds)));
if (hasUnmuted) {
items.add(new ActionItem(R.drawable.ic_mute_24, getResources().getQuantityString(R.plurals.ConversationListFragment_mute_plural, count), () -> handleMute(viewModel.currentSelectedConversations())));
} else {
items.add(new ActionItem(R.drawable.ic_unmute_24, getResources().getQuantityString(R.plurals.ConversationListFragment_unmute_plural, count), () -> handleUnmute(viewModel.currentSelectedConversations())));
}
items.add(new ActionItem(R.drawable.ic_select_24, getString(R.string.ConversationListFragment_select_all), viewModel::onSelectAllClick));
bottomActionBar.setItems(items);
}
use of org.thoughtcrime.securesms.conversationlist.model.Conversation in project Signal-Android by WhisperSystems.
the class ConversationListFragment method handlePin.
private void handlePin(@NonNull Collection<Conversation> conversations) {
final Set<Long> toPin = new LinkedHashSet<>(Stream.of(conversations).filterNot(conversation -> conversation.getThreadRecord().isPinned()).map(conversation -> conversation.getThreadRecord().getThreadId()).toList());
if (toPin.size() + viewModel.getPinnedCount() > MAXIMUM_PINNED_CONVERSATIONS) {
Snackbar.make(fab, getString(R.string.conversation_list__you_can_only_pin_up_to_d_chats, MAXIMUM_PINNED_CONVERSATIONS), Snackbar.LENGTH_LONG).setTextColor(Color.WHITE).show();
endActionModeIfActive();
return;
}
SimpleTask.run(SignalExecutors.BOUNDED, () -> {
ThreadDatabase db = SignalDatabase.threads();
db.pinConversations(toPin);
return null;
}, unused -> {
endActionModeIfActive();
});
}
use of org.thoughtcrime.securesms.conversationlist.model.Conversation in project Signal-Android by WhisperSystems.
the class ConversationListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder.getItemViewType() == TYPE_ACTION || holder.getItemViewType() == TYPE_THREAD) {
ConversationViewHolder casted = (ConversationViewHolder) holder;
Conversation conversation = Objects.requireNonNull(getItem(position));
casted.getConversationListItem().bind(conversation.getThreadRecord(), glideRequests, Locale.getDefault(), typingSet, selectedConversations);
} else if (holder.getItemViewType() == TYPE_HEADER) {
HeaderViewHolder casted = (HeaderViewHolder) holder;
Conversation conversation = Objects.requireNonNull(getItem(position));
switch(conversation.getType()) {
case PINNED_HEADER:
casted.headerText.setText(R.string.conversation_list__pinned);
break;
case UNPINNED_HEADER:
casted.headerText.setText(R.string.conversation_list__chats);
break;
default:
throw new IllegalArgumentException();
}
}
}
Aggregations