상속: RequestBase
예제 #1
0
        public Task <ResponsePost> GetPost(RequestPost request)
        {
            var response = CallService <ResponsePost, RequestPost>(Settings.GetPostUrl, HttpMethod.Post, request);

            return(response);
        }
		public async Task LoadPost() {

			if (Status == NetworkStatus.NotReachable) {//true || 
				ShowErrorMessage (Settings.MSG_NETWORK_NOT_REACHABLE);
				return;
			}

			IsLoading = true;

			RequestPost req = new RequestPost();
			req.Id = Post.Id;
			ResponsePost detailPost;

			try{
				detailPost = await Service.GetPost (req);
				Post = detailPost.Post;
				if (Post.Kento_vote != null) {
					IsLikedThisPost = Post.Kento_vote.Vote_status == 1;
					Like_count = Post.Kento_vote.Vote_up_total;
				}
				Title = Post.FirstCategoryName;//category name - home post
			} catch (Exception e){
				Debug.WriteLine (e);
				ShowErrorMessage (Settings.MSG_NETWORK_COMMON, e);
				return;
			}

			var doc = new HtmlAgilityPack.HtmlDocument();

			//remove ulike info
			try {
				doc.LoadHtml(detailPost.Post.Content);
				foreach(var item in doc.DocumentNode.ChildNodes)
				{
					if (item.Id.StartsWith ("kento-vote")) {
						item.InnerHtml = string.Empty;
						Debug.WriteLine ("Empty ULike Info: " + item.OuterHtml);
					}

					//remove follow & unfollow content
					if (item.Attributes["class"] != null && item.Attributes["class"].Value.StartsWith("wpw-fp-follow-post-wrapper"))
						item.InnerHtml = string.Empty;
				}
				var stringBuilder = new System.Text.StringBuilder();
				doc.Save (new System.IO.StringWriter(stringBuilder));

				Post.Content = stringBuilder.ToString();
			} catch (Exception e) {
				ShowErrorMessage (Settings.MSG_NETWORK_COMMON, e);
			}

			//Repair comment content to plain text
			try {
				Comment_count = Post.Comment_count;
				foreach (Comment comment in Post.Comments) {
					doc.LoadHtml(comment.Content);
					foreach(var item in doc.DocumentNode.ChildNodes)// "//div" is a xpath which means select div nodes that are anywhere in the html

					{
						if (item.Id.StartsWith ("wp-ulike-comment-")) {
							item.InnerHtml = string.Empty;
							Debug.WriteLine (item.OuterHtml);
						}
					}

					comment.Content = System.Net.WebUtility.HtmlDecode (doc.DocumentNode.InnerText);
					Comments.Add (comment);
				}
			} catch (Exception e) {
				Debug.WriteLine ("[CommentPage-LoadComments] {0}", e);
			}
			string featured_img = Post.FullImage; //Post.IconSource==null ? "" : (Post.Thumbnail_images.Full.Url ?? Post.IconSource) ;			
			string timeAgo = new TimeAgoValueConverter ().Convert (Post.Date, null, null, null).ToString();
//			Html = NewsTemplates.DETAIL_TEMPLATE_HEADER + String.Format(NewsTemplates.DETAIL_TEMPLATE_BODY, Post.Title, timeAgo, featured_img ,Post.Content, Post.FirstCategoryName);
			Html = String.Format(NewsTemplates.DETAIL_TEMPLATE, Post.Title, timeAgo, featured_img ,Post.Content, Post.FirstCategoryName);
			//test video player
			//Html = string.Format(NewsTemplates.DETAIL_VIDEO_PLAYER, "http://techslides.com/demos/sample-videos/small.mp4");


			RaisePropertyChanged ("Comment_count");
			RaisePropertyChanged ("Comments");

			IsLoading = false;
		}