Add content to feed info cover widget.

This commit is contained in:
John Preston 2018-02-06 17:46:00 +03:00
parent 5a5c5782a9
commit a144e35f84
4 changed files with 60 additions and 121 deletions

View File

@ -1425,6 +1425,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_feed_channel_added" = "Channel added to your feed.";
"lng_feed_channel_removed" = "Channel removed from your feed.";
"lng_feed_no_messages" = "No messages in this feed yet";
"lng_feed_channels#one" = "{count} channel";
"lng_feed_channels#other" = "{count} channels";
"lng_info_feed_title" = "Feed Info";

View File

@ -8,9 +8,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "info/feed/info_feed_cover.h"
#include "data/data_feed.h"
#include "data/data_session.h"
#include "info/info_controller.h"
#include "lang/lang_keys.h"
#include "ui/widgets/labels.h"
#include "ui/special_buttons.h"
#include "auth_session.h"
#include "styles/style_info.h"
namespace Info {
@ -26,88 +29,43 @@ Cover::Cover(
+ st::infoProfilePhotoBottom)
, _controller(controller)
, _feed(_controller->key().feed())
//, _userpic(
// this,
// controller->parentController(),
// _peer,
// Ui::UserpicButton::Role::OpenPhoto,
// st::infoProfilePhoto)
, _userpic(
this,
controller->parentController(),
_feed,
st::infoFeedProfilePhoto)
, _name(this, st::infoProfileNameLabel)
, _status(
this,
st::infoProfileMegagroupStatusLabel) {
this,
st::infoProfileMegagroupStatusLabel) {
_userpic->setPointerCursor(false);
_name->setSelectable(true);
_name->setContextCopyText(lang(lng_profile_copy_fullname));
refreshNameText();
initViewers();
setupChildGeometry();
}
void Cover::setupChildGeometry() {
using namespace rpl::mappers;
//
// Visual Studio 2017 15.5.1 internal compiler error here.
// See https://developercommunity.visualstudio.com/content/problem/165155/ice-regression-in-1551-after-successfull-build-in.html
//
//rpl::combine(
// toggleShownValue(),
// widthValue(),
// _2
//) | rpl::map([](bool shown, int width) {
//rpl::combine(
// toggleShownValue(),
// widthValue()
//) | rpl::map([](bool shown, int width) {
// return width;
//}) | rpl::start_with_next([this](int newWidth) {
// _userpic->moveToLeft(
// st::infoProfilePhotoLeft,
// st::infoProfilePhotoTop,
// newWidth);
// refreshNameGeometry(newWidth);
// refreshStatusGeometry(newWidth);
//}, lifetime());
widthValue(
) | rpl::start_with_next([=](int newWidth) {
_userpic->moveToLeft(
st::infoProfilePhotoLeft,
st::infoProfilePhotoTop,
newWidth);
refreshNameGeometry(newWidth);
refreshStatusGeometry(newWidth);
}, lifetime());
}
void Cover::initViewers() {
//using Flag = Notify::PeerUpdate::Flag;
//Notify::PeerUpdateValue(
// _peer,
// Flag::NameChanged
//) | rpl::start_with_next(
// [this] { refreshNameText(); },
// lifetime());
//Notify::PeerUpdateValue(
// _peer,
// Flag::UserOnlineChanged | Flag::MembersChanged
//) | rpl::start_with_next(
// [this] { refreshStatusText(); },
// lifetime());
//if (!_peer->isUser()) {
// Notify::PeerUpdateValue(
// _peer,
// Flag::ChannelRightsChanged | Flag::ChatCanEdit
// ) | rpl::start_with_next(
// [this] { refreshUploadPhotoOverlay(); },
// lifetime());
//}
//VerifiedValue(
// _peer
//) | rpl::start_with_next(
// [this](bool verified) { setVerified(verified); },
// lifetime());
}
void Cover::refreshUploadPhotoOverlay() {
//_userpic->switchChangePhotoOverlay([&] {
// if (auto chat = _peer->asChat()) {
// return chat->canEdit();
// } else if (auto channel = _peer->asChannel()) {
// return channel->canEditInformation();
// }
// return false;
//}());
Auth().data().feedUpdated(
) | rpl::filter([](const Data::FeedUpdate &update) {
return update.flag == Data::FeedUpdateFlag::Channels;
}) | rpl::start_with_next(
[=] { refreshStatusText(); },
lifetime());
}
void Cover::refreshNameText() {
@ -116,56 +74,21 @@ void Cover::refreshNameText() {
}
void Cover::refreshStatusText() {
//auto hasMembersLink = [&] {
// if (auto megagroup = _peer->asMegagroup()) {
// return megagroup->canViewMembers();
// }
// return false;
//}();
//auto statusText = [&] {
// auto currentTime = unixtime();
// if (auto user = _peer->asUser()) {
// const auto result = Data::OnlineTextFull(user, currentTime);
// const auto showOnline = Data::OnlineTextActive(user, currentTime);
// const auto updateIn = Data::OnlineChangeTimeout(user, currentTime);
// if (showOnline) {
// _refreshStatusTimer.callOnce(updateIn);
// }
// return showOnline
// ? textcmdLink(1, result)
// : result;
// } else if (auto chat = _peer->asChat()) {
// if (!chat->amIn()) {
// return lang(lng_chat_status_unaccessible);
// }
// auto fullCount = std::max(
// chat->count,
// int(chat->participants.size()));
// return ChatStatusText(fullCount, _onlineCount, true);
// } else if (auto channel = _peer->asChannel()) {
// auto fullCount = qMax(channel->membersCount(), 1);
// auto result = ChatStatusText(
// fullCount,
// _onlineCount,
// channel->isMegagroup());
// return hasMembersLink ? textcmdLink(1, result) : result;
// }
// return lang(lng_chat_status_unaccessible);
//}();
//_status->setRichText(statusText);
//if (hasMembersLink) {
// _status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
// _controller->showSection(Info::Memento(
// _controller->peerId(),
// Section::Type::Members));
// }));
//}
const auto statusText = [&] {
if (!_feed->channelsLoaded() || _feed->channels().empty()) {
return QString();
}
return lng_feed_channels(lt_count, _feed->channels().size());
}();
_status->setRichText(statusText);
//_status->setLink(1, std::make_shared<LambdaClickHandler>([=] {
// _controller->showSection(Info::Memento(
// _feed,
// Section::Type::Channels));
//})); // #TODO channels list
refreshStatusGeometry(width());
}
Cover::~Cover() {
}
void Cover::refreshNameGeometry(int newWidth) {
auto nameLeft = st::infoProfileNameLeft;
auto nameTop = st::infoProfileNameTop;
@ -187,5 +110,7 @@ void Cover::refreshStatusGeometry(int newWidth) {
newWidth);
}
Cover::~Cover() = default;
} // namespace FeedProfile
} // namespace Info

