public async void fetchSurveyDetail() { try { if (survey == null) { survey = await new FeedManager().GetSurvey(this.userId, this.creationDate, LoginController.tokenModel.access_token); } else { this.userId = survey.userId; this.creationDate = survey.creationDate; } ReportManager reportManager = new ReportManager(); List <ReportModel> reportsDatasets = new List <ReportModel>(); reportsDatasets.Add(await reportManager.GetOverallResults(this.userId, this.creationDate, LoginController.tokenModel.access_token)); reportsDatasets.Add(await reportManager.GetResultsByGender(this.userId, this.creationDate, LoginController.tokenModel.access_token)); reportsDatasets.Add(await reportManager.GetResultsByAge(this.userId, this.creationDate, LoginController.tokenModel.access_token)); var feedCellHeight = Utils.getHeightForFeedCell(survey, View.Frame.Width); feedCell = new FeedCollectionViewCell(new CGRect(0, 0, View.Frame.Width, feedCellHeight)); feedController.BindFeedCell(feedCell, survey, indexPathRow); feedCell.resultButton.RemoveTarget(null, null, UIControlEvent.AllEvents); if (feedController.NavigationController == null) { feedCell.commentButton.Params[2] = this.NavigationController; feedCell.moreButton.Params[2] = this; (feedCell.profileImageView.GestureRecognizers[0] as UIFeedTapGestureRecognizer).Params[0] = this.NavigationController; } feed.Source = new ResultsCollectionViewSource(reports, reportsDatasets, feedCell); feed.Delegate = new ResultsCollectionViewDelegate((float)feedCell.Frame.Height); feed.ReloadData(); BTProgressHUD.Dismiss(); } catch (Exception ex) { BTProgressHUD.Dismiss(); Utils.HandleException(ex); } }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); this.RestrictRotation(UIInterfaceOrientationMask.Portrait); var feedCellHeight = Utils.getHeightForFeedCell(CreateSurveyController.SurveyModel, View.Frame.Width); feedCell = new FeedCollectionViewCell(new CGRect(0, 0, View.Frame.Width, feedCellHeight)); Utils.BindFeedCell(feedCell, CreateSurveyController.SurveyModel, 0, this, true); UIScrollView scrollView = new UIScrollView(); scrollView.Frame = new CGRect(0, 70, View.Frame.Width, View.Frame.Height - 70); scrollView.ContentSize = new CGSize(View.Frame.Width, feedCellHeight); scrollView.LayoutIfNeeded(); scrollView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; scrollView.AddSubview(feedCell); View.AddSubview(scrollView); //View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); //View.AddConstraints( // scrollView.WithSameCenterX(View), // scrollView.AtTopOf(View, 70), // scrollView.AtLeftOf(View), // scrollView.AtRightOf(View), // scrollView.Height().EqualTo(feedCellHeight), // feedCell.WithSameCenterX(scrollView), // feedCell.AtTopOf(scrollView), // feedCell.AtLeftOf(scrollView), // feedCell.AtRightOf(scrollView), // feedCell.Height().EqualTo(feedCellHeight) //); StepActivated?.Invoke(this, new MultiStepProcessStepEventArgs { Index = StepIndex }); }
public ResultsCollectionViewSource(List <ReportType> reports, List <ReportModel> reportsDatasets, FeedCollectionViewCell feedCell) { this.reports = reports; this.feedCell = feedCell; this.reportsDatasets = reportsDatasets; this.chartColors = new List <UIColor>(); this.chartColors.Add(UIColor.FromRGBA(0, 211, 213, 100)); this.chartColors.Add(UIColor.FromRGBA(0, 160, 70, 100)); this.chartColors.Add(UIColor.FromRGBA(220, 40, 40, 100)); this.chartColors.Add(UIColor.FromRGBA(250, 220, 0, 100)); this.chartColors.Add(UIColor.FromRGBA(190, 40, 150, 100)); this.chartColors.Add(UIColor.FromRGBA(0, 74, 91, 100)); this.chartColors.Add(UIColor.FromRGBA(0, 143, 152, 100)); this.chartColors.Add(UIColor.FromRGBA(0, 128, 46, 100)); this.chartColors.Add(UIColor.FromRGBA(168, 24, 24, 100)); this.chartColors.Add(UIColor.FromRGBA(190, 160, 0, 100)); this.chartColors.Add(UIColor.FromRGBA(0, 96, 22, 100)); this.chartColors.Add(UIColor.FromRGBA(116, 8, 8, 100)); this.chartColors.Add(UIColor.FromRGBA(130, 100, 0, 100)); this.chartColors.Add(UIColor.FromRGBA(94, 8, 54, 100)); this.chartColors.Add(UIColor.FromRGBA(142, 24, 102, 100)); this.chartColors.Add(UIColor.FromRGBA(176, 54, 121, 100)); this.chartColors.Add(UIColor.FromRGBA(184, 98, 26, 100)); this.chartColors.Add(UIColor.FromRGBA(204, 64, 147, 100)); this.chartColors.Add(UIColor.FromRGBA(255, 84, 44, 100)); this.chartColors.Add(UIColor.FromRGBA(140, 100, 210, 100)); this.chartColors.Add(UIColor.FromRGBA(210, 36, 114, 100)); this.chartColors.Add(UIColor.FromRGBA(179, 49, 9, 100)); this.chartColors.Add(UIColor.FromRGBA(155, 73, 9, 100)); this.chartColors.Add(UIColor.FromRGBA(120, 68, 162, 100)); this.chartColors.Add(UIColor.FromRGBA(217, 66, 26, 100)); this.chartColors.Add(UIColor.FromRGBA(20, 20, 20, 100)); this.chartColors.Add(UIColor.FromRGBA(56, 56, 56, 100)); this.chartColors.Add(UIColor.FromRGBA(92, 92, 92, 100)); this.chartColors.Add(UIColor.FromRGBA(128, 128, 128, 100)); this.chartColors.Add(UIColor.FromRGBA(164, 164, 164, 100)); }
public static void BindFeedCell(FeedCollectionViewCell feedCell, SurveyModel survey, int indexPathRow, NSObject controller, bool isPreview = false) { if (survey.profilePicture != null) { Utils.SetImageFromNSUrlSession(survey.profilePicture, feedCell.profileImageView, controller, PictureType.Profile); } else { feedCell.profileImageView.Image = UIImage.FromBundle("Profile"); } var attributedText = new NSMutableAttributedString(survey.userName, UIFont.BoldSystemFontOfSize(14)); if (!isPreview) { if ("Groups".Equals(survey.targetAudience)) { var x = 0; foreach (string group in survey.targetAudienceGroups.names) { if (x == 0) { attributedText.Append(new NSAttributedString("\n" + group, UIFont.SystemFontOfSize(12), UIColor.FromRGBA(nfloat.Parse("0.60"), nfloat.Parse("0.63"), nfloat.Parse("0.67"), nfloat.Parse("1")))); } else { attributedText.Append(new NSAttributedString(", " + group, UIFont.SystemFontOfSize(12), UIColor.FromRGBA(nfloat.Parse("0.60"), nfloat.Parse("0.63"), nfloat.Parse("0.67"), nfloat.Parse("1")))); } x++; } } else { attributedText.Append(new NSAttributedString("\n" + survey.targetAudience, UIFont.SystemFontOfSize(12), UIColor.FromRGBA(nfloat.Parse("0.60"), nfloat.Parse("0.63"), nfloat.Parse("0.67"), nfloat.Parse("1")))); } attributedText.Append(new NSAttributedString(" • " + TimeAgoDisplay(ConvertToLocalTime(DateTime.ParseExact(survey.creationDate, "yyyyMMddTHHmmss", null))), UIFont.SystemFontOfSize(12), UIColor.FromRGBA(nfloat.Parse("0.60"), nfloat.Parse("0.63"), nfloat.Parse("0.67"), nfloat.Parse("1")))); } var paragraphStyle = new NSMutableParagraphStyle(); paragraphStyle.LineSpacing = 4; attributedText.AddAttribute(new NSString("ParagraphStyle"), paragraphStyle, new NSRange(0, attributedText.Length)); feedCell.nameLabel.AttributedText = attributedText; bool finished = false; bool reported = false; var reportedLabel = findFirstLabelWithBkgColor(feedCell, UIColor.FromRGB(255, 201, 3)); if (reportedLabel != null) { reportedLabel.RemoveFromSuperview(); } if (string.IsNullOrEmpty(survey.finishDate)) { feedCell.finishedLabel.Text = ""; //feedCell.moreButton.Hidden = false; feedCell.optionsTableView.AllowsSelection = true; feedCell.optionsCollectionView.AllowsSelection = true; finished = false; } else { feedCell.finishedLabel.Text = "Finished"; //feedCell.moreButton.Hidden = true; feedCell.optionsTableView.AllowsSelection = false; feedCell.optionsCollectionView.AllowsSelection = false; finished = true; feedCell.AddSubview(feedCell.finishedLabel); feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-8-[v0]-8-|", new NSLayoutFormatOptions(), "v0", feedCell.finishedLabel)); } if (survey.userId.Equals(LoginController.userModel.id) && (survey.reportedByUsersIds != null && survey.reportedByUsersIds.Count > 0)) { feedCell.reportedLabel.Text = "Reported"; reported = true; feedCell.AddSubview(feedCell.reportedLabel); feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-8-[v0]-8-|", new NSLayoutFormatOptions(), "v0", feedCell.reportedLabel)); } else { feedCell.reportedLabel.Text = ""; reported = false; } if (isPreview) { finished = false; reported = false; } feedCell.questionText.Text = survey.question.text; if (survey.type == SurveyType.Text.ToString()) { feedCell.optionsTableView.ContentMode = UIViewContentMode.ScaleAspectFill; feedCell.optionsTableView.Layer.MasksToBounds = true; feedCell.optionsTableView.TranslatesAutoresizingMaskIntoConstraints = false; feedCell.optionsTableView.ContentInset = new UIEdgeInsets(0, -10, 0, 0); feedCell.optionsTableView.Tag = indexPathRow; feedCell.optionsTableView.FeedCell = feedCell; feedCell.optionsTableViewSource.survey = survey; feedCell.optionsTableView.Source = feedCell.optionsTableViewSource; feedCell.optionsTableView.TableFooterView = new UIView(frame: new CGRect(x: 0, y: 0, width: feedCell.optionsTableView.Frame.Size.Width, height: 1)); feedCell.optionsTableView.ReloadData(); feedCell.optionsCollectionView.RemoveFromSuperview(); feedCell.AddSubview(feedCell.optionsTableView); feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[v0]|", new NSLayoutFormatOptions(), "v0", feedCell.optionsTableView)); if (finished) { if (reported) { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-8-[v1(32)]-8-[v2(32)]-4-[v3]-4-[v4]-8-[v5(1)][v6(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.finishedLabel, "v2", feedCell.reportedLabel, "v3", feedCell.questionText, "v4", feedCell.optionsTableView, "v5", feedCell.dividerLineView, "v6", feedCell.contentViewButtons)); } else { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-8-[v1(32)]-4-[v2]-4-[v3]-8-[v4(1)][v5(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.finishedLabel, "v2", feedCell.questionText, "v3", feedCell.optionsTableView, "v4", feedCell.dividerLineView, "v5", feedCell.contentViewButtons)); } } else { if (reported) { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-8-[v1(32)]-4-[v2]-4-[v3]-8-[v4(1)][v5(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.reportedLabel, "v2", feedCell.questionText, "v3", feedCell.optionsTableView, "v4", feedCell.dividerLineView, "v5", feedCell.contentViewButtons)); } else { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-4-[v1]-4-[v2]-8-[v3(1)][v4(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.questionText, "v2", feedCell.optionsTableView, "v3", feedCell.dividerLineView, "v4", feedCell.contentViewButtons)); } } if (isPreview) { feedCell.optionsTableView.ScrollEnabled = false; feedCell.optionsTableView.AllowsSelection = false; } } else { feedCell.optionsCollectionView.TranslatesAutoresizingMaskIntoConstraints = false; feedCell.optionsCollectionView.Tag = indexPathRow; feedCell.optionsCollectionView.FeedCell = feedCell; feedCell.optionsCollectionViewSource.survey = survey; feedCell.optionsCollectionViewSource.isPreview = isPreview; feedCell.optionsCollectionView.Source = feedCell.optionsCollectionViewSource; feedCell.optionsCollectionViewDelegate.optionsCollectionViewSource = feedCell.optionsCollectionViewSource; feedCell.optionsCollectionViewDelegate.survey = survey; feedCell.optionsCollectionView.Delegate = feedCell.optionsCollectionViewDelegate; feedCell.optionsCollectionView.ReloadData(); feedCell.optionsTableView.RemoveFromSuperview(); feedCell.AddSubview(feedCell.optionsCollectionView); feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|[v0]|", new NSLayoutFormatOptions(), "v0", feedCell.optionsCollectionView)); if (finished) { if (reported) { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-8-[v1(32)]-8-[v2(32)]-4-[v3]-4-[v4(290)]-8-[v5(1)][v6(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.finishedLabel, "v2", feedCell.reportedLabel, "v3", feedCell.questionText, "v4", feedCell.optionsCollectionView, "v5", feedCell.dividerLineView, "v6", feedCell.contentViewButtons)); } else { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-8-[v1(32)]-4-[v2]-4-[v3(290)]-8-[v4(1)][v5(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.finishedLabel, "v2", feedCell.questionText, "v3", feedCell.optionsCollectionView, "v4", feedCell.dividerLineView, "v5", feedCell.contentViewButtons)); } } else { if (reported) { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-8-[v1(32)]-4-[v2]-4-[v3(290)]-8-[v4(1)][v5(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.reportedLabel, "v2", feedCell.questionText, "v3", feedCell.optionsCollectionView, "v4", feedCell.dividerLineView, "v5", feedCell.contentViewButtons)); } else { feedCell.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(44)]-4-[v1]-4-[v2(290)]-8-[v3(1)][v4(44)]|", new NSLayoutFormatOptions(), "v0", feedCell.profileImageView, "v1", feedCell.questionText, "v2", feedCell.optionsCollectionView, "v3", feedCell.dividerLineView, "v4", feedCell.contentViewButtons)); } } if (isPreview) { feedCell.optionsCollectionView.AllowsSelection = false; } } feedCell.updateTotalVotes(survey.totalVotes); feedCell.updateTotalComments(survey.totalComments); feedCell.updateTotalLikes(survey.totalLikes); if (survey.userLiked == true) { feedCell.updateLikeButtonText(false, survey.totalLikes); } else if (survey.userLiked == null || survey.userLiked == false) { feedCell.updateLikeButtonText(true, survey.totalLikes); } }
public CommentsCollectionViewSource(List <SurveyCommentModel> comments, FeedCollectionViewCell feedCell, CommentViewController commentViewController) { this.comments = comments; this.feedCell = feedCell; this.commentViewController = commentViewController; }
public async void fetchSurveyComments(bool scrollToLastItem) { try { if (survey == null) { survey = await new FeedManager().GetSurvey(this.userId, this.creationDate, LoginController.tokenModel.access_token); } else { this.userId = survey.userId; this.creationDate = survey.creationDate; } comments = await new CommentManager().GetSurveyComments(this.userId + this.creationDate, LoginController.userModel.id, LoginController.tokenModel.access_token); var feedCellHeight = Utils.getHeightForFeedCell(survey, View.Frame.Width); feedCell = new FeedCollectionViewCell(new CGRect(0, 0, View.Frame.Width, feedCellHeight)); feedController.BindFeedCell(feedCell, survey, indexPathRow); feedCell.commentButton.RemoveTarget(null, null, UIControlEvent.AllEvents); feedCell.commentButton.AddTarget(this, new ObjCRuntime.Selector("CommentSelector:"), UIControlEvent.TouchUpInside); if (feedController.NavigationController == null) { feedCell.resultButton.Params[2] = this.NavigationController; feedCell.moreButton.Params[2] = this; (feedCell.profileImageView.GestureRecognizers[0] as UIFeedTapGestureRecognizer).Params[0] = this.NavigationController; } feed.Source = new CommentsCollectionViewSource(comments, feedCell, this); feed.Delegate = new CommentsCollectionViewDelegate((float)feedCell.Frame.Height); feed.ReloadData(); var section = (int)feed.NumberOfSections() - 1; var item = (int)feed.NumberOfItemsInSection(section) - 1; if (item != -1) { if (scrollToLastItem) { NSIndexPath indexPath = NSIndexPath.FromRowSection(item, section); feed.ScrollToItem(indexPath, UICollectionViewScrollPosition.Bottom, true); } else if (!string.IsNullOrEmpty(commentDate)) { var index = comments.FindIndex(q => q.surveyId == userId + creationDate && q.commentDate == commentDate); if (index != -1) { feed.ScrollToItem(NSIndexPath.FromItemSection(index, 0), UICollectionViewScrollPosition.CenteredVertically, true); } } } BTProgressHUD.Dismiss(); commentArea.CommentText.BecomeFirstResponder(); } catch (Exception ex) { BTProgressHUD.Dismiss(); Utils.HandleException(ex); } }