68 lines
2.3 KiB
Java
68 lines
2.3 KiB
Java
package com.hyzq.boss;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import java.util.Collections;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.Set;
|
|
|
|
public final class ProjectChatUiState {
|
|
private ProjectChatUiState() {}
|
|
|
|
public static final class SelectionState {
|
|
public final boolean multiSelecting;
|
|
public final Set<String> selectedMessageIds;
|
|
|
|
private SelectionState(Set<String> selectedMessageIds) {
|
|
LinkedHashSet<String> normalizedIds = new LinkedHashSet<>(selectedMessageIds);
|
|
this.multiSelecting = !normalizedIds.isEmpty();
|
|
this.selectedMessageIds = Collections.unmodifiableSet(normalizedIds);
|
|
}
|
|
}
|
|
|
|
public static boolean canSend(String text, boolean sending) {
|
|
return !sending && text != null && !text.trim().isEmpty();
|
|
}
|
|
|
|
public static boolean shouldAutoScroll(boolean nearBottom, boolean forced) {
|
|
return nearBottom || forced;
|
|
}
|
|
|
|
public static SelectionState emptySelection() {
|
|
return new SelectionState(new LinkedHashSet<>());
|
|
}
|
|
|
|
public static SelectionState selectOnly(String messageId) {
|
|
return toggleSelection(emptySelection(), messageId);
|
|
}
|
|
|
|
public static SelectionState toggleSelection(@Nullable SelectionState current, String messageId) {
|
|
if (messageId == null || messageId.trim().isEmpty()) {
|
|
throw new IllegalArgumentException("messageId must not be blank");
|
|
}
|
|
SelectionState state = current == null ? emptySelection() : current;
|
|
LinkedHashSet<String> selectedMessageIds = new LinkedHashSet<>(state.selectedMessageIds);
|
|
if (selectedMessageIds.contains(messageId)) {
|
|
selectedMessageIds.remove(messageId);
|
|
return new SelectionState(selectedMessageIds);
|
|
}
|
|
selectedMessageIds.add(messageId);
|
|
return new SelectionState(selectedMessageIds);
|
|
}
|
|
|
|
public static boolean canForwardSelection(@Nullable SelectionState state) {
|
|
return state != null && state.multiSelecting && state.selectedMessageIds.size() >= 2;
|
|
}
|
|
|
|
@Nullable
|
|
public static String labelForForwardKind(@Nullable String kind) {
|
|
if ("forward_single".equals(kind)) {
|
|
return "转发";
|
|
}
|
|
if ("forward_bundle".equals(kind)) {
|
|
return "聊天记录";
|
|
}
|
|
return null;
|
|
}
|
|
}
|