Esempio n. 1
0
        /// <summary>
        ///     Adds an item to the feed
        /// </summary>
        /// <param name="color"></param>
        /// <param name="text"></param>
        public void AddItem(Color color, string text)
        {
            var item = new MultiplayerFeedItem(color, text)
            {
                Parent    = this,
                Alignment = Alignment.BotLeft,
                X         = 10
            };

            FeedItems.Add(item);

            if (FeedItems.Count == 6)
            {
                var first = FeedItems.First();
                first.Destroy();
                FeedItems.Remove(first);
            }

            for (var i = FeedItems.Count - 1; i >= 0; i--)
            {
                var feedItem = FeedItems[i];

                feedItem.ClearAnimations();
                feedItem.MoveToY(-22 * (FeedItems.Count - i - 1) - 11, Easing.OutQuint, 200);
            }
        }
Esempio n. 2
0
		private async Task _Refresh()
		{
			if (!IsNeedRefresh) { return; }

			Debug.WriteLine($"{Label} starting update feed.");

			var updateTime = DateTime.Now;
			var latestItems = new List<FeedItem>();
			foreach (var feedSource in _FeedSourceList)
			{
				var items = await feedSource.GetLatestItems(HohoemaApp);
				foreach (var item in items)
				{
					latestItems.Add(item);
				}
			}


			var latestOrderedItems = latestItems
				.OrderByDescending(x => x.SubmitDate)
				.Take(MaxFeedItemsCount)
				.ToList();

			foreach (var item in latestOrderedItems)
			{
				item.CheckedTime = updateTime;
			}

			var exceptItems = latestOrderedItems.Except(FeedItems, FeedItemComparer.Default).ToList();

			var addedItems = exceptItems.Where(x => x.CheckedTime == updateTime);

			var removedItems = FeedItems
				.Except(latestOrderedItems, FeedItemComparer.Default)
				.Where(x => x.CheckedTime != updateTime)
				.ToList();


			foreach (var addItem in addedItems)
			{
				addItem.IsUnread = true;

				// 投稿日時が初期化されていない場合はThumbnailInfoから拾ってくる

				// ユーザー動画取得の場合に投稿時刻が取れないことが原因
				// 追加されたアイテムだけのThumbnailを取得することで無駄な処理を減らす
				if (addItem.SubmitDate == default(DateTime))
				{
					try
					{
						var nicoVideo = await HohoemaApp.MediaManager.GetNicoVideoAsync(addItem.VideoId);
						
						addItem.SubmitDate = nicoVideo.PostedAt;
					}
					catch (Exception ex)
					{
						Debug.Fail("UserFeedItem 更新中、NicoVideoオブジェクトの取得に失敗しました。", ex.Message);
					}
				}
				

				FeedItems.Add(addItem);
			}

			foreach (var removedItem in removedItems)
			{
				var item = FeedItems.SingleOrDefault(x => x.VideoId == removedItem.VideoId);
				if (item != null)
				{
					item.IsDeleted = true;
					FeedItems.Remove(item);
				}

			}

			FeedItems.Sort(FeedItemComparer.Default);

			UpdateTime = updateTime;

			await FeedManager.SaveOne(this);

            Completed?.Invoke(this);

            IsNeedRefresh = false;

			Debug.WriteLine($"{Label} update feed done.");
		}