diff --git a/resources/xml/fragment/inbox_feed.xml b/resources/xml/fragment/inbox_feed.xml index 7f3df578e..34d72a9b4 100644 --- a/resources/xml/fragment/inbox_feed.xml +++ b/resources/xml/fragment/inbox_feed.xml @@ -10,7 +10,7 @@ flowMode="true" paddingLeft="15" paddingRight="15" - itemHeight="500" + itemHeight="100" wireframe="false" id="inbox/feedList" /> \ No newline at end of file diff --git a/wiliwili/include/fragment/inbox_feed.hpp b/wiliwili/include/fragment/inbox_feed.hpp index d90c0f357..289f504ff 100644 --- a/wiliwili/include/fragment/inbox_feed.hpp +++ b/wiliwili/include/fragment/inbox_feed.hpp @@ -17,11 +17,11 @@ class InboxFeed : public AttachedView, public InboxFeedRequest { void setMode(MsgFeedMode mode); - void onFeedReplyList(const bilibili::FeedReplyResultWrapper& result) override; + void onFeedReplyList(const bilibili::FeedReplyResultWrapper& result, bool refresh) override; - void onFeedAtList(const bilibili::FeedAtResultWrapper& result) override; + void onFeedAtList(const bilibili::FeedAtResultWrapper& result, bool refresh) override; - void onFeedLikeList(const bilibili::FeedLikeResultWrapper& result) override; + void onFeedLikeList(const bilibili::FeedLikeResultWrapper& result, bool refresh) override; void onError(const std::string& error) override; diff --git a/wiliwili/include/presenter/inbox_feed.hpp b/wiliwili/include/presenter/inbox_feed.hpp index 69dce821d..4c40f434b 100644 --- a/wiliwili/include/presenter/inbox_feed.hpp +++ b/wiliwili/include/presenter/inbox_feed.hpp @@ -16,11 +16,11 @@ enum class MsgFeedMode class InboxFeedRequest : public Presenter { public: - virtual void onFeedReplyList(const bilibili::FeedReplyResultWrapper& result); + virtual void onFeedReplyList(const bilibili::FeedReplyResultWrapper& result, bool refresh); - virtual void onFeedAtList(const bilibili::FeedAtResultWrapper& result); + virtual void onFeedAtList(const bilibili::FeedAtResultWrapper& result, bool refresh); - virtual void onFeedLikeList(const bilibili::FeedLikeResultWrapper& result); + virtual void onFeedLikeList(const bilibili::FeedLikeResultWrapper& result, bool refresh); virtual void onError(const std::string& error); diff --git a/wiliwili/source/fragment/inbox_feed.cpp b/wiliwili/source/fragment/inbox_feed.cpp index dafb4eff2..ffd6e5380 100644 --- a/wiliwili/source/fragment/inbox_feed.cpp +++ b/wiliwili/source/fragment/inbox_feed.cpp @@ -103,6 +103,12 @@ class DataSourceFeedList : public RecyclingGridDataSource { } } + void appendData(const std::vector& result) { + for (const auto& i : result) { + this->list.push_back(i); + } + } + void clearData() override { this->list.clear(); } private: @@ -122,27 +128,62 @@ InboxFeed::InboxFeed() { // 消息列表 recyclingGrid->registerCell("Cell", []() { return new FeedCard(); }); + + recyclingGrid->onNextPage([this](){ + this->requestData(feedMode, false); + }); + + recyclingGrid->setRefreshAction([this](){ + this->recyclingGrid->estimatedRowHeight = 100; + this->recyclingGrid->showSkeleton(); + this->requestData(feedMode, true); + brls::Application::giveFocus(this->getTabBar()); + }); } InboxFeed::~InboxFeed() { brls::Logger::debug("Fragment InboxFeed: delete"); } -void InboxFeed::onCreate() { this->requestData(feedMode, true); } +void InboxFeed::onCreate() { + this->requestData(feedMode, true); + this->registerTabAction("", brls::ControllerButton::BUTTON_X ,[this](brls::View* view) { + this->recyclingGrid->refresh(); + return true; + }, true); +} void InboxFeed::setMode(MsgFeedMode mode) { this->feedMode = mode; } -void InboxFeed::onFeedReplyList(const bilibili::FeedReplyResultWrapper& result) { - auto dataSource = new DataSourceFeedList(result.items); - recyclingGrid->setDataSource(dataSource); +void InboxFeed::onFeedReplyList(const bilibili::FeedReplyResultWrapper& result, bool refresh) { + this->recyclingGrid->estimatedRowHeight = 500; + auto dataSource = dynamic_cast*>(recyclingGrid->getDataSource()); + if (dataSource && !refresh) { + dataSource->appendData(result.items); + recyclingGrid->notifyDataChanged(); + } else { + recyclingGrid->setDataSource(new DataSourceFeedList(result.items)); + } } -void InboxFeed::onFeedAtList(const bilibili::FeedAtResultWrapper& result) { - auto dataSource = new DataSourceFeedList(result.items); - recyclingGrid->setDataSource(dataSource); +void InboxFeed::onFeedAtList(const bilibili::FeedAtResultWrapper& result, bool refresh) { + this->recyclingGrid->estimatedRowHeight = 500; + auto dataSource = dynamic_cast*>(recyclingGrid->getDataSource()); + if (dataSource && !refresh) { + dataSource->appendData(result.items); + recyclingGrid->notifyDataChanged(); + } else { + recyclingGrid->setDataSource(new DataSourceFeedList(result.items)); + } } -void InboxFeed::onFeedLikeList(const bilibili::FeedLikeResultWrapper& result) { - auto dataSource = new DataSourceFeedList(result.total.items); - recyclingGrid->setDataSource(dataSource); +void InboxFeed::onFeedLikeList(const bilibili::FeedLikeResultWrapper& result, bool refresh) { + this->recyclingGrid->estimatedRowHeight = 500; + auto dataSource = dynamic_cast*>(recyclingGrid->getDataSource()); + if (dataSource && !refresh) { + dataSource->appendData(result.total.items); + recyclingGrid->notifyDataChanged(); + } else { + recyclingGrid->setDataSource(new DataSourceFeedList(result.total.items)); + } } void InboxFeed::onError(const std::string& error) { diff --git a/wiliwili/source/presenter/inbox_feed.cpp b/wiliwili/source/presenter/inbox_feed.cpp index a51a12a7f..387fa275e 100644 --- a/wiliwili/source/presenter/inbox_feed.cpp +++ b/wiliwili/source/presenter/inbox_feed.cpp @@ -3,24 +3,27 @@ #include "bilibili.h" #include "presenter/inbox_feed.hpp" -void InboxFeedRequest::onFeedReplyList(const bilibili::FeedReplyResultWrapper& result) {} +void InboxFeedRequest::onFeedReplyList(const bilibili::FeedReplyResultWrapper& result, bool refresh) {} -void InboxFeedRequest::onFeedAtList(const bilibili::FeedAtResultWrapper& result) {} +void InboxFeedRequest::onFeedAtList(const bilibili::FeedAtResultWrapper& result, bool refresh) {} -void InboxFeedRequest::onFeedLikeList(const bilibili::FeedLikeResultWrapper& result) {} +void InboxFeedRequest::onFeedLikeList(const bilibili::FeedLikeResultWrapper& result, bool refresh) {} void InboxFeedRequest::onError(const std::string& error) {} void InboxFeedRequest::requestData(MsgFeedMode mode, bool refresh) { + if (this->cursor.is_end && !refresh) return; + if (refresh) this->cursor = bilibili::MsgFeedCursor{}; switch (mode) { case MsgFeedMode::REPLY: { ASYNC_RETAIN BILI::msg_feed_reply( this->cursor, - [ASYNC_TOKEN](const bilibili::FeedReplyResultWrapper& result) { - brls::sync([ASYNC_TOKEN, result]() { + [ASYNC_TOKEN, refresh](const bilibili::FeedReplyResultWrapper& result) { + brls::sync([ASYNC_TOKEN, result, refresh]() { ASYNC_RELEASE - this->onFeedReplyList(result); + this->cursor = result.cursor; + this->onFeedReplyList(result, refresh); }); }, [ASYNC_TOKEN](BILI_ERR) { @@ -35,10 +38,11 @@ void InboxFeedRequest::requestData(MsgFeedMode mode, bool refresh) { ASYNC_RETAIN BILI::msg_feed_at( this->cursor, - [ASYNC_TOKEN](const bilibili::FeedAtResultWrapper& result) { - brls::sync([ASYNC_TOKEN, result]() { + [ASYNC_TOKEN, refresh](const bilibili::FeedAtResultWrapper& result) { + brls::sync([ASYNC_TOKEN, result, refresh]() { ASYNC_RELEASE - this->onFeedAtList(result); + this->cursor = result.cursor; + this->onFeedAtList(result, refresh); }); }, [ASYNC_TOKEN](BILI_ERR) { @@ -53,10 +57,11 @@ void InboxFeedRequest::requestData(MsgFeedMode mode, bool refresh) { ASYNC_RETAIN BILI::msg_feed_like( this->cursor, - [ASYNC_TOKEN](const bilibili::FeedLikeResultWrapper& result) { - brls::sync([ASYNC_TOKEN, result]() { + [ASYNC_TOKEN, refresh](const bilibili::FeedLikeResultWrapper& result) { + brls::sync([ASYNC_TOKEN, result, refresh]() { ASYNC_RELEASE - this->onFeedLikeList(result); + this->cursor = result.total.cursor; + this->onFeedLikeList(result, refresh); }); }, [ASYNC_TOKEN](BILI_ERR) {