Widget _buildChatList() { Widget child = new Container(); if (this.widget.viewModel.messageLoading) { child = new GlobalLoading(); } else { if (this.widget.viewModel.messageList.Count <= 0) { child = new BlankView("暂无聊天内容", null); } else { child = new SmartRefresher( controller: this._refreshController, enablePullDown: this.widget.viewModel.hasMore, enablePullUp: false, onRefresh: this._onRefresh, child: ListView.builder( padding: EdgeInsets.only(16, right: 16, bottom: 10), physics: new AlwaysScrollableScrollPhysics(), itemCount: this.widget.viewModel.messageList.Count, itemBuilder: (cxt, index) => { var messageId = this.widget.viewModel.messageList[ this.widget.viewModel.messageList.Count - index - 1]; var messageDict = new Dictionary <string, Message>(); if (this.widget.viewModel.channelMessageDict.ContainsKey( this.widget.viewModel.channelId)) { messageDict = this.widget.viewModel.channelMessageDict[this.widget.viewModel.channelId]; } var message = new Message(); if (messageDict.ContainsKey(messageId)) { message = messageDict[messageId]; } return(new ChatMessage( message )); } ) ); } } return(new Flexible( child: new GestureDetector( onTap: () => this._focusNode.unfocus(), child: new Container( color: CColors.White, child: child ) ) )); }
Widget _buildArticleList() { Widget content = new Container(); if (this.widget.viewModel.articlesLoading && this.widget.viewModel.articleList.isEmpty()) { content = ListView.builder( itemCount: 4, itemBuilder: (cxt, index) => new ArticleLoading() ); } else if (this.widget.viewModel.articleList.Count <= 0) { content = new BlankView("暂无文章", true, () => { this.widget.actionModel.startFetchArticles(); this.widget.actionModel.fetchArticles(initOffset); }); } else { content = new SmartRefresher( controller: this._refreshController, enablePullDown: true, enablePullUp: this.widget.viewModel.hottestHasMore, onRefresh: this.onRefresh, child: ListView.builder( physics: new AlwaysScrollableScrollPhysics(), itemCount: this.widget.viewModel.articleList.Count, itemBuilder: (cxt, index) => { var articleId = this.widget.viewModel.articleList[index]; if (this.widget.viewModel.blockArticleList.Contains(articleId)) { return(new Container()); } var article = this.widget.viewModel.articleDict[articleId]; var fullName = ""; if (article.ownerType == OwnerType.user.ToString()) { if (this.widget.viewModel.userDict.ContainsKey(article.userId)) { fullName = this.widget.viewModel.userDict[article.userId].fullName; } } if (article.ownerType == OwnerType.team.ToString()) { if (this.widget.viewModel.teamDict.ContainsKey(article.teamId)) { fullName = this.widget.viewModel.teamDict[article.teamId].name; } } return(new ArticleCard( article, () => this.widget.actionModel.pushToArticleDetail(articleId), () => ReportManager.showReportView(this.widget.viewModel.isLoggedIn, articleId, ReportType.article, this.widget.actionModel.pushToLogin, this.widget.actionModel.pushToReport, this.widget.actionModel.pushToBlock ), fullName, new ObjectKey(article.id) )); } ) ); } return(new NotificationListener <ScrollNotification>( onNotification: this._onNotification, child: new Container( color: CColors.Background, child: content ) )); }
public override Widget build(BuildContext context) { this.widget.viewModel.articleDict.TryGetValue(key: this.widget.viewModel.articleId, value: out this._article); if (this.widget.viewModel.articleDetailLoading && (this._article == null || !this._article.isNotFirst)) { return(new Container( color: CColors.White, child: new CustomSafeArea( child: new Column( children: new List <Widget> { this._buildNavigationBar(false), new ArticleDetailLoading() } ) ) )); } if (this._article == null || this._article.channelId == null) { return(new Container( color: CColors.White, child: new CustomSafeArea( child: new Column( children: new List <Widget> { this._buildNavigationBar(false), new Flexible( child: new BlankView("帖子不存在", "image/default-history") ) } ) ) ));; } if (this._article.ownerType == "user") { if (this._article.userId != null && this.widget.viewModel.userDict.TryGetValue(this._article.userId, out this._user)) { this._user = this.widget.viewModel.userDict[key : this._article.userId]; } } if (this._article.ownerType == "team") { if (this._article.teamId != null && this.widget.viewModel.teamDict.TryGetValue(this._article.teamId, out this._team)) { this._team = this.widget.viewModel.teamDict[key : this._article.teamId]; } } if (this._titleHeight == 0f && this._article.title.isNotEmpty()) { this._titleHeight = CTextUtils.CalculateTextHeight( text: this._article.title, textStyle: CTextStyle.H3, MediaQuery.of(context).size.width - 16 * 2, // 16 is horizontal padding null ) + 16; // 16 is top padding this.setState(() => { }); } var commentIndex = 0; var originItems = this._article == null ? new List <Widget>() : this._buildItems(context, out commentIndex); commentIndex = this._jumpState == _ArticleJumpToCommentState.active ? commentIndex : 0; this._jumpState = _ArticleJumpToCommentState.Inactive; Widget contentWidget; //happens at the next frame after user presses the "Comment" button //we rebuild a CenteredRefresher so that we can calculate out the comment section's position if (this._needRebuildWithCachedCommentPosition == false && commentIndex != 0) { contentWidget = new CenteredRefresher( controller: this._refreshController, enablePullDown: false, enablePullUp: this._article.hasMore, onRefresh: this._onRefresh, onNotification: this._onNotification, children: originItems, centerIndex: commentIndex ); } else { //happens when the page is updated or (when _needRebuildWithCachedCommentPosition is true) at the next frame after //a CenteredRefresher is created and the comment section's position is estimated //we use 0 or this estimated position to initiate the SmartRefresher's init scroll offset, respectively D.assert(!this._needRebuildWithCachedCommentPosition || this._cachedCommentPosition != null); contentWidget = new SmartRefresher( initialOffset: this._needRebuildWithCachedCommentPosition ? this._cachedCommentPosition.Value : 0f, controller: this._refreshController, enablePullDown: false, enablePullUp: this._article.hasMore, onRefresh: this._onRefresh, onNotification: this._onNotification, child: ListView.builder( physics: new AlwaysScrollableScrollPhysics(), itemCount: originItems.Count, itemBuilder: (cxt, index) => originItems[index] )); if (this._needRebuildWithCachedCommentPosition) { this._needRebuildWithCachedCommentPosition = false; //assume that when we jump to the comment, the title should always be shown as the header //this assumption will fail when an article is shorter than 16 pixels in height (as referred to in _onNotification this._controller.forward(); this._isHaveTitle = true; } } var child = new Container( color: CColors.Background, child: new Column( children: new List <Widget> { this._buildNavigationBar(), new Expanded( child: new CustomScrollbar( child: contentWidget ) ), this._buildArticleTabBar() } ) ); return(new Container( color: CColors.White, child: new CustomSafeArea( child: child ) )); }
Widget _buildArticleList(BuildContext context) { Widget content; var recommendArticleIds = this.widget.viewModel.recommendArticleIds; if (!this._hasBeenLoadedData || this.widget.viewModel.articlesLoading && recommendArticleIds.isEmpty()) { content = ListView.builder( physics: new NeverScrollableScrollPhysics(), itemCount: 6, itemBuilder: (cxt, index) => new ArticleLoading() ); } else if (0 == recommendArticleIds.Count) { content = new Container( padding: EdgeInsets.only(bottom: CConstant.TabBarHeight + CCommonUtils.getSafeAreaBottomPadding(context: context)), child: new BlankView( "哎呀,暂无推荐文章", "image/default-article", true, () => { this.widget.actionModel.startFetchArticles(); this.widget.actionModel.fetchArticles(arg: initOffset); } ) ); } else { content = new SmartRefresher( controller: this._refreshController, enablePullDown: true, enablePullUp: this.widget.viewModel.hottestHasMore, onRefresh: this._onRefresh, hasBottomMargin: true, child: ListView.builder( physics: new AlwaysScrollableScrollPhysics(), itemCount: recommendArticleIds.Count, itemBuilder: (cxt, index) => { var articleId = recommendArticleIds[index: index]; if (this.widget.viewModel.blockArticleList.Contains(item: articleId)) { return(new Container()); } if (!this.widget.viewModel.articleDict.ContainsKey(key: articleId)) { return(new Container()); } if (!this.widget.viewModel.hottestHasMore && recommendArticleIds.Count > 0 && index + 1 == recommendArticleIds.Count) { return(new EndView(hasBottomMargin: true)); } var article = this.widget.viewModel.articleDict[key: articleId]; var fullName = ""; var userId = ""; if (article.ownerType == OwnerType.user.ToString()) { userId = article.userId; if (this.widget.viewModel.userDict.ContainsKey(key: article.userId)) { fullName = this.widget.viewModel.userDict[key: article.userId].fullName ?? this.widget.viewModel.userDict[key: article.userId].name; } } if (article.ownerType == OwnerType.team.ToString()) { userId = article.teamId; if (this.widget.viewModel.teamDict.ContainsKey(key: article.teamId)) { fullName = this.widget.viewModel.teamDict[key: article.teamId].name; } } var linkUrl = CStringUtils.JointProjectShareLink(projectId: article.id); return(new ArticleCard( article: article, () => { this.widget.actionModel.pushToArticleDetail(obj: articleId); AnalyticsManager.ClickEnterArticleDetail("Home_Article", articleId: article.id, articleTitle: article.title); }, () => ShareManager.showArticleShareView( this.widget.viewModel.currentUserId != userId, isLoggedIn: this.widget.viewModel.isLoggedIn, () => { Clipboard.setData(new ClipboardData(text: linkUrl)); CustomDialogUtils.showToast("复制链接成功", iconData: Icons.check_circle_outline); }, () => this.widget.actionModel.pushToLogin(), () => this.widget.actionModel.pushToBlock(obj: article.id), () => this.widget.actionModel.pushToReport(arg1: article.id, arg2: ReportType.article), type => { CustomDialogUtils.showCustomDialog( child: new CustomLoadingDialog() ); string imageUrl = CImageUtils.SizeTo200ImageUrl(article.thumbnail.url); this.widget.actionModel.shareToWechat(arg1: type, arg2: article.title, arg3: article.subTitle, arg4: linkUrl, arg5: imageUrl) .Then(onResolved: CustomDialogUtils.hiddenCustomDialog) .Catch(_ => CustomDialogUtils.hiddenCustomDialog()); } ), fullName: fullName, key: new ObjectKey(value: article.id) )); } ) ); } if (this.widget.viewModel.isLoggedIn) { return(new Container( color: CColors.Background, child: new CustomScrollbar(child: content) )); } return(new NotificationListener <ScrollNotification>( onNotification: this._onNotification, child: new Container( color: CColors.Background, child: new CustomScrollbar(child: content) ) )); }
Widget _buildContent() { var followArticleIds = this.widget.viewModel.followArticleIds; var followings = this.widget.viewModel.followings; var hotArticleIds = this.widget.viewModel.hotArticleIds; var followArticleLoading = this.widget.viewModel.followArticlesLoading && followArticleIds.isEmpty() && hotArticleIds.isEmpty(); var followingLoading = this.widget.viewModel.followingLoading && followings.isEmpty(); Widget content; if (followArticleLoading || followingLoading) { content = new FollowArticleLoading(); } else if (followArticleIds.isEmpty()) { var itemCount = followings.isEmpty() ? hotArticleIds.Count : hotArticleIds.Count + 1; if (!this.widget.viewModel.hotArticleHasMore) { itemCount = itemCount + 1; } content = new SmartRefresher( controller: this._refreshController, enablePullDown: true, enablePullUp: this.widget.viewModel.hotArticleHasMore, onRefresh: up => this._onRefresh(up: up, true), child: ListView.builder( physics: new AlwaysScrollableScrollPhysics(), itemCount: itemCount, itemBuilder: (cxt, index) => this._buildFollowArticleCard(context: cxt, index: index, false) ) ); } else { var itemCount = followings.isEmpty() ? followArticleIds.Count : followArticleIds.Count + 1; if (!this.widget.viewModel.followArticleHasMore) { itemCount = itemCount + 1; } content = new SmartRefresher( controller: this._refreshController, enablePullDown: true, enablePullUp: this.widget.viewModel.followArticleHasMore, onRefresh: up => this._onRefresh(up: up, false), child: ListView.builder( physics: new AlwaysScrollableScrollPhysics(), itemCount: itemCount, itemBuilder: (cxt, index) => this._buildFollowArticleCard(context: cxt, index: index) ) ); } return(new Container( color: CColors.Background, child: new CustomScrollbar(child: content) )); }