diff --git a/resources/xml/views/video_card.xml b/resources/xml/views/video_card.xml index e0470dad..3b362360 100644 --- a/resources/xml/views/video_card.xml +++ b/resources/xml/views/video_card.xml @@ -91,6 +91,10 @@ horizontalAlign="center" textColor="@theme/font/yellow_1"/> + dequeueReusableCell("Cell"); bilibili::RecommendVideoResult& r = this->recommendList[index]; - if (r.isAd) { - item->setCard(r.business_info.pic + ImageHelper::h_ext, r.business_info.title, r.business_info.adver_name, - "", "", "", r.business_info.business_mark); + if (r.business_info.is_ad) { + auto& card = r.business_info.archive; + auto& info = r.business_info; + auto& mark = r.business_info.business_mark; + if (r.business_info.is_ad_video) { + // 推广视频 + item->setCard(card.pic + ImageHelper::h_ext, info.title, card.owner.name, card.pubdate, card.stat.view, + card.stat.danmaku, card.duration); + item->setExtraInfo(mark.img_url, (float)mark.img_width * 0.375f, (float)mark.img_height * 0.375f); + } else { + // 广告网页 + item->setCard(info.pic + ImageHelper::h_ext, info.title, info.adver_name, "", "", "", mark.text); + } } else { item->setCard(r.pic + ImageHelper::h_ext, r.title, r.owner.name, r.pubdate, r.stat.view, r.stat.danmaku, r.duration, r.rcmd_reason.content); @@ -39,8 +49,12 @@ class DataSourceRecommendVideoList : public RecyclingGridDataSource { size_t getItemCount() override { return recommendList.size(); } void onItemSelected(RecyclingGrid* recycler, size_t index) override { - if (recommendList[index].isAd) { - brls::Application::getPlatform()->openBrowser(recommendList[index].business_info.url); + if (recommendList[index].business_info.is_ad) { + if (recommendList[index].business_info.is_ad_video) { + Intent::openBV(recommendList[index].business_info.archive.bvid); + } else { + brls::Application::getPlatform()->openBrowser(recommendList[index].business_info.url); + } } else { Intent::openBV(recommendList[index].bvid); } @@ -102,9 +116,10 @@ void HomeRecommends::onRecommendVideoList(const bilibili::RecommendVideoListResu if (ProgramConfig::instance().upFilter.empty()) { std::copy(originalResult.item.begin(), originalResult.item.end(), result.item.begin()); } else { - auto it = std::copy_if( - originalResult.item.begin(), originalResult.item.end(), result.item.begin(), - [](const bilibili::RecommendVideoResult& r) { return !ProgramConfig::instance().upFilter.count(r.owner.mid); }); + auto it = std::copy_if(originalResult.item.begin(), originalResult.item.end(), result.item.begin(), + [](const bilibili::RecommendVideoResult& r) { + return !ProgramConfig::instance().upFilter.count(r.owner.mid); + }); result.item.resize(std::distance(result.item.begin(), it)); } diff --git a/wiliwili/source/view/video_card.cpp b/wiliwili/source/view/video_card.cpp index 15ab0aa5..ce4de7b7 100644 --- a/wiliwili/source/view/video_card.cpp +++ b/wiliwili/source/view/video_card.cpp @@ -7,6 +7,7 @@ #include "view/text_box.hpp" #include "utils/number_helper.hpp" #include "utils/image_helper.hpp" +#include using namespace brls::literals; @@ -45,67 +46,68 @@ void RecyclingGridItemVideoCard::setAchievement(const std::string& explain) { RecyclingGridItemVideoCard* RecyclingGridItemVideoCard::create() { return new RecyclingGridItemVideoCard(); } -void RecyclingGridItemVideoCard::setCard(const std::string& pic, const std::string& title, const std::string& username, - int pubdate, int view_count, int danmaku, int duration, - const std::string& extra) { - if (pubdate) - this->labelUsername->setText(username + "·" + wiliwili::sec2date(pubdate)); - else - this->labelUsername->setText(username); - - this->labelTitle->setIsWrapping(true); - this->labelTitle->setText(title); - ImageHelper::with(this->picture)->load(pic); - this->labelCount->setText(wiliwili::num2w(view_count)); - this->labelDanmaku->setText(wiliwili::num2w(danmaku)); - - if (duration) - this->labelDuration->setText(wiliwili::sec2Time(duration)); - else - this->labelDuration->setText(""); +void RecyclingGridItemVideoCard::cacheForReuse() { + //准备回收该项 + ImageHelper::clear(this->picture); + ImageHelper::clear(this->pictureHint); +} +void RecyclingGridItemVideoCard::setExtraInfo(const std::string& extra, float width, float height){ if (extra.empty()) { this->svgUp->setVisibility(brls::Visibility::VISIBLE); this->boxHint->setVisibility(brls::Visibility::GONE); + this->pictureHint->setVisibility(brls::Visibility::GONE); + } else if (pystring::startswith(extra, "http")) { + this->svgUp->setVisibility(brls::Visibility::GONE); + this->boxHint->setVisibility(brls::Visibility::GONE); + this->pictureHint->setVisibility(brls::Visibility::VISIBLE); + this->pictureHint->setDimensions(width, height); + ImageHelper::with(this->pictureHint)->load(extra); } else { this->svgUp->setVisibility(brls::Visibility::GONE); this->boxHint->setVisibility(brls::Visibility::VISIBLE); this->labelHint->setText(extra); + this->pictureHint->setVisibility(brls::Visibility::GONE); } } +void RecyclingGridItemVideoCard::setBasicInfo(const std::string& title, const std::string& pic, const std::string& username) { + this->labelTitle->setIsWrapping(true); + this->labelTitle->setText(title); + + this->labelUsername->setText(username); + + ImageHelper::with(this->picture)->load(pic); +} + +void RecyclingGridItemVideoCard::setCard(const std::string& pic, const std::string& title, const std::string& username, + int pubdate, int view_count, int danmaku, int duration, + const std::string& extra) { + std::string rightBottomBadge; + if (duration) + rightBottomBadge = wiliwili::sec2Time(duration); + + this->setCard(pic, title, username, pubdate, view_count, danmaku, rightBottomBadge, extra); +} + void RecyclingGridItemVideoCard::setCard(const std::string& pic, const std::string& title, const std::string& username, int pubdate, int view_count, int danmaku, const std::string& rightBottomBadge, const std::string& extra) { + std::string author; if (pubdate) - this->labelUsername->setText(username + "·" + wiliwili::sec2date(pubdate)); + author = username + "·" + wiliwili::sec2date(pubdate); else - this->labelUsername->setText(username); + author = username; - this->labelTitle->setIsWrapping(true); - this->labelTitle->setText(title); - ImageHelper::with(this->picture)->load(pic); - this->labelCount->setText(wiliwili::num2w(view_count)); - this->labelDanmaku->setText(wiliwili::num2w(danmaku)); - this->labelDuration->setText(rightBottomBadge); - - if (extra.empty()) { - this->svgUp->setVisibility(brls::Visibility::VISIBLE); - this->boxHint->setVisibility(brls::Visibility::GONE); - } else { - this->svgUp->setVisibility(brls::Visibility::GONE); - this->boxHint->setVisibility(brls::Visibility::VISIBLE); - this->labelHint->setText(extra); - } + this->setCard(pic, title, author, wiliwili::num2w(view_count), wiliwili::num2w(danmaku), rightBottomBadge, extra); } void RecyclingGridItemVideoCard::setCard(const std::string& pic, const std::string& title, const std::string& username, const std::string& viewCount, const std::string& danmakuCount, const std::string& rightBottomBadge, const std::string& extra) { - this->labelUsername->setText(username); - this->labelTitle->setIsWrapping(true); - this->labelTitle->setText(title); - ImageHelper::with(this->picture)->load(pic); + this->setBasicInfo(title, pic, username); + this->setExtraInfo(extra); + this->labelDuration->setText(rightBottomBadge); if (viewCount.empty()) { @@ -125,15 +127,6 @@ void RecyclingGridItemVideoCard::setCard(const std::string& pic, const std::stri this->labelDanmaku->setVisibility(brls::Visibility::VISIBLE); this->labelDanmaku->setText(danmakuCount); } - - if (extra.empty()) { - this->svgUp->setVisibility(brls::Visibility::VISIBLE); - this->boxHint->setVisibility(brls::Visibility::GONE); - } else { - this->svgUp->setVisibility(brls::Visibility::GONE); - this->boxHint->setVisibility(brls::Visibility::VISIBLE); - this->labelHint->setText(extra); - } } /// 排行榜视频封面