fix: restore native conversation row text layout
This commit is contained in:
@@ -570,7 +570,7 @@ public final class BossUi {
|
||||
trailingColumn.setGravity(Gravity.END);
|
||||
trailingColumn.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
|
||||
if (!TextUtils.isEmpty(row.topPinnedLabel)) {
|
||||
@@ -581,6 +581,10 @@ public final class BossUi {
|
||||
pinnedView.setTextColor(context.getColor(R.color.boss_green));
|
||||
pinnedView.setBackground(createRoundedBackground(Color.parseColor("#E7F7EE"), dp(context, 9)));
|
||||
pinnedView.setPadding(dp(context, 7), dp(context, 3), dp(context, 7), dp(context, 3));
|
||||
pinnedView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
trailingColumn.addView(pinnedView);
|
||||
}
|
||||
|
||||
@@ -589,6 +593,10 @@ public final class BossUi {
|
||||
timeView.setTextSize(12);
|
||||
timeView.setTextColor(context.getColor(R.color.boss_text_muted));
|
||||
timeView.setPadding(0, dp(context, TextUtils.isEmpty(row.topPinnedLabel) ? 2 : 8), 0, 0);
|
||||
timeView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
trailingColumn.addView(timeView);
|
||||
|
||||
if (row.unreadCount > 0) {
|
||||
@@ -610,14 +618,6 @@ public final class BossUi {
|
||||
trailingColumn.addView(unreadView);
|
||||
}
|
||||
|
||||
View spacer = new View(context);
|
||||
spacer.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
0,
|
||||
1f
|
||||
));
|
||||
trailingColumn.addView(spacer);
|
||||
|
||||
LinearLayout activityWrap = new LinearLayout(context);
|
||||
activityWrap.setOrientation(LinearLayout.HORIZONTAL);
|
||||
activityWrap.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.hyzq.boss;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(sdk = 34)
|
||||
public class BossUiConversationRowTest {
|
||||
@Test
|
||||
public void conversationRow_keepsCenterTextsVisibleWhenMeasured() {
|
||||
Context context = RuntimeEnvironment.getApplication();
|
||||
WechatSurfaceMapper.ConversationRow row = new WechatSurfaceMapper.ConversationRow(
|
||||
"北区试产线回归",
|
||||
"归档确认",
|
||||
"现场摄像头关键帧",
|
||||
"09:26",
|
||||
0,
|
||||
"置顶",
|
||||
1,
|
||||
false,
|
||||
"M",
|
||||
"W",
|
||||
new WechatSurfaceMapper.GroupAvatarMember[0]
|
||||
);
|
||||
|
||||
LinearLayout card = BossUi.buildConversationRow(context, row, null);
|
||||
|
||||
int width = View.MeasureSpec.makeMeasureSpec(BossUi.dp(context, 320), View.MeasureSpec.EXACTLY);
|
||||
int height = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
|
||||
card.measure(width, height);
|
||||
card.layout(0, 0, card.getMeasuredWidth(), card.getMeasuredHeight());
|
||||
|
||||
LinearLayout centerColumn = (LinearLayout) card.getChildAt(1);
|
||||
LinearLayout trailingColumn = (LinearLayout) card.getChildAt(2);
|
||||
TextView titleView = (TextView) centerColumn.getChildAt(0);
|
||||
TextView previewView = (TextView) centerColumn.getChildAt(centerColumn.getChildCount() - 1);
|
||||
|
||||
String metrics = String.format(
|
||||
"card=%d center=%d trailing=%d title=%d preview=%d",
|
||||
card.getMeasuredWidth(),
|
||||
centerColumn.getMeasuredWidth(),
|
||||
trailingColumn.getMeasuredWidth(),
|
||||
titleView.getMeasuredWidth(),
|
||||
previewView.getMeasuredWidth()
|
||||
);
|
||||
assertTrue("中间文字列不应被挤成 0 宽: " + metrics, centerColumn.getMeasuredWidth() > 0);
|
||||
assertTrue("标题需要保留可见宽度: " + metrics, titleView.getMeasuredWidth() > 0);
|
||||
assertTrue("预览需要保留可见宽度: " + metrics, previewView.getMeasuredWidth() > 0);
|
||||
assertTrue("右侧信息列不应吞掉中间内容: " + metrics, trailingColumn.getMeasuredWidth() < card.getMeasuredWidth() / 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user