Skip to content

Commit

Permalink
Fix share message ui
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonflylee committed May 8, 2024
1 parent af65ccc commit 5c56bb4
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 9 deletions.
49 changes: 49 additions & 0 deletions resources/xml/views/inbox_msg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
backgroundColor="@theme/color/grey_1"
highlightCornerRadius="16"
cornerRadius="16"
visibility="gone"
focusable="true"
axis="column"
grow="1"
Expand All @@ -40,6 +41,54 @@
wireframe="false" />
</brls:Box>

<brls:Box
id="msg/share_box"
backgroundColor="@theme/color/grey_1"
highlightCornerRadius="16"
cornerRadius="16"
focusable="true"
visibility="gone"
width="300"
axis="column"
grow="1"
padding="5">

<brls:Image
id="msg/share/thumb"
height="200"
image="@res/pictures/video-card-bg.png"
scalingType="fill" />

<brls:Label
id="msg/share/misc"
width="auto"
height="auto"
fontSize="18"
singleLine="true"
margin="12"
autoAnimate="false"
wireframe="false" />

<brls:Box
width="100%"
padding="12"
alignItems="center"
lineColor="@theme/color/line"
lineTop="1">
<SVGImage
height="14"
width="18"
SVG="@res/svg/widget-up.svg" />
<brls:Label
id="msg/share/author"
marginLeft="4"
fontSize="16"
singleLine="true"
textColor="@theme/font/grey"
height="100%" />
</brls:Box>
</brls:Box>

<brls:Box
marginTop="5"
marginLeft="15">
Expand Down
1 change: 0 additions & 1 deletion resources/xml/views/inbox_user.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
highlightCornerRadius="8"
cornerRadius="8"
alignItems="center"
justifyContent="spaceBetween"
paddingLeft="15"
paddingRight="20"
width="auto"
Expand Down
4 changes: 4 additions & 0 deletions wiliwili/include/view/inbox_msg_card.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class InboxMsgCard : public RecyclingGridItem {
private:
BRLS_BIND(TextBox, textBox, "msg/content");
BRLS_BIND(brls::Box, msgBox, "msg/content_box");
BRLS_BIND(brls::Box, shareBox, "msg/share_box");
BRLS_BIND(brls::Label, shareMisc, "msg/share/misc");
BRLS_BIND(brls::Label, shareAuthor, "msg/share/author");
BRLS_BIND(brls::Image, shareThumb, "msg/share/thumb");
BRLS_BIND(brls::Image, talker, "avatar/talker");
BRLS_BIND(brls::Image, mine, "avatar/mine");
};
3 changes: 3 additions & 0 deletions wiliwili/source/fragment/inbox_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class ChatUserCard : public RecyclingGridItem {
misc = r.last_msg.content.at("content");
} else if (r.last_msg.msg_type == 2) {
misc = "[图片]";
} else if (r.last_msg.msg_type == 7) {
misc = "[分享] ";
misc.append(r.last_msg.content.at("title"));
} else if (r.last_msg.msg_type == 10) {
misc = r.last_msg.content.at("title");
}
Expand Down
38 changes: 30 additions & 8 deletions wiliwili/source/view/inbox_msg_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,34 @@ void InboxMsgCard::setCard(const bilibili::InboxMessageResult& r, const IEMap& m
this->mine->setVisibility(brls::Visibility::VISIBLE);
}

// 分享消息
if (r.msg_type == 7) {
if (r.content.contains("title")) {
std::string title = r.content.at("title");
this->shareMisc->setText(title);
}
if (r.content.contains("thumb")) {
std::string thumb = r.content.at("thumb");
ImageHelper::with(this->shareThumb)->load(thumb);
}
if (r.content.contains("author")) {
std::string author = r.content.at("author");
this->shareAuthor->setText(author);
} else if (r.content.contains("source_desc")) {
std::string desc = r.content.at("source_desc");
this->shareAuthor->setText(desc);
}
this->shareBox->setVisibility(brls::Visibility::VISIBLE);
this->msgBox->setVisibility(brls::Visibility::GONE);
return;
}

this->shareBox->setVisibility(brls::Visibility::GONE);
this->msgBox->setVisibility(brls::Visibility::VISIBLE);

switch (r.msg_type) {
case 1: { // 文本消息
if (!r.content.contains("content")) break;
std::string msg = r.content.at("content");
size_t start = 0;
for (size_t i = 0; i < msg.length(); i++) {
Expand Down Expand Up @@ -62,6 +88,7 @@ void InboxMsgCard::setCard(const bilibili::InboxMessageResult& r, const IEMap& m
break;
}
case 2: { // 图片消息
if (!r.content.contains("url")) break;
std::string pic = r.content.at("url");
float width = r.content.at("width");
float height = r.content.at("height");
Expand All @@ -73,17 +100,12 @@ void InboxMsgCard::setCard(const bilibili::InboxMessageResult& r, const IEMap& m
d.push_back(std::make_shared<RichTextImage>(pic, width, height));
break;
}
case 7: { // 分享消息
std::string title = r.content.at("title");
std::string thumb = r.content.at("thumb");
d.push_back(std::make_shared<RichTextSpan>(title, textColor));
d.push_back(std::make_shared<RichTextImage>(thumb, 400.f, 100.f));
break;
}
case 10: { // 系统消息
if (!r.content.contains("title")) break;
auto titleColor = theme.getColor("color/bilibili");
std::string title = r.content.at("title");
std::string text = r.content.at("text");
d.push_back(std::make_shared<RichTextSpan>(title, theme.getColor("color/bilibili")));
d.push_back(std::make_shared<RichTextSpan>(title, titleColor));
d.push_back(std::make_shared<RichTextBreak>());
d.push_back(std::make_shared<RichTextSpan>(text, textColor));
break;
Expand Down

0 comments on commit 5c56bb4

Please sign in to comment.