Allow either category or set being selected.

This commit is contained in:
John Preston 2023-02-09 12:17:16 +04:00
parent a8decf154f
commit cbd9dd0c2c
5 changed files with 54 additions and 10 deletions

View file

@ -485,7 +485,10 @@ void EmojiListWidget::applyNextSearchQuery() {
if (!_searchMode && !searching) {
return;
}
_searchMode = searching;
const auto modeChanged = (_searchMode != searching);
if (modeChanged) {
_searchMode = searching;
}
if (!searching) {
_searchResults.clear();
_searchCustomIds.clear();
@ -493,6 +496,9 @@ void EmojiListWidget::applyNextSearchQuery() {
clearSelection();
resizeToWidth(width());
update();
if (modeChanged) {
visibleTopBottomUpdated(getVisibleTop(), getVisibleBottom());
}
};
if (_searchQuery.empty()) {
finish(false);
@ -2190,10 +2196,13 @@ void EmojiListWidget::showSet(uint64 setId) {
}
uint64 EmojiListWidget::sectionSetId(int section) const {
Expects(section < _staticCount
Expects(_searchMode
|| section < _staticCount
|| (section - _staticCount) < _custom.size());
return (section < _staticCount)
return _searchMode
? SearchEmojiSectionSetId()
: (section < _staticCount)
? EmojiSectionSetId(static_cast<Section>(section))
: _custom[section - _staticCount].id;
}

View file

@ -161,6 +161,7 @@ object_ptr<TabbedSelector::InnerFooter> GifsListWidget::createFooter() {
.st = &st(),
});
_footer = result;
_chosenSetId = Data::Stickers::RecentSetId;
GifSectionsValue(
&session()
@ -171,6 +172,9 @@ object_ptr<TabbedSelector::InnerFooter> GifsListWidget::createFooter() {
_footer->setChosen(
) | rpl::start_with_next([=](uint64 setId) {
if (_search) {
_search->cancel();
}
_chosenSetId = setId;
refreshIcons();
const auto i = ranges::find(_sections, setId, [](GifSection value) {
@ -791,13 +795,16 @@ bool GifsListWidget::refreshInlineRows(int32 *added) {
void GifsListWidget::setupSearch() {
const auto session = &_controller->session();
_search = MakeSearch(this, st(), [=](std::vector<QString> &&query) {
_chosenSetId = Data::Stickers::RecentSetId;
refreshIcons();
searchForGifs(ranges::accumulate(query, QString(), [](
const auto accumulated = ranges::accumulate(query, QString(), [](
QString a,
QString b) {
return a.isEmpty() ? b : (a + ' ' + b);
}));
});
_chosenSetId = accumulated.isEmpty()
? Data::Stickers::RecentSetId
: SearchEmojiSectionSetId();
refreshIcons();
searchForGifs(accumulated);
}, session);
}

View file

@ -417,6 +417,16 @@ void StickersListFooter::enumerateSubicons(
}
auto StickersListFooter::iconInfo(int index) const -> IconInfo {
if (index < 0) {
const auto iconsX = int(base::SafeRound(_iconState.x.current()));
return {
.index = -1,
.left = -_singleWidth - _iconsLeft,
.adjustedLeft = -_singleWidth - _iconsLeft - iconsX,
.width = _singleWidth,
.visible = false,
};
}
auto result = IconInfo();
enumerateIcons([&](const IconInfo &info) {
if (info.index == index) {
@ -473,7 +483,8 @@ void StickersListFooter::validateSelectedIcon(
&& setId == Data::Stickers::RecentSetId)) {
newSelected = i;
break;
} else if (_icons[i].setId == Data::Stickers::FavedSetId) {
} else if (_icons[i].setId == Data::Stickers::FavedSetId
&& setId != SearchEmojiSectionSetId()) {
favedIconIndex = i;
} else if (isEmojiSection && _icons[i].setId == allEmojiSetId) {
newSelected = i;
@ -483,7 +494,9 @@ void StickersListFooter::validateSelectedIcon(
setSelectedIcon(
(newSelected >= 0
? newSelected
: (favedIconIndex >= 0) ? favedIconIndex : 0),
: (favedIconIndex >= 0)
? favedIconIndex
: -1),
animations);
setSelectedSubicon(
(newSubSelected >= 0 ? newSubSelected : 0),
@ -522,6 +535,9 @@ void StickersListFooter::setSelectedIcon(
if (_iconState.selected == newSelected) {
return;
}
if ((_iconState.selected < 0) != (newSelected < 0)) {
animations = ValidateIconAnimations::None;
}
_iconState.selected = newSelected;
updateEmojiSectionWidth();
const auto info = iconInfo(_iconState.selected);
@ -1113,7 +1129,7 @@ void StickersListFooter::refreshIconsGeometry(
(st().footer - st().iconArea) / 2);
refreshScrollableDimensions();
refreshSubiconsGeometry();
_iconState.selected = _subiconState.selected = -1;
_iconState.selected = _subiconState.selected = -2;
validateSelectedIcon(activeSetId, animations);
update();
}

View file

@ -2463,7 +2463,18 @@ auto StickersListWidget::getLottieRenderer()
}
void StickersListWidget::showStickerSet(uint64 setId) {
if (_showingSetById) {
return;
}
_showingSetById = true;
const auto guard = gsl::finally([&] { _showingSetById = false; });
clearSelection();
if (_search
&& (!_searchQuery.isEmpty() || !_searchNextQuery.isEmpty())) {
_search->cancel();
cancelSetsSearch();
}
if (setId == Data::Stickers::FeaturedSetId) {
if (_section != Section::Featured) {

View file

@ -355,6 +355,7 @@ private:
base::flat_set<not_null<DocumentData*>> _favedStickersMap;
std::weak_ptr<Lottie::FrameRenderer> _lottieRenderer;
bool _showingSetById = false;
crl::time _lastScrolledAt = 0;
crl::time _lastFullUpdatedAt = 0;