Skip to content

Commit

Permalink
SearchActivity: Display video duration in the bottom right corner
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Jun 25, 2024
1 parent 88f4f93 commit e58fcca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions wiliwili/include/fragment/search_tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ typedef brls::Event<std::string> UpdateSearchEvent;

class DataSourceSearchVideoList : public RecyclingGridDataSource {
public:
DataSourceSearchVideoList(bilibili::VideoItemSearchListResult result) : list(std::move(result)) {}
explicit DataSourceSearchVideoList(bilibili::VideoItemSearchListResult result) : list(std::move(result)) {}

RecyclingGridItem* cellForRow(RecyclingGrid* recycler, size_t index) override {
//从缓存列表中取出 或者 新生成一个表单项
RecyclingGridItemVideoCard* item = (RecyclingGridItemVideoCard*)recycler->dequeueReusableCell("Cell");

bilibili::VideoItemSearchResult& r = this->list[index];
item->setCard(r.cover + ImageHelper::h_ext, r.title, r.subtitle, r.pubdate, r.play, r.danmaku, "");
item->setCard(r.cover + ImageHelper::h_ext, r.title, r.subtitle, r.pubdate, r.play, r.danmaku,
wiliwili::uglyString2Time(r.rightBottomBadge));
return item;
}

Expand Down
4 changes: 4 additions & 0 deletions wiliwili/include/utils/number_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ std::string getRandomHex(int length, bool lowerCase = true);
//4180 => 01:09:40
std::string sec2Time(size_t t);

// 我不知道为什么B站要返回一个字符串来显示视频的长度,然后在前端把这个字符串转换成更好看的时间,这真的很蠢
// 120:12 => 02:00:12
std::string uglyString2Time(const std::string& str);

// 100 => 0:01:40
// 4180 => 1:09:40
std::string sec2TimeDLNA(size_t t);
Expand Down
13 changes: 13 additions & 0 deletions wiliwili/source/utils/number_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ std::string wiliwili::sec2Time(size_t t) {
return wiliwili::pre0(hour, 2) + ":" + wiliwili::pre0(minute, 2) + ":" + wiliwili::pre0(sec, 2);
}

std::string wiliwili::uglyString2Time(const std::string& str) {
if(str.empty()) return "";
auto res = pystring::split(str, ":");
if (res.size() != 2) return str;
try {
int min = std::stoi(res[0]);
int sec = std::stoi(res[1]);
return wiliwili::sec2Time(min * 60 + sec);
} catch (...) {
return str;
}
}

std::string wiliwili::sec2TimeDLNA(size_t t) {
size_t hour = t / 3600;
size_t minute = t / 60 % 60;
Expand Down

0 comments on commit e58fcca

Please sign in to comment.