Simplify media overview layouts.

This commit is contained in:
John Preston 2020-05-21 16:49:47 +04:00
parent 053eace154
commit 58f82620e0
6 changed files with 23 additions and 82 deletions

View file

@ -689,7 +689,7 @@ void DocumentData::loadThumbnail(Data::FileOrigin origin) {
_thumbnailLoader = nullptr;
_flags |= Flag::ThumbnailFailed;
}, [=] {
if (!_thumbnailLoader->cancelled()) {
if (_thumbnailLoader && !_thumbnailLoader->cancelled()) {
if (auto image = _thumbnailLoader->imageData(); image.isNull()) {
_flags |= Flag::ThumbnailFailed;
} else if (const auto active = activeMediaView()) {
@ -697,7 +697,7 @@ void DocumentData::loadThumbnail(Data::FileOrigin origin) {
}
}
_thumbnailLoader = nullptr;
}) | rpl::release();
}, _thumbnailLoader->lifetime());
_thumbnailLoader->start();
}
@ -806,7 +806,7 @@ void DocumentData::finishLoad() {
const auto guard = gsl::finally([&] {
destroyLoader();
});
if (_loader->cancelled()) {
if (!_loader || _loader->cancelled()) {
_flags |= Flag::DownloadCancelled;
return;
}
@ -1004,7 +1004,7 @@ void DocumentData::handleLoaderUpdates() {
) | rpl::start_with_next_error_done([=] {
_owner->documentLoadProgress(this);
}, [=](bool started) {
if (started) {
if (started && _loader) {
const auto origin = _loader->fileOrigin();
const auto failedFileName = _loader->fileName();
const auto retry = [=] {
@ -1035,7 +1035,7 @@ void DocumentData::handleLoaderUpdates() {
}, [=] {
finishLoad();
_owner->documentLoadDone(this);
}) | rpl::release();
}, _loader->lifetime());
}

View file

@ -140,11 +140,6 @@ void Checkbox::startAnimation() {
_pression.start(_updateCallback, showPressed ? 0. : 1., showPressed ? 1. : 0., st::overviewCheck.duration);
}
MsgId AbstractItem::msgId() const {
auto item = getItem();
return item ? item->id : 0;
}
ItemBase::ItemBase(
not_null<Delegate*> delegate,
not_null<HistoryItem*> parent)
@ -295,25 +290,6 @@ void StatusText::setSize(int newSize) {
_size = newSize;
}
Date::Date(const QDate &date, bool month)
: _date(date)
, _text(month ? langMonthFull(date) : langDayOfMonthFull(date)) {
AddComponents(Info::Bit());
}
void Date::initDimensions() {
_maxw = st::normalFont->width(_text);
_minh = st::linksDateMargin.top() + st::normalFont->height + st::linksDateMargin.bottom() + st::linksBorder;
}
void Date::paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) {
if (clip.intersects(QRect(0, st::linksDateMargin.top(), _width, st::normalFont->height))) {
p.setPen(st::linksDateColor);
p.setFont(st::semiboldFont);
p.drawTextLeft(0, st::linksDateMargin.top(), _width, _text);
}
}
Photo::Photo(
not_null<Delegate*> delegate,
not_null<HistoryItem*> parent,

View file

@ -37,35 +37,17 @@ public:
};
class AbstractItem : public LayoutItemBase {
public:
virtual void paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) = 0;
virtual ItemBase *toMediaItem() {
return nullptr;
}
virtual const ItemBase *toMediaItem() const {
return nullptr;
}
virtual HistoryItem *getItem() const {
return nullptr;
}
virtual DocumentData *getDocument() const {
return nullptr;
}
MsgId msgId() const;
virtual void invalidateCache() {
}
};
class ItemBase : public AbstractItem {
class ItemBase : public LayoutItemBase {
public:
ItemBase(not_null<Delegate*> delegate, not_null<HistoryItem*> parent);
~ItemBase();
virtual void paint(
Painter &p,
const QRect &clip,
TextSelection selection,
const PaintContext *context) = 0;
QDateTime dateTime() const;
void setPosition(int position) {
@ -75,20 +57,14 @@ public:
return _position;
}
ItemBase *toMediaItem() final override {
return this;
}
const ItemBase *toMediaItem() const final override {
return this;
}
HistoryItem *getItem() const final override {
HistoryItem *getItem() const {
return _parent;
}
void clickHandlerActiveChanged(const ClickHandlerPtr &action, bool active) override;
void clickHandlerPressedChanged(const ClickHandlerPtr &action, bool pressed) override;
void invalidateCache() override;
void invalidateCache();
virtual void clearHeavyPart() {
}
@ -194,19 +170,6 @@ struct Info : public RuntimeComponent<Info, LayoutItemBase> {
int top = 0;
};
class Date : public AbstractItem {
public:
Date(const QDate &date, bool month);
void initDimensions() override;
void paint(Painter &p, const QRect &clip, TextSelection selection, const PaintContext *context) override;
private:
QDate _date;
QString _text;
};
class Photo final : public ItemBase {
public:
Photo(
@ -321,10 +284,6 @@ public:
QPoint point,
StateRequest request) const override;
DocumentData *getDocument() const override {
return _data;
}
protected:
float64 dataProgress() const override;
bool dataFinished() const override;

View file

@ -1745,7 +1745,7 @@ void FormController::loadFile(File &file) {
fileLoadFail(key);
}, [=] {
fileLoadDone(key, loader->bytes());
}) | rpl::release();
}, loader->lifetime());
loader->start();
}

View file

@ -112,6 +112,10 @@ public:
return _updates.events();
}
rpl::lifetime &lifetime() {
return _lifetime;
}
protected:
enum class LocalStatus {
NotTried,
@ -138,7 +142,6 @@ protected:
[[nodiscard]] QByteArray readLoadedPartBack(int offset, int size);
const not_null<Main::Session*> _session;
rpl::event_stream<rpl::empty_value, bool> _updates;
bool _autoLoading = false;
uint8 _cacheTag = 0;
@ -163,6 +166,9 @@ protected:
mutable QByteArray _imageFormat;
mutable QImage _imageData;
rpl::lifetime _lifetime;
rpl::event_stream<rpl::empty_value, bool> _updates;
};
[[nodiscard]] std::unique_ptr<FileLoader> CreateFileLoader(

@ -1 +1 @@
Subproject commit df918b9d3e2cce729cf21de5c69a01a847e7107c
Subproject commit 88ae67c59ab791084f43163d4484c9874003ac42