test: cover native chat chrome transitions
This commit is contained in:
@@ -50,6 +50,43 @@ public class ProjectDetailActivity extends BossScreenActivity {
|
||||
private ActivityResultLauncher<Intent> conversationInfoLauncher;
|
||||
private ActivityResultLauncher<Intent> forwardTargetLauncher;
|
||||
|
||||
static final class ChromeBindings {
|
||||
final boolean multiSelecting;
|
||||
final boolean showComposer;
|
||||
final boolean showMultiSelectBar;
|
||||
final boolean showRefresh;
|
||||
final boolean showHeaderAction;
|
||||
final boolean enableForwardButton;
|
||||
final boolean enablePullRefresh;
|
||||
final String backLabel;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
|
||||
ChromeBindings(
|
||||
boolean multiSelecting,
|
||||
boolean showComposer,
|
||||
boolean showMultiSelectBar,
|
||||
boolean showRefresh,
|
||||
boolean showHeaderAction,
|
||||
boolean enableForwardButton,
|
||||
boolean enablePullRefresh,
|
||||
String backLabel,
|
||||
String title,
|
||||
String subtitle
|
||||
) {
|
||||
this.multiSelecting = multiSelecting;
|
||||
this.showComposer = showComposer;
|
||||
this.showMultiSelectBar = showMultiSelectBar;
|
||||
this.showRefresh = showRefresh;
|
||||
this.showHeaderAction = showHeaderAction;
|
||||
this.enableForwardButton = enableForwardButton;
|
||||
this.enablePullRefresh = enablePullRefresh;
|
||||
this.backLabel = backLabel;
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_project_chat;
|
||||
@@ -467,30 +504,31 @@ public class ProjectDetailActivity extends BossScreenActivity {
|
||||
currentScreenTitle,
|
||||
currentScreenSubtitle
|
||||
);
|
||||
ChromeBindings bindings = buildChromeBindings(chromeState, isComposerBusy());
|
||||
if (composerRow != null) {
|
||||
composerRow.setVisibility(chromeState.showComposer ? View.VISIBLE : View.GONE);
|
||||
composerRow.setVisibility(bindings.showComposer ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
if (multiSelectActionsLayout != null) {
|
||||
multiSelectActionsLayout.setVisibility(chromeState.showMultiSelectBar ? View.VISIBLE : View.GONE);
|
||||
multiSelectActionsLayout.setVisibility(bindings.showMultiSelectBar ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
if (multiSelectForwardButton != null) {
|
||||
multiSelectForwardButton.setEnabled(!isComposerBusy() && chromeState.forwardEnabled);
|
||||
multiSelectForwardButton.setEnabled(bindings.enableForwardButton);
|
||||
}
|
||||
if (refreshLayout != null) {
|
||||
refreshLayout.setEnabled(!chromeState.multiSelecting);
|
||||
refreshLayout.setEnabled(bindings.enablePullRefresh);
|
||||
}
|
||||
backButton.setText(chromeState.backLabel);
|
||||
backButton.setText(bindings.backLabel);
|
||||
backButton.setOnClickListener(v -> {
|
||||
if (chromeState.multiSelecting) {
|
||||
if (bindings.multiSelecting) {
|
||||
exitMultiSelect();
|
||||
return;
|
||||
}
|
||||
finish();
|
||||
});
|
||||
refreshButton.setVisibility(chromeState.showRefresh ? View.VISIBLE : View.GONE);
|
||||
titleView.setText(chromeState.title);
|
||||
subtitleView.setText(chromeState.subtitle);
|
||||
if (chromeState.showHeaderAction) {
|
||||
refreshButton.setVisibility(bindings.showRefresh ? View.VISIBLE : View.GONE);
|
||||
titleView.setText(bindings.title);
|
||||
subtitleView.setText(bindings.subtitle);
|
||||
if (bindings.showHeaderAction) {
|
||||
setHeaderAction(WechatSurfaceMapper.conversationInfoActionLabel(), v -> openConversationInfo());
|
||||
} else {
|
||||
hideHeaderAction();
|
||||
@@ -663,6 +701,24 @@ public class ProjectDetailActivity extends BossScreenActivity {
|
||||
return message.optString("body", "转发的聊天记录");
|
||||
}
|
||||
|
||||
static ChromeBindings buildChromeBindings(
|
||||
ProjectChatUiState.ChromeState chromeState,
|
||||
boolean composerBusy
|
||||
) {
|
||||
return new ChromeBindings(
|
||||
chromeState.multiSelecting,
|
||||
chromeState.showComposer,
|
||||
chromeState.showMultiSelectBar,
|
||||
chromeState.showRefresh,
|
||||
chromeState.showHeaderAction,
|
||||
!composerBusy && chromeState.forwardEnabled,
|
||||
!chromeState.multiSelecting,
|
||||
chromeState.backLabel,
|
||||
chromeState.title,
|
||||
chromeState.subtitle
|
||||
);
|
||||
}
|
||||
|
||||
private List<String> collectMessageIds(@Nullable JSONArray messages) {
|
||||
ArrayList<String> ids = new ArrayList<>();
|
||||
if (messages == null) {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProjectDetailActivityChromeBindingsTest {
|
||||
@Test
|
||||
public void multiSelectBindingsHideComposerAndDisableRefresh() {
|
||||
ProjectChatUiState.SelectionState selectionState = ProjectChatUiState.selectOnly("m1");
|
||||
selectionState = ProjectChatUiState.toggleSelection(selectionState, "m2");
|
||||
ProjectChatUiState.ChromeState chromeState = ProjectChatUiState.resolveChromeState(
|
||||
selectionState,
|
||||
true,
|
||||
"北区试产线回归",
|
||||
"归档确认"
|
||||
);
|
||||
|
||||
ProjectDetailActivity.ChromeBindings bindings =
|
||||
ProjectDetailActivity.buildChromeBindings(chromeState, false);
|
||||
|
||||
assertTrue(bindings.multiSelecting);
|
||||
assertFalse(bindings.showComposer);
|
||||
assertTrue(bindings.showMultiSelectBar);
|
||||
assertFalse(bindings.showRefresh);
|
||||
assertFalse(bindings.showHeaderAction);
|
||||
assertTrue(bindings.enableForwardButton);
|
||||
assertFalse(bindings.enablePullRefresh);
|
||||
assertEquals("取消", bindings.backLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalBindingsRestoreConversationChrome() {
|
||||
ProjectChatUiState.ChromeState chromeState = ProjectChatUiState.resolveChromeState(
|
||||
ProjectChatUiState.emptySelection(),
|
||||
true,
|
||||
"北区试产线回归",
|
||||
"归档确认"
|
||||
);
|
||||
|
||||
ProjectDetailActivity.ChromeBindings bindings =
|
||||
ProjectDetailActivity.buildChromeBindings(chromeState, true);
|
||||
|
||||
assertFalse(bindings.multiSelecting);
|
||||
assertTrue(bindings.showComposer);
|
||||
assertFalse(bindings.showMultiSelectBar);
|
||||
assertTrue(bindings.showRefresh);
|
||||
assertTrue(bindings.showHeaderAction);
|
||||
assertFalse(bindings.enableForwardButton);
|
||||
assertTrue(bindings.enablePullRefresh);
|
||||
assertEquals("返回", bindings.backLabel);
|
||||
assertEquals("北区试产线回归", bindings.title);
|
||||
assertEquals("归档确认", bindings.subtitle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user