mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Start showing downloading items in Downloads.
This commit is contained in:
parent
0be320a6c7
commit
93c6038992
3 changed files with 150 additions and 25 deletions
|
@ -10,6 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "info/media/info_media_widget.h"
|
#include "info/media/info_media_widget.h"
|
||||||
#include "info/media/info_media_list_section.h"
|
#include "info/media/info_media_list_section.h"
|
||||||
#include "info/info_controller.h"
|
#include "info/info_controller.h"
|
||||||
|
#include "data/data_download_manager.h"
|
||||||
|
#include "data/data_document.h"
|
||||||
|
#include "data/data_media_types.h"
|
||||||
|
#include "history/history_item.h"
|
||||||
|
#include "core/application.h"
|
||||||
#include "storage/storage_shared_media.h"
|
#include "storage/storage_shared_media.h"
|
||||||
#include "layout/layout_selection.h"
|
#include "layout/layout_selection.h"
|
||||||
|
|
||||||
|
@ -22,11 +27,6 @@ using namespace Media;
|
||||||
|
|
||||||
Provider::Provider(not_null<AbstractController*> controller)
|
Provider::Provider(not_null<AbstractController*> controller)
|
||||||
: _controller(controller) {
|
: _controller(controller) {
|
||||||
//_controller->session().data().itemRemoved(
|
|
||||||
//) | rpl::start_with_next([this](auto item) {
|
|
||||||
// itemRemoved(item);
|
|
||||||
//}, _lifetime);
|
|
||||||
|
|
||||||
style::PaletteChanged(
|
style::PaletteChanged(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
for (auto &layout : _layouts) {
|
for (auto &layout : _layouts) {
|
||||||
|
@ -52,11 +52,10 @@ bool Provider::isPossiblyMyItem(not_null<const HistoryItem*> item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<int> Provider::fullCount() {
|
std::optional<int> Provider::fullCount() {
|
||||||
return 0;
|
return _fullCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Provider::restart() {
|
void Provider::restart() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Provider::checkPreload(
|
void Provider::checkPreload(
|
||||||
|
@ -65,11 +64,44 @@ void Provider::checkPreload(
|
||||||
not_null<BaseLayout*> bottomLayout,
|
not_null<BaseLayout*> bottomLayout,
|
||||||
bool preloadTop,
|
bool preloadTop,
|
||||||
bool preloadBottom) {
|
bool preloadBottom) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Provider::refreshViewer() {
|
void Provider::refreshViewer() {
|
||||||
|
if (_fullCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto &manager = Core::App().downloadManager();
|
||||||
|
rpl::single(
|
||||||
|
rpl::empty_value()
|
||||||
|
) | rpl::then(
|
||||||
|
manager.loadingListChanges() | rpl::to_empty
|
||||||
|
) | rpl::start_with_next([=, &manager] {
|
||||||
|
auto copy = _downloading;
|
||||||
|
auto added = false;
|
||||||
|
for (const auto &id : manager.loadingList()) {
|
||||||
|
if (!id.done) {
|
||||||
|
const auto item = id.object.item;
|
||||||
|
if (!copy.remove(item)) {
|
||||||
|
added = true;
|
||||||
|
_downloading.emplace(item);
|
||||||
|
_elements.push_back(Element{ item, id.started });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const auto &item : copy) {
|
||||||
|
_downloading.remove(item);
|
||||||
|
// #TODO downloads check if downloaded
|
||||||
|
_elements.erase(
|
||||||
|
ranges::remove(_elements, item, &Element::item),
|
||||||
|
end(_elements));
|
||||||
|
}
|
||||||
|
if (added) {
|
||||||
|
ranges::sort(_elements, ranges::less(), &Element::started);
|
||||||
|
_refreshed.fire({});
|
||||||
|
} else if (!copy.empty()) {
|
||||||
|
_refreshed.fire({});
|
||||||
|
}
|
||||||
|
}, _lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<> Provider::refreshed() {
|
rpl::producer<> Provider::refreshed() {
|
||||||
|
@ -77,8 +109,40 @@ rpl::producer<> Provider::refreshed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ListSection> Provider::fillSections(
|
std::vector<ListSection> Provider::fillSections(
|
||||||
not_null<Overview::Layout::Delegate*> delegate) {
|
not_null<Overview::Layout::Delegate*> delegate) {
|
||||||
return {};
|
markLayoutsStale();
|
||||||
|
const auto guard = gsl::finally([&] { clearStaleLayouts(); });
|
||||||
|
|
||||||
|
if (_elements.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
auto result = std::vector<ListSection>(1, ListSection(Type::File));
|
||||||
|
auto §ion = result.back();
|
||||||
|
for (const auto &element : _elements) {
|
||||||
|
if (auto layout = getLayout(element, delegate)) {
|
||||||
|
section.addItem(layout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
section.finishSection();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Provider::markLayoutsStale() {
|
||||||
|
for (auto &layout : _layouts) {
|
||||||
|
layout.second.stale = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Provider::clearStaleLayouts() {
|
||||||
|
for (auto i = _layouts.begin(); i != _layouts.end();) {
|
||||||
|
if (i->second.stale) {
|
||||||
|
_layoutRemoved.fire(i->second.item.get());
|
||||||
|
i = _layouts.erase(i);
|
||||||
|
} else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<not_null<BaseLayout*>> Provider::layoutRemoved() {
|
rpl::producer<not_null<BaseLayout*>> Provider::layoutRemoved() {
|
||||||
|
@ -90,22 +154,68 @@ BaseLayout *Provider::lookupLayout(const HistoryItem *item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Provider::isMyItem(not_null<const HistoryItem*> item) {
|
bool Provider::isMyItem(not_null<const HistoryItem*> item) {
|
||||||
return false;
|
return _downloading.contains(item) || _downloaded.contains(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Provider::isAfter(
|
bool Provider::isAfter(
|
||||||
not_null<const HistoryItem*> a,
|
not_null<const HistoryItem*> a,
|
||||||
not_null<const HistoryItem*> b) {
|
not_null<const HistoryItem*> b) {
|
||||||
return a < b;
|
if (a != b) {
|
||||||
|
for (const auto &element : _elements) {
|
||||||
|
if (element.item == a) {
|
||||||
|
return false;
|
||||||
|
} else if (element.item == b) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseLayout *Provider::getLayout(
|
||||||
|
Element element,
|
||||||
|
not_null<Overview::Layout::Delegate*> delegate) {
|
||||||
|
auto it = _layouts.find(element.item);
|
||||||
|
if (it == _layouts.end()) {
|
||||||
|
if (auto layout = createLayout(element, delegate)) {
|
||||||
|
layout->initDimensions();
|
||||||
|
it = _layouts.emplace(element.item, std::move(layout)).first;
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it->second.stale = false;
|
||||||
|
return it->second.item.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<BaseLayout> Provider::createLayout(
|
||||||
|
Element element,
|
||||||
|
not_null<Overview::Layout::Delegate*> delegate) {
|
||||||
|
const auto getFile = [&]() -> DocumentData* {
|
||||||
|
if (auto media = element.item->media()) {
|
||||||
|
return media->document();
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto &songSt = st::overviewFileLayout;
|
||||||
|
if (const auto file = getFile()) {
|
||||||
|
return std::make_unique<Overview::Layout::Document>(
|
||||||
|
delegate,
|
||||||
|
element.item,
|
||||||
|
file,
|
||||||
|
songSt);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Provider::applyDragSelection(
|
void Provider::applyDragSelection(
|
||||||
ListSelectedMap &selected,
|
ListSelectedMap &selected,
|
||||||
not_null<const HistoryItem*> fromItem,
|
not_null<const HistoryItem*> fromItem,
|
||||||
bool skipFrom,
|
bool skipFrom,
|
||||||
not_null<const HistoryItem*> tillItem,
|
not_null<const HistoryItem*> tillItem,
|
||||||
bool skipTill) {
|
bool skipTill) {
|
||||||
|
// #TODO downloads
|
||||||
}
|
}
|
||||||
|
|
||||||
void Provider::saveState(
|
void Provider::saveState(
|
||||||
|
|
|
@ -62,11 +62,26 @@ public:
|
||||||
private:
|
private:
|
||||||
struct Element {
|
struct Element {
|
||||||
not_null<HistoryItem*> item;
|
not_null<HistoryItem*> item;
|
||||||
uint64 started = 0;
|
int64 started = 0; // unixtime * 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void itemRemoved(not_null<const HistoryItem*> item);
|
||||||
|
void markLayoutsStale();
|
||||||
|
void clearStaleLayouts();
|
||||||
|
|
||||||
|
[[nodiscard]] Media::BaseLayout *getLayout(
|
||||||
|
Element element,
|
||||||
|
not_null<Overview::Layout::Delegate*> delegate);
|
||||||
|
[[nodiscard]] std::unique_ptr<Media::BaseLayout> createLayout(
|
||||||
|
Element element,
|
||||||
|
not_null<Overview::Layout::Delegate*> delegate);
|
||||||
|
|
||||||
const not_null<AbstractController*> _controller;
|
const not_null<AbstractController*> _controller;
|
||||||
|
|
||||||
std::vector<Element> _elements;
|
std::vector<Element> _elements;
|
||||||
|
std::optional<int> _fullCount;
|
||||||
|
base::flat_set<not_null<const HistoryItem*>> _downloading;
|
||||||
|
base::flat_set<not_null<const HistoryItem*>> _downloaded;
|
||||||
|
|
||||||
std::unordered_map<not_null<HistoryItem*>, Media::CachedItem> _layouts;
|
std::unordered_map<not_null<HistoryItem*>, Media::CachedItem> _layouts;
|
||||||
rpl::event_stream<not_null<Media::BaseLayout*>> _layoutRemoved;
|
rpl::event_stream<not_null<Media::BaseLayout*>> _layoutRemoved;
|
||||||
|
|
|
@ -338,20 +338,20 @@ std::unique_ptr<BaseLayout> Provider::createLayout(
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto getPhoto = [&]() -> PhotoData* {
|
const auto getPhoto = [&]() -> PhotoData* {
|
||||||
if (const auto media = item->media()) {
|
if (const auto media = item->media()) {
|
||||||
return media->photo();
|
return media->photo();
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
auto getFile = [&]() -> DocumentData* {
|
const auto getFile = [&]() -> DocumentData* {
|
||||||
if (auto media = item->media()) {
|
if (auto media = item->media()) {
|
||||||
return media->document();
|
return media->document();
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto &songSt = st::overviewFileLayout;
|
const auto &songSt = st::overviewFileLayout;
|
||||||
using namespace Overview::Layout;
|
using namespace Overview::Layout;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::Photo:
|
case Type::Photo:
|
||||||
|
|
Loading…
Add table
Reference in a new issue