예제 #1
0
 public CommentViewModel()
 {
     OwnerName = "OwnerName";
     CommentDate = "00:00";
     ActorIcon = SampleData.DataLoader.LoadImage("accountIcon00.png").Result;
     PostContentInline = new StyleElement(StyleType.None, new[] { new TextElement("Comment Content Text") });
 }
예제 #2
0
 public async Task Refresh()
 {
     var postDate = TimeZone.CurrentTimeZone.ToLocalTime(_model.CommentInfo.PostDate);
     CommentDate = postDate >= DateTime.Today ? postDate.ToString("HH:mm") : postDate.ToString("yyyy/MM/dd");
     OwnerName = _model.CommentInfo.Owner.Name;
     ActorIcon = await DataCacheDictionary.DownloadImage(new Uri(_model.CommentInfo.Owner.IconImageUrl
         .Replace("$SIZE_SEGMENT", "s25-c-k").Replace("$SIZE_NUM", "80"))).ConfigureAwait(false);
     PostContentInline = _model.CommentInfo.GetParsedContent();
 }
 public AttachedActivityViewModel(string ownerName, Uri ownerProfileUrl, Uri ownerActivityUrl,
     ImageSource ownerIcon, StyleElement postContentInline, object attachedContent)
 {
     _ownerName = ownerName;
     _ownerProfileUrl = ownerProfileUrl;
     _ownerActivityUrl = ownerActivityUrl;
     _ownerIcon = ownerIcon;
     _postContentInline = postContentInline;
     _attachedContent = attachedContent;
 }
예제 #4
0
 public ActivityViewModel()
 {
     ActorIcon = SampleData.DataLoader.LoadImage("accountIcon00.png").Result;
     ActivityUrl = new Uri("https://plus.google.com");
     IsEnableCommentsHeader = true;
     IsCheckedCommentsHeader = false;
     IsOpenedCommentList = false;
     IsLoadingCommentList = true;
     CommentLength = 5;
     PostUserName = "******";
     PostDate = "00:00";
     _comments = new ReadOnlyDispatcherCollection<CommentViewModel>(
         new DispatcherCollection<CommentViewModel>(
         new ObservableCollection<CommentViewModel>(
             Enumerable.Range(0, 2).Select(_ => new CommentViewModel())), App.Current.Dispatcher));
     PostContentInline = new StyleElement(StyleType.None, new[] { new TextElement("Activity Content Text") });
 }
        public static StyleElement ParseJson(JToken contentJson)
        {
            contentJson = contentJson.ElementAtOrDefault(0);
            if (contentJson == null)
                return new StyleElement(StyleType.None, new List<ContentElement>());

            var styleStatus = new[] { false, false, false };
            var styleStack = new Stack<StyleType>();
            var blocksStack = new Stack<List<ContentElement>>();
            blocksStack.Push(new List<ContentElement>());
            foreach (var item in contentJson)
                switch ((int)item[0])
                {
                    case 0:
                    case 2:
                    case 3:
                    case 4:
                        //itemの書式を取得
                        var newStyleStatus = new[] { false, false, false };
                        if (item.Count() > 2 && item[2].Type == JTokenType.Array)
                            foreach (var styleItem in item[2].Select((token, idx) => new { Token = token, Index = idx }))
                                newStyleStatus[styleItem.Index] = styleItem.Token.Type != JTokenType.Null && (int)styleItem.Token == 1;
                        //書式解除があった場合は新旧比較し、解除書式全てを消すまで書式スタックを削る
                        //ここで開始地点がスライドしてる書式などの巻き添えになる書式も発生する。その
                        //書式は後続の書式追加で補填する
                        for (var currentStyleIdx = 0; currentStyleIdx < styleStatus.Length; currentStyleIdx++)
                        {
                            if (newStyleStatus[currentStyleIdx] == false && styleStatus[currentStyleIdx])
                                while (blocksStack.Count > 0)
                                {
                                    styleStatus[(int)styleStack.Peek()] = false;
                                    var newElement = new StyleElement(styleStack.Peek(), blocksStack.Pop());
                                    blocksStack.Peek().Add(newElement);
                                    if (styleStack.Pop() == (StyleType)currentStyleIdx)
                                        break;
                                }
                        }
                        //書式追加がある場合は書式スタックの追加とブロックスタックの最上にある
                        //要素リストを新規追加で新品リストにする
                        for (var currentStyleIdx = 0; currentStyleIdx < styleStatus.Length; currentStyleIdx++)
                        {
                            if (newStyleStatus[currentStyleIdx] && styleStatus[currentStyleIdx] == false)
                            {
                                styleStack.Push((StyleType)currentStyleIdx);
                                styleStatus[currentStyleIdx] = true;
                                blocksStack.Push(new List<ContentElement>());
                            }
                        }
                        switch ((int)item[0])
                        {
                            case 0:
                                blocksStack.Peek().Add(new TextElement((string)item[1]));
                                break;
                            case 2:
                            case 4:
                                blocksStack.Peek().Add(new HyperlinkElement(new Uri((string)item[3][0]), (string)item[1]));
                                break;
                            case 3:
                                blocksStack.Peek().Add(new MensionElement(new ProfileData((string)item[4][1], (string)item[1])));
                                break;
                        }
                        break;
                    case 1:
                        blocksStack.Peek().Add(new BreakElement());
                        break;
                }
            //ルート要素は書式設定無しのスタイル要素にする。しかし、配列に要素が
            //一つしか入っておらず、要素がスタイル要素だった場合には新しく生成せ
            //ずにそのスタイル要素を戻り値とする
            if (blocksStack.Peek().Count == 1 && blocksStack.Peek().First() is StyleElement)
                return (StyleElement)blocksStack.Peek().First();
            else
                return new StyleElement(StyleType.None, blocksStack.Pop());
        }