Skip to content

Commit

Permalink
Adjust the episode list style
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Apr 21, 2024
1 parent af3ba07 commit 31fb848
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
25 changes: 25 additions & 0 deletions wiliwili/include/view/grid_dropdown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ class TextDataSourceDropdown : public DataSourceDropdown {
std::vector<std::string> data;
};


template <typename T>
class CommonDataSourceDropdown : public DataSourceDropdown {
public:
typedef std::function<RecyclingGridItem*(RecyclingGrid*, T&)> CommonCellForRowCallback;

CommonDataSourceDropdown(std::vector<T> result, BaseDropdown* view,
CommonCellForRowCallback cb)
: DataSourceDropdown(view), data(std::move(result)), cellForRowFunc(cb) {}

RecyclingGridItem* cellForRow(RecyclingGrid* recycler, size_t index) override {
if (cellForRowFunc) return cellForRowFunc(recycler, data[index]);
return nullptr;
}

size_t getItemCount() override { return data.size(); }

void clearData() override { data.clear(); }

private:
std::vector<T> data;
CommonCellForRowCallback cellForRowFunc = nullptr;
};


/**
* 带有进入退出动画的菜单,自带列表,默认提供了文本列表,也可以自定义列表内容
*/
Expand Down
30 changes: 21 additions & 9 deletions wiliwili/source/activity/player_season_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "view/video_card.hpp"
#include "view/svg_image.hpp"
#include "view/mpv_core.hpp"
#include "view/grid_dropdown.hpp"

/// PlayerSeasonActivity

Expand Down Expand Up @@ -277,15 +278,26 @@ void PlayerSeasonActivity::onSeasonVideoInfo(const bilibili::SeasonResultWrapper
return container;
});

video->setSeasonAction([this](brls::View *view){
std::vector<std::string> values;
for (const auto& item : this->episodeList) {
values.push_back(fmt::format("{} {}", item.title, item.long_title));
}
brls::Dropdown* dropdown = new brls::Dropdown(
"wiliwili/player/p"_i18n, values, [this](int selected) {
this->onIndexChange(selected);
}, episodeResult.index);
video->setSeasonAction([this](brls::View* view) {
auto* dropdown = new BaseDropdown(
"wiliwili/player/p"_i18n, [this](int selected) { this->onIndexChange(selected); }, episodeResult.index);
dropdown->getRecyclingList()->registerCell("Cell", []() { return PlayerTabCell::create(); });
dropdown->getRecyclingList()->registerCell("Header", []() { return PlayerTabHeader::create(); });
dropdown->setDataSource(new CommonDataSourceDropdown<bilibili::SeasonEpisodeResult>(
this->episodeList, dropdown, [dropdown](auto recycler, auto d) {
if (!d.id) {
// 显示项为标题
auto* item = (PlayerTabHeader*)recycler->dequeueReusableCell("Header");
item->title->setText(d.title);
return (RecyclingGridItem*)item;
}
// 显示分集项
auto* item = (PlayerTabCell*)recycler->dequeueReusableCell("Cell");
item->title->setText(d.title);
item->setSelected(dropdown->getSelected() == d.index);
item->setBadge(d.badge_info.text, d.badge_info.bg_color);
return (RecyclingGridItem*)item;
}));
brls::Application::pushActivity(new brls::Activity(dropdown));
return true;
});
Expand Down

0 comments on commit 31fb848

Please sign in to comment.