public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try { RecordSoundFragmentView = inflater.Inflate(Resource.Layout.RecourdSoundFragment, container, false); RecordFilePath = Arguments.GetString("FilePath"); MainActivityView = ((CommentActivity)Activity); MainActivityView.BtnVoice.SetImageResource(Resource.Drawable.microphone); MainActivityView.BtnVoice.Tag = "Audio"; RecordPlayButton = RecordSoundFragmentView.FindViewById <CircleButton>(Resource.Id.playButton); RecordCloseButton = RecordSoundFragmentView.FindViewById <CircleButton>(Resource.Id.closeRecordButton); VoiceSeekBar = RecordSoundFragmentView.FindViewById <SeekBar>(Resource.Id.voiceseekbar); VoiceSeekBar.Progress = 0; RecordCloseButton.Click += RecordCloseButtonClick; RecordPlayButton.Click += RecordPlayButton_Click; RecordPlayButton.Tag = "Stop"; AudioPlayerClass = new Methods.AudioRecorderAndPlayer(MainActivityView.PostId); TimerSound = new Timer(); return(RecordSoundFragmentView); } catch (Exception e) { Console.WriteLine(e); return(null); } }
public async Task FetchPostApiComments(string offset, string postId) { int countList = CommentList.Count; var(apiStatus, respond) = await RequestsAsync.Comment.GetPostComments(postId, "10", offset); if (apiStatus == 200) { if (respond is CommentObject result) { var respondList = result.CommentList?.Count; if (respondList > 0) { foreach (var item in from item in result.CommentList let check = CommentList.FirstOrDefault(a => a.Id == item.Id) where check == null select item) { var db = Mapper.Map <CommentObjectExtra>(item); if (db != null) { CommentList.Add(db); } } if (countList > 0) { ActivityContext.RunOnUiThread(() => { NotifyItemRangeInserted(countList, CommentList.Count - countList); }); } else { ActivityContext.RunOnUiThread(NotifyDataSetChanged); } } } } else { Methods.DisplayReportResult(ActivityContext, respond); } CommentActivity.GetInstance().SwipeRefreshLayout.Refreshing = false; MainScrollEvent.IsLoading = false; if (CommentList.Count > 0) { var emptyStateChecker = CommentList.FirstOrDefault(a => a.Text == EmptyState); if (emptyStateChecker != null && CommentList.Count > 1) { CommentList.Remove(emptyStateChecker); ActivityContext.RunOnUiThread(NotifyDataSetChanged); } } else { CommentList.Clear(); var d = new CommentObjectExtra { Text = EmptyState }; CommentList.Add(d); ActivityContext.RunOnUiThread(NotifyDataSetChanged); } }
public override void OnViewCreated(View view, Bundle savedInstanceState) { try { base.OnViewCreated(view, savedInstanceState); RecordFilePath = Arguments.GetString("FilePath"); MainActivityView = (CommentActivity)Activity; MainActivityView.BtnVoice.SetImageResource(Resource.Drawable.microphone); MainActivityView.BtnVoice.Tag = "Audio"; RecordPlayButton = view.FindViewById <CircleButton>(Resource.Id.playButton); RecordCloseButton = view.FindViewById <CircleButton>(Resource.Id.closeRecordButton); VoiceSeekBar = view.FindViewById <SeekBar>(Resource.Id.voiceseekbar); VoiceSeekBar.Progress = 0; RecordCloseButton.Click += RecordCloseButtonClick; RecordPlayButton.Click += RecordPlayButton_Click; RecordPlayButton.Tag = "Stop"; AudioPlayerClass = new Methods.AudioRecorderAndPlayer(MainActivityView.PostId); TimerSound = new Timer(); } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } }
private Post DoLikeOrComment(long postId) { Post post = db.Posts.Where(p => p.Id == postId).First(); string userId = User.Identity.GetUserId(); string like_com = Request.Params["like_com"]; if (like_com == "Like") { if (db.LikeActivities.Where(activity => activity.PostId == postId && activity.ApplicationUserId == userId).Count() == 0) { LikeActivity act = new LikeActivity(); act = new LikeActivity(); act.ApplicationUserId = userId; act.PostId = postId; act.Like = true; db.LikeActivities.Add(act); post.TotalLikes++; } else { LikeActivity likeAct = db.LikeActivities.Where(activity => activity.PostId == postId && activity.ApplicationUserId == userId).First(); if (!likeAct.Like) { post.TotalLikes++; } likeAct.Like = true; ViewBag.Like = "UnLike"; } db.SaveChanges(); } else if (like_com == "UnLike") { LikeActivity likeAct = db.LikeActivities.Where(activity => activity.PostId == postId && activity.ApplicationUserId == userId).First(); likeAct.Like = false; ViewBag.Like = "Like"; post.TotalLikes--; db.SaveChanges(); } else if (like_com == "Comment") { string comment = Request.Params["UserComment"]; if (!string.IsNullOrWhiteSpace(comment)) { CommentActivity act = new CommentActivity(); act.ApplicationUserId = userId; act.PostId = postId; act.Comment = comment; act.User = db.Users.Where(us => us.Id == userId).First(); db.CommentActivities.Add(act); post.TotalComments++; db.SaveChanges(); } } return(post); }
public ActionResult LikeComment() { string userId = Request.Params["userId"]; string sortOrder = Request.Params["sortOrder"]; long commentId = long.Parse(Request.Params["commentId"]); long postId = long.Parse(Request.Params["postId"]); CommentActivity comment = db.CommentActivities.Where(c => c.CommentId == commentId).First(); //comment.User = db.Users.Where(us => us.Id == comment.ApplicationUserId).First(); if (comment.LikeActivities.Where(c => c.CommentId == commentId).Count() == 0) { LikeActivity act = new LikeActivity(); act = new LikeActivity(); //act.Id = db.LikeActivities.Count() + 1; act.ApplicationUserId = userId; act.PostId = postId; act.CommentId = commentId; act.Like = true; //db.LikeActivities.Add(act); comment.LikeActivities.Add(act); comment.TotalLikes++; } else { LikeActivity act = comment.LikeActivities.Where(c => c.CommentId == commentId).First(); if (!act.Like) { comment.TotalLikes++; } act.CommentId = commentId; act.Like = true; // ViewBag.LikeComment = "UnLike"; } try { db.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(RedirectToAction("Index", "Home")); }
public ActionResult UnLikeComment() { //string userId = Request.Params["userId"]; string sortOrder = Request.Params["sortOrder"]; long commentId = long.Parse(Request.Params["commentId"]); long postId = long.Parse(Request.Params["postId"]); CommentActivity comment = db.CommentActivities.Where(c => c.CommentId == commentId).First(); LikeActivity likeAct = comment.LikeActivities.Where(c => c.CommentId == commentId).First(); likeAct.Like = false; //ViewBag.LikeComment = "Like"; comment.TotalLikes--; db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult LikeOrComment(string returnUrl) { //long postId = long.Parse(Request.Form["postId"]); //string sortOrder = Request.Form["sortOrder"]; //string pageNo = Request.Form["pageNo"]; //Post post = db.Posts.Where(p => p.Id == postId).First(); //string userId = User.Identity.GetUserId(); //string like_com = Request.Form["like_com"]; long postId = long.Parse(Request.Params["postId"]); string sortOrder = Request.Params["sortOrder"]; string pageNo = Request.Params["pageNo"]; Post post = db.Posts.Where(p => p.Id == postId).First(); string userId = User.Identity.GetUserId(); string like_com = Request.Params["like_com"]; if (like_com == "Like") { if (db.LikeActivities.Where(activity => activity.PostId == postId && activity.ApplicationUserId == userId).Count() == 0) { LikeActivity act = new LikeActivity(); act = new LikeActivity(); //act.Id = db.LikeActivities.Count() + 1; act.ApplicationUserId = userId; act.PostId = postId; act.Like = true; db.LikeActivities.Add(act); post.TotalLikes++; } else { LikeActivity likeAct = db.LikeActivities.Where(activity => activity.PostId == postId && activity.ApplicationUserId == userId).First(); if (!likeAct.Like) { post.TotalLikes++; } likeAct.Like = true; ViewBag.Like = "UnLike"; } db.SaveChanges(); } else if (like_com == "UnLike") { LikeActivity likeAct = db.LikeActivities.Where(activity => activity.PostId == postId && activity.ApplicationUserId == userId).First(); likeAct.Like = false; ViewBag.Like = "Like"; post.TotalLikes--; db.SaveChanges(); } else if (like_com == "Comment") { string comment = Request.Params["UserComment"]; if (!string.IsNullOrWhiteSpace(comment)) { CommentActivity act = new CommentActivity(); act.ApplicationUserId = userId; act.PostId = postId; act.Comment = comment; act.User = db.Users.Where(us => us.Id == User.Identity.GetUserId()).First(); db.CommentActivities.Add(act); post.TotalComments++; db.SaveChanges(); } } return(RedirectToAction("Index", "Post", new { sortOrder = "date", page = 1 })); }