Show Beginning button only for message date

Also hide button when you're already at beginning.
This commit is contained in:
RadRussianRus 2019-09-08 23:12:48 +03:00 committed by John Preston
parent 3ca57ae50d
commit 428a501bac
3 changed files with 28 additions and 1 deletions

View file

@ -27,6 +27,11 @@ public:
_month.setForced(_month.value(), true);
}
void setBeginningButton(bool enabled);
bool hasBeginningButton() const {
return _beginningButton;
}
void setMinDate(QDate date);
void setMaxDate(QDate date);
@ -55,6 +60,9 @@ public:
bool isEnabled(int index) const {
return (index >= _minDayIndex) && (index <= _maxDayIndex);
}
bool atBeginning() const {
return _highlighted == _min;
}
const base::Variable<QDate> &month() {
return _month;
@ -69,6 +77,8 @@ private:
static int daysShiftForMonth(QDate month);
static int rowsCountForMonth(QDate month);
bool _beginningButton = false;
base::Variable<QDate> _month;
QDate _min, _max;
QDate _highlighted;
@ -86,6 +96,10 @@ CalendarBox::Context::Context(QDate month, QDate highlighted) : _highlighted(hig
showMonth(month);
}
void CalendarBox::Context::setBeginningButton(bool enabled) {
_beginningButton = enabled;
}
void CalendarBox::Context::setMinDate(QDate date) {
_min = date;
applyMonth(_month.value(), true);
@ -502,6 +516,14 @@ void CalendarBox::setMaxDate(QDate date) {
_context->setMaxDate(date);
}
bool CalendarBox::hasBeginningButton() const {
return _context->hasBeginningButton();
}
void CalendarBox::setBeginningButton(bool enabled) {
_context->setBeginningButton(enabled);
}
void CalendarBox::prepare() {
_previous->setClickedCallback([this] { goPreviousMonth(); });
_next->setClickedCallback([this] { goNextMonth(); });
@ -509,7 +531,6 @@ void CalendarBox::prepare() {
// _inner = setInnerWidget(object_ptr<Inner>(this, _context.get()), st::calendarScroll, st::calendarTitleHeight);
_inner->setDateChosenCallback(std::move(_callback));
addLeftButton(tr::lng_calendar_beginning(), [this] { _inner->selectBeginning(); });
addButton(tr::lng_close(), [this] { closeBox(); });
subscribe(_context->month(), [this](QDate month) { monthChanged(month); });
@ -519,6 +540,9 @@ void CalendarBox::prepare() {
if (_finalize) {
_finalize(this);
}
if (!_context->atBeginning() && hasBeginningButton()) {
addLeftButton(tr::lng_calendar_beginning(), [this] { _inner->selectBeginning(); });
}
}
bool CalendarBox::isPreviousEnabled() const {

View file

@ -33,6 +33,8 @@ public:
FnMut<void(not_null<CalendarBox*>)> finalize,
const style::CalendarSizes &st);
void setBeginningButton(bool enabled);
bool hasBeginningButton() const;
void setMinDate(QDate date);
void setMaxDate(QDate date);

View file

@ -594,6 +594,7 @@ void SessionController::showJumpToDate(Dialogs::Key chat, QDate requestedDate) {
std::move(callback));
box->setMinDate(minPeerDate(chat));
box->setMaxDate(maxPeerDate(chat));
box->setBeginningButton(true);
Ui::show(std::move(box));
}