View File

@ -20,7 +20,7 @@ class Feed;
} // namespace Data
namespace Ui {
class UserpicButton;
class FeedUserpicButton;
class FlatLabel;
template <typename Widget>
class SlideWrap;
@ -48,12 +48,11 @@ private:
void refreshStatusText();
void refreshNameGeometry(int newWidth);
void refreshStatusGeometry(int newWidth);
void refreshUploadPhotoOverlay();
not_null<Controller*> _controller;
not_null<Data::Feed*> _feed;
//object_ptr<Ui::UserpicButton> _userpic;
object_ptr<Ui::FeedUserpicButton> _userpic;
object_ptr<Ui::FlatLabel> _name = { nullptr };
object_ptr<Ui::FlatLabel> _status = { nullptr };
//object_ptr<CoverDropArea> _dropArea = { nullptr };

View File

@ -260,9 +260,22 @@ infoTabs: SettingsSlider(defaultTabsSlider) {
labelTop: 19px;
}
infoProfilePhotoInnerSize: 72px;
infoProfilePhotoSize: size(
infoProfilePhotoInnerSize,
infoProfilePhotoInnerSize);
infoProfilePhoto: UserpicButton(defaultUserpicButton) {
size: size(72px, 72px);
photoSize: 72px;
size: infoProfilePhotoSize;
photoSize: infoProfilePhotoInnerSize;
}
infoFeedProfilePhoto: FeedUserpicButton(defaultFeedUserpicButton) {
size: infoProfilePhotoSize;
innerSize: infoProfilePhotoInnerSize;
innerPart: UserpicButton(defaultUserpicButton) {
size: size(35px, 35px);
photoSize: 35px;
}
}
infoProfilePhotoLeft: 19px;
infoProfilePhotoTop: 18px;