private void ResultApi(int apiStatus, dynamic respond) { try { if (apiStatus == 200) { if (respond is SharePostToObject result) { var combine = new FeedCombiner(result.Data, TabbedMainActivity.GetInstance()?.NewsFeedTab?.PostFeedAdapter.ListDiffer, this); combine.CombineDefaultPostSections("Top"); Toast.MakeText(this, GetText(Resource.String.Lbl_PostSuccessfullyShared), ToastLength.Short).Show(); if (UserDetails.SoundControl) { Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("PopNotificationPost.mp3"); } Finish(); } } else { Methods.DisplayReportResult(this, respond); } } catch (Exception e) { Console.WriteLine(e); } }
private async Task LoadPostDataAsync() { (int apiStatus, var respond) = await RequestsAsync.Global.Get_Post_Data(PostId, "post_data"); if (apiStatus == 200) { if (respond is GetPostDataObject result) { DataObject = result.PostData; if (DataObject != null) { DataObject.GetPostComments = new List <GetCommentObject>(); var combine = new FeedCombiner(DataObject, NativeFeedAdapter.ListDiffer, this); combine.CombineDefaultPostSections(); await LoadDataComment(); RunOnUiThread(() => { NativeFeedAdapter.NotifyDataSetChanged(); }); } } } else { Methods.DisplayReportResult(this, respond); } RunOnUiThread(ShowEmptyPage); }
private async Task LoadPostDataAsync() { if (Methods.CheckConnectivity()) { (int apiStatus, var respond) = await RequestsAsync.Global.Get_Post_Data(PostId, "post_data"); if (apiStatus == 200) { if (respond is GetPostDataObject result) { var data = result.PostData; if (data != null) { RunOnUiThread(() => { try { MainRecyclerView.CacheVideosFiles(Uri.Parse(data.PostFileFull)); var combine = new FeedCombiner(data, MAdapter.ListDiffer, this); combine.CombineDefaultPostSections(); MAdapter.NotifyDataSetChanged(); } catch (Exception e) { Console.WriteLine(e); } }); PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => LoadDataComment("0") }); } } } else { Methods.DisplayReportResult(this, respond); } SwipeRefreshLayout.Refreshing = false; RunOnUiThread(ShowEmptyPage); } else { SwipeRefreshLayout.Refreshing = false; Inflated = EmptyStateLayout.Inflate(); EmptyStateInflater x = new EmptyStateInflater(); x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection); if (!x.EmptyStateButton.HasOnClickListeners) { x.EmptyStateButton.Click += null; x.EmptyStateButton.Click += EmptyStateButtonOnClick; } Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } }
public void LoadMemoriesDataApi(int apiStatus, dynamic respond, List <AdapterModelsClass> diffList) { try { if (WRecyclerView.MainScrollEvent.IsLoading) { return; } WRecyclerView.MainScrollEvent.IsLoading = true; if (apiStatus != 200 || !(respond is FetchMemoriesObject result) || result.Data == null) { WRecyclerView.MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(ActivityContext, respond); } else { if (WRecyclerView.SwipeRefreshLayoutView != null && WRecyclerView.SwipeRefreshLayoutView.Refreshing) { WRecyclerView.SwipeRefreshLayoutView.Refreshing = false; } var countList = NativeFeedAdapter.ItemCount; if (result.Data.Posts.Count > 0) { result.Data.Posts.RemoveAll(a => a.Publisher == null && a.UserData == null); result.Data.Posts.Reverse(); foreach (var post in from post in result.Data.Posts let check = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a?.PostData?.PostId == post.PostId && a?.TypeView == PostFunctions.GetAdapterType(post)) where check == null select post) { if (post.Publisher == null && post.UserData == null) { continue; } var combine = new FeedCombiner(RegexFilterText(post), NativeFeedAdapter.ListDiffer, ActivityContext); combine.CombineDefaultPostSections(); } ActivityContext.RunOnUiThread(() => { NativeFeedAdapter.NotifyItemRangeInserted(countList, NativeFeedAdapter.ListDiffer.Count - countList); WRecyclerView.MainScrollEvent.IsLoading = false; }); } } WRecyclerView.MainScrollEvent.IsLoading = false; } catch (Exception e) { Methods.DisplayReportResultTrack(e); WRecyclerView.MainScrollEvent.IsLoading = false; } }
public void LoadTopDataApi(List <PostDataObject> list) { try { NativeFeedAdapter.ListDiffer.Clear(); NativeFeedAdapter.NotifyDataSetChanged(); var combiner = new FeedCombiner(null, NativeFeedAdapter.ListDiffer, ActivityContext); combiner.AddStoryPostView(); combiner.AddPostBoxPostView("feed", -1); if (list.Count > 0) { bool add = false; foreach (var post in from post in list let check = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a?.PostData?.PostId == post.PostId && a?.TypeView == PostFunctions.GetAdapterType(post)) where check == null select post) { add = true; var combine = new FeedCombiner(RegexFilterText(post), NativeFeedAdapter.ListDiffer, ActivityContext); if (post.PostType == "ad") { combine.AddAdsPost(); } else { combine.CombineDefaultPostSections(); } } if (PostCacheList?.Count > 0) { LoadBottomDataApi(PostCacheList.Take(30).ToList()); } if (add) { ActivityContext.RunOnUiThread(() => { try { NativeFeedAdapter.NotifyDataSetChanged(); NativeFeedAdapter.NewPostList.Clear(); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }); } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void SetRecyclerViewAdapters() { try { PostFeedAdapter = new NativePostAdapter(this, EventData.Id, MainRecyclerView, NativeFeedType.Event, SupportFragmentManager); MainRecyclerView.SetXAdapter(PostFeedAdapter, null); Combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, this); } catch (Exception e) { Console.WriteLine(e); } }
private void SetRecyclerViewAdapters() { try { PostFeedAdapter = new NativePostAdapter(this, EventData.Id, MainRecyclerView, NativeFeedType.Event, SupportFragmentManager); MainRecyclerView.SetXAdapter(PostFeedAdapter, null); Combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, this); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void SetRecyclerViewAdapters() { try { MainRecyclerView = FindViewById <WRecyclerView>(Resource.Id.newsfeedRecyler); PostFeedAdapter = new NativePostAdapter(this, GroupId, MainRecyclerView, NativeFeedType.Group, SupportFragmentManager); MainRecyclerView.SetXAdapter(PostFeedAdapter, null); Combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, this); } catch (Exception e) { Console.WriteLine(e); } }
//Refresh public void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e) { try { PopupBubbleView.Visibility = ViewStates.Gone; PostFeedAdapter.ListDiffer.Clear(); PostFeedAdapter.NotifyDataSetChanged(); PostFeedAdapter?.HolderStory?.StoryAdapter?.StoryList?.Clear(); PostFeedAdapter?.HolderStory?.StoryAdapter?.NotifyDataSetChanged(); MainRecyclerView?.StopVideo(); var combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, Activity); combiner.AddPostBoxPostView("feed", -1); switch (AppSettings.ShowStory) { case true: combiner.AddStoryPostView("feed", -1); break; } //combiner.AddPostBoxPostView("feed", -1); var checkSectionAlertBox = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); { PostFeedAdapter.ListDiffer.Remove(checkSectionAlertBox); } var checkSectionAlertJoinBox = PostFeedAdapter.ListDiffer.Where(a => a.TypeView == PostModelType.AlertJoinBox).ToList(); { foreach (var adapterModelsClass in checkSectionAlertJoinBox) { PostFeedAdapter.ListDiffer.Remove(adapterModelsClass); } } PostFeedAdapter.NotifyDataSetChanged(); StartApiService(); } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } }
private void LoadPost() { try { var combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, Activity); combiner.AddStoryPostView(); combiner.AddPostBoxPostView("feed", -1); combiner.AddGreetingAlertPostView(); if (PostFeedAdapter.ListDiffer.Count <= 5) { StartApiService(); } else { var item = PostFeedAdapter.ListDiffer.LastOrDefault(); var lastItem = PostFeedAdapter.ListDiffer.IndexOf(item); item = PostFeedAdapter.ListDiffer[lastItem]; string offset; if (item.TypeView == PostModelType.Divider || item.TypeView == PostModelType.ViewProgress || item.TypeView == PostModelType.AdMob1 || item.TypeView == PostModelType.AdMob2 || item.TypeView == PostModelType.FbAdNative || item.TypeView == PostModelType.AdsPost || item.TypeView == PostModelType.SuggestedGroupsBox || item.TypeView == PostModelType.SuggestedUsersBox || item.TypeView == PostModelType.CommentSection || item.TypeView == PostModelType.AddCommentSection) { item = PostFeedAdapter.ListDiffer.LastOrDefault(a => a.TypeView != PostModelType.Divider && a.TypeView != PostModelType.ViewProgress && a.TypeView != PostModelType.AdMob1 && a.TypeView != PostModelType.AdMob2 && a.TypeView != PostModelType.FbAdNative && a.TypeView != PostModelType.AdsPost && a.TypeView != PostModelType.SuggestedGroupsBox && a.TypeView != PostModelType.SuggestedUsersBox && a.TypeView != PostModelType.CommentSection && a.TypeView != PostModelType.AddCommentSection); offset = item?.PostData?.Id ?? "0"; Console.WriteLine(offset); } else { offset = item.PostData?.Id ?? "0"; } StartApiService(offset); } //Start Updating the news feed every few minus MainHandler.PostDelayed(new ApiPostUpdaterHelper(Activity, MainRecyclerView, MainHandler), 30000); } catch (Exception e) { Console.WriteLine(e); } }
private void LoadPost() { try { var combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, Activity); combiner.AddStoryPostView(); combiner.AddPostBoxPostView("feed", -1); combiner.AddGreetingAlertPostView(); if (PostFeedAdapter.ListDiffer.Count <= 5) { StartApiService(); } else { var item = PostFeedAdapter.ListDiffer.LastOrDefault(); var lastItem = PostFeedAdapter.ListDiffer.IndexOf(item); item = PostFeedAdapter.ListDiffer[lastItem]; string offset; if (item.TypeView == PostModelType.AdMob || item.TypeView == PostModelType.FbAdNative || item.TypeView == PostModelType.AdsPost || item.TypeView == PostModelType.SuggestedGroupsBox || item.TypeView == PostModelType.SuggestedUsersBox) { item = PostFeedAdapter.ListDiffer.LastOrDefault(a => a.PostData != null && a.TypeView != PostModelType.AdMob && a.TypeView != PostModelType.FbAdNative && a.TypeView != PostModelType.AdsPost && a.TypeView != PostModelType.SuggestedGroupsBox && a.TypeView != PostModelType.SuggestedUsersBox); offset = item?.PostData?.Id ?? "0"; Console.WriteLine(offset); } else { offset = item.PostData?.Id ?? "0"; } StartApiService(offset); } } catch (Exception e) { Console.WriteLine(e); } }
//Refresh private void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e) { try { PostFeedAdapter.ListDiffer.Clear(); MainRecyclerView?.StopVideo(); var combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, Activity); if (AppSettings.ShowStory) { combiner.AddStoryPostView(); } combiner.AddPostBoxPostView("feed", -1); var checkSectionAlertBox = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); { PostFeedAdapter.ListDiffer.Remove(checkSectionAlertBox); } var checkSectionAlertJoinBox = PostFeedAdapter.ListDiffer.Where(a => a.TypeView == PostModelType.AlertJoinBox).ToList(); { foreach (var adapterModelsClass in checkSectionAlertJoinBox) { PostFeedAdapter.ListDiffer.Remove(adapterModelsClass); } } PostFeedAdapter.NotifyDataSetChanged(); StartApiService(); } catch (Exception exception) { Console.WriteLine(exception); } }
private async Task LoadPostDataAsync() { var(apiStatus, respond) = await RequestsAsync.Posts.GetPostDataAsync(PostId, "post_data"); switch (apiStatus) { case 200: { switch (respond) { case GetPostDataObject result: { DataObject = result.PostData; if (DataObject != null) { DataObject.GetPostComments = new List <GetCommentObject>(); var combine = new FeedCombiner(DataObject, NativeFeedAdapter.ListDiffer, this); combine.CombineDefaultPostSections(); await LoadDataComment(); RunOnUiThread(() => { NativeFeedAdapter.NotifyDataSetChanged(); }); } break; } } break; } default: Methods.DisplayReportResult(this, respond); break; } RunOnUiThread(ShowEmptyPage); }
private void DestroyBasic() { try { BtnJoin = null; BtnMore = null; UserProfileImage = null; CoverImage = null; IconBack = null; IconPrivacy = null; CategoryText = null; IconEdit = null; TxtGroupName = null; TxtGroupUsername = null; PrivacyText = null; TxtEditGroupInfo = null; TxtMembers = null; InviteText = null; FloatingActionButtonView = null; EditAvatarImageGroup = null; MainRecyclerView = null; PostFeedAdapter = null; GroupId = null; ImageType = null; GroupDataClass = null; JoinRequestImage1 = null; JoinRequestImage2 = null; JoinRequestImage3 = null; LayoutJoinRequest = null; Combiner = null; } catch (Exception e) { Console.WriteLine(e); } }
public void LoadPost(bool local) { try { var combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, Activity); //combiner.AddStoryPostView(); combiner.AddPostBoxPostView("feed", -1); switch (AppSettings.ShowStory) { case true: combiner.AddStoryPostView("feed", -1); break; } switch (local) { case true: combiner.AddGreetingAlertPostView(); break; } SqLiteDatabase dbDatabase = new SqLiteDatabase(); var json = dbDatabase.GetDataPost(); switch (string.IsNullOrEmpty(json)) { case false when local: { var postObject = JsonConvert.DeserializeObject <PostObject>(json); switch (postObject?.Data.Count) { case > 0: MainRecyclerView.ApiPostAsync.LoadDataApi(postObject.Status, postObject, "0"); MainRecyclerView.ScrollToPosition(0); break; } //Start Updating the news feed every few minus StartApiService(); StartHandler(); return; } } switch (PostFeedAdapter.ListDiffer.Count) { case <= 5: StartApiService(); break; default: { var item = PostFeedAdapter.ListDiffer.LastOrDefault(); var lastItem = PostFeedAdapter.ListDiffer.IndexOf(item); item = PostFeedAdapter.ListDiffer[lastItem]; string offset; switch (item.TypeView) { case PostModelType.Divider: case PostModelType.ViewProgress: case PostModelType.AdMob1: case PostModelType.AdMob2: case PostModelType.AdMob3: case PostModelType.FbAdNative: case PostModelType.AdsPost: case PostModelType.SuggestedGroupsBox: case PostModelType.SuggestedUsersBox: case PostModelType.CommentSection: case PostModelType.AddCommentSection: item = PostFeedAdapter.ListDiffer.LastOrDefault(a => a.TypeView != PostModelType.Divider && a.TypeView != PostModelType.ViewProgress && a.TypeView != PostModelType.AdMob1 && a.TypeView != PostModelType.AdMob2 && a.TypeView != PostModelType.AdMob3 && a.TypeView != PostModelType.FbAdNative && a.TypeView != PostModelType.AdsPost && a.TypeView != PostModelType.SuggestedGroupsBox && a.TypeView != PostModelType.SuggestedUsersBox && a.TypeView != PostModelType.CommentSection && a.TypeView != PostModelType.AddCommentSection); offset = item?.PostData?.PostId ?? "0"; Console.WriteLine(offset); break; default: offset = item.PostData?.PostId ?? "0"; break; } StartApiService(offset, "Insert"); break; } } //Start Updating the news feed every few minus StartHandler(); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void GetDataPost() { try { switch (TypePost) { case "Group": { GroupData = JsonConvert.DeserializeObject <GroupClass>(Intent?.GetStringExtra("ShareToGroup") ?? ""); if (GroupData != null) { GlideImageLoader.LoadImage(this, GroupData.Avatar, PostSectionImage, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); TxtUserName.Text = GroupData.GroupName; } break; } case "Page": { PageData = JsonConvert.DeserializeObject <PageClass>(Intent?.GetStringExtra("ShareToPage") ?? ""); if (PageData != null) { GlideImageLoader.LoadImage(this, PageData.Avatar, PostSectionImage, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); TxtUserName.Text = PageData.PageName; } break; } case "MyTimeline": GlideImageLoader.LoadImage(this, UserDetails.Avatar, PostSectionImage, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); TxtUserName.Text = UserDetails.FullName; break; } PostData = JsonConvert.DeserializeObject <PostDataObject>(Intent?.GetStringExtra("PostObject") ?? ""); if (PostData != null) { switch (TypePost) { case "Group" when PostData.GroupRecipient == null: { if (GroupData != null) { PostData.GroupId = GroupData.GroupId; PostData.GroupRecipient = GroupData; } break; } case "Page" when PostData.Publisher == null: { if (PageData != null) { PostData.PageId = PageData.PageId; PostData.Publisher = new PublisherPost { Avatar = PageData.Avatar, About = PageData.About, Active = PageData.Active, Address = PageData.Address, BackgroundImage = PageData.BackgroundImage, Boosted = Convert.ToInt32(PageData.Boosted), CallActionType = Convert.ToInt32(PageData.CallActionType), Category = PageData.Category, Company = PageData.Company, Cover = PageData.Cover, Google = PageData.Google, Instgram = PageData.Instgram, IsPageOnwer = PageData.IsPageOnwer, Linkedin = PageData.Linkedin, Name = PageData.Name, PageCategory = Convert.ToInt32(PageData.PageCategory), PageDescription = PageData.PageDescription, PageId = Convert.ToInt32(PageData.PageId), PageName = PageData.PageName, PageTitle = PageData.PageTitle, Phone = PageData.Phone, Rating = Convert.ToInt32(PageData.Rating), Registered = PageData.Registered, Twitter = PageData.Twitter, Url = PageData.Url, }; } break; } } var combine = new FeedCombiner(PostData, PostFeedAdapter.ListDiffer, this); combine.CombineDefaultPostSections(); PostFeedAdapter.NotifyDataSetChanged(); } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private void ResultApi(int apiStatus, dynamic respond) { try { switch (apiStatus) { case 200: { switch (respond) { case SharePostToObject result: { AndHUD.Shared.Dismiss(this); //if (result.Data.SharedInfo.SharedInfoClass == null) //{ // result.Data.ParentId = PostData.PostId; // result.Data.SharedInfo = new SharedInfoUnion // { // SharedInfoClass = PostData // }; //} //var globalContextTabbed = TabbedMainActivity.GetInstance(); //var countList = globalContextTabbed.NewsFeedTab.PostFeedAdapter.ItemCount; //var combine = new FeedCombiner(result.Data, globalContextTabbed?.NewsFeedTab?.PostFeedAdapter?.ListDiffer, this); //combine.CombineDefaultPostSections("Top"); //int countIndex = 1; //var model1 = globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); //var model2 = globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); //var model3 = globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.FilterSection); //var model4 = globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); //var model5 = globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); //if (model5 != null) // countIndex += globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model5) + 1; //else if (model4 != null) // countIndex += globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model4) + 1; //else if (model3 != null) // countIndex += globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model3) + 1; //else if (model2 != null) // countIndex += globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model2) + 1; //else if (model1 != null) // countIndex += globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model1) + 1; //else // countIndex = 0; //var emptyStateChecker = globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.EmptyState); //if (emptyStateChecker != null && globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.Count > 1) // globalContextTabbed.NewsFeedTab.MainRecyclerView.RemoveByRowIndex(emptyStateChecker); //globalContextTabbed.NewsFeedTab.PostFeedAdapter.NotifyItemRangeInserted(countIndex, globalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.Count - countList); switch (TypePost) { case "MyTimeline": { MyProfileActivity myProfileActivity = MyProfileActivity.GetInstance(); if (myProfileActivity != null) { var countList1 = myProfileActivity.PostFeedAdapter.ItemCount; var combine1 = new FeedCombiner(result.Data, myProfileActivity.PostFeedAdapter.ListDiffer, this); var check1 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.PostData != null && a.TypeView != PostModelType.AddPostBox && a.TypeView != PostModelType.FilterSection && a.TypeView != PostModelType.SearchForPosts); if (check1 != null) { combine1.CombineDefaultPostSections("Top"); } else { combine1.CombineDefaultPostSections(); } int countIndex1 = 1; var model11 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); var model21 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); var model31 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.FilterSection); var model41 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); var model51 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); if (model51 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model51) + 1; } else if (model41 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model41) + 1; } else if (model31 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model31) + 1; } else if (model21 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model21) + 1; } else if (model11 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model11) + 1; } else { countIndex1 = 0; } var emptyStateChecker1 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.EmptyState); if (emptyStateChecker1 != null && myProfileActivity.PostFeedAdapter.ListDiffer.Count > 1) { myProfileActivity.MainRecyclerView.RemoveByRowIndex(emptyStateChecker1); } myProfileActivity.PostFeedAdapter.NotifyItemRangeInserted(countIndex1, myProfileActivity.PostFeedAdapter.ListDiffer.Count - countList1); } break; } } Toast.MakeText(this, GetText(Resource.String.Lbl_PostSuccessfullyShared), ToastLength.Short)?.Show(); switch (UserDetails.SoundControl) { case true: Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("PopNotificationPost.mp3"); break; } Finish(); break; } } break; } default: Methods.DisplayAndHudErrorResult(this, respond); break; } } catch (Exception e) { AndHUD.Shared.Dismiss(this); Methods.DisplayReportResultTrack(e); } }
private async void AddPost() { try { var(apiStatus, respond) = await ApiRequest.AddNewPost_Async(DataPost.IdPost, DataPost.PagePost, DataPost.Content, DataPost.PostPrivacy, DataPost.PostFeelingType, DataPost.PostFeelingText, DataPost.PlaceText, DataPost.AttachmentList, DataPost.AnswersList, DataPost.IdColor, DataPost.AlbumName); if (apiStatus == 200) { if (respond is AddPostObject postObject) { Toast.MakeText(GlobalContextPost, GlobalContextPost.GetText(Resource.String.Lbl_Post_Added), ToastLength.Short).Show(); // put the String to pass back into an Intent and close this activity var resultIntent = new Intent(); if (postObject.PostData != null) { var countList = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ItemCount; var combine = new FeedCombiner(postObject.PostData, GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer, this); combine.CombineDefaultPostSections("Top"); int countIndex = 1; var model1 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); var model2 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); var model3 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); var model4 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); if (model4 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model4) + 1; } else if (model3 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model3) + 1; } else if (model2 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model2) + 1; } else if (model1 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model1) + 1; } else { countIndex = 0; } GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.NotifyItemRangeInserted(countIndex, GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.Count - countList); resultIntent.PutExtra("itemObject", JsonConvert.SerializeObject(postObject.PostData)); } GlobalContextPost.SetResult(Result.Ok, resultIntent); if (UserDetails.SoundControl) { Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("PopNotificationPost.mp3"); } } } else { Methods.DisplayReportResult(GlobalContextPost, respond); } RemoveNotification(); } catch (Exception e) { RemoveNotification(); Console.WriteLine(e); } }
//Result protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); //If its from Camera or Gallery if (requestCode == CropImage.CropImageActivityRequestCode) { var result = CropImage.GetActivityResult(data); if (resultCode == Result.Ok) { if (result.IsSuccessful) { var resultUri = result.Uri; if (!string.IsNullOrEmpty(resultUri.Path)) { string pathImg; if (ImageType == "Cover") { pathImg = resultUri.Path; UpdateImageGroup_Api(ImageType, pathImg); } else if (ImageType == "Avatar") { pathImg = resultUri.Path; UpdateImageGroup_Api(ImageType, pathImg); } } else { Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show(); } } } } else if (requestCode == 2500 && resultCode == Result.Ok)//add post { if (!string.IsNullOrEmpty(data.GetStringExtra("itemObject"))) { var postData = JsonConvert.DeserializeObject <PostDataObject>(data.GetStringExtra("itemObject")); if (postData != null) { var countList = PostFeedAdapter.ItemCount; var combine = new FeedCombiner(postData, PostFeedAdapter.ListDiffer, this); combine.CombineDefaultPostSections("Top"); int countIndex = 1; var model1 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); var model2 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); var model3 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); var model4 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); if (model4 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model4) + 1; } else if (model3 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model3) + 1; } else if (model2 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model2) + 1; } else if (model1 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model1) + 1; } else { countIndex = 0; } PostFeedAdapter.NotifyItemRangeInserted(countIndex, PostFeedAdapter.ListDiffer.Count - countList); } } else { PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => MainRecyclerView.FetchNewsFeedApiPosts() }); } } else if (requestCode == 3950 && resultCode == Result.Ok) //Edit post { var postId = data.GetStringExtra("PostId") ?? ""; var postText = data.GetStringExtra("PostText") ?? ""; var diff = PostFeedAdapter.ListDiffer; List <AdapterModelsClass> dataGlobal = diff.Where(a => a.PostData?.Id == postId).ToList(); if (dataGlobal.Count > 0) { foreach (var postData in dataGlobal) { postData.PostData.Orginaltext = postText; var index = diff.IndexOf(postData); if (index > -1) { PostFeedAdapter.NotifyItemChanged(index); } } var checkTextSection = dataGlobal.FirstOrDefault(w => w.TypeView == PostModelType.TextSectionPostPart); if (checkTextSection == null) { var collection = dataGlobal.FirstOrDefault()?.PostData; var item = new AdapterModelsClass { TypeView = PostModelType.TextSectionPostPart, Id = int.Parse((int)PostModelType.TextSectionPostPart + collection?.Id), PostData = collection, IsDefaultFeedPost = true }; var headerPostIndex = diff.IndexOf(dataGlobal.FirstOrDefault(w => w.TypeView == PostModelType.HeaderPost)); if (headerPostIndex > -1) { diff.Insert(headerPostIndex + 1, item); PostFeedAdapter.NotifyItemInserted(headerPostIndex + 1); } } } } else if (requestCode == 3500 && resultCode == Result.Ok) //Edit post product { if (string.IsNullOrEmpty(data.GetStringExtra("itemData"))) { return; } var item = JsonConvert.DeserializeObject <ProductDataObject>(data.GetStringExtra("itemData")); if (item != null) { var diff = PostFeedAdapter.ListDiffer; var dataGlobal = diff.Where(a => a.PostData?.Id == item.PostId).ToList(); if (dataGlobal.Count > 0) { foreach (var postData in dataGlobal) { var index = diff.IndexOf(postData); if (index > -1) { var productUnion = postData.PostData.Product?.ProductClass; if (productUnion != null) { productUnion.Id = item.Id; } productUnion = item; Console.WriteLine(productUnion); PostFeedAdapter.NotifyItemChanged(PostFeedAdapter.ListDiffer.IndexOf(postData)); } } } } } else if (requestCode == 2005 && resultCode == Result.Ok) { string result = data.GetStringExtra("groupItem"); var item = JsonConvert.DeserializeObject <GroupClass>(result); if (item != null) { LoadPassedData(item); } } else if (requestCode == 2019 && resultCode == Result.Ok) { var manged = GroupsActivity.GetInstance().MAdapter.SocialList.FirstOrDefault(a => a.TypeView == SocialModelType.MangedGroups); var dataListGroup = manged?.MangedGroupsModel.GroupsList?.FirstOrDefault(a => a.GroupId == GroupId); if (dataListGroup != null) { manged.MangedGroupsModel.GroupsList.Remove(dataListGroup); GroupsActivity.GetInstance().MAdapter.NotifyDataSetChanged(); ListUtils.MyGroupList.Remove(dataListGroup); } Finish(); } } catch (Exception e) { Console.WriteLine(e); } }
//Save private async void TxtAddOnClick(object sender, EventArgs e) { try { if (!Methods.CheckConnectivity()) { Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show(); } else { if (string.IsNullOrEmpty(TxtName.Text) || string.IsNullOrWhiteSpace(TxtName.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_name), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtTitle.Text) || string.IsNullOrWhiteSpace(TxtTitle.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_title), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtDescription.Text) || string.IsNullOrWhiteSpace(TxtDescription.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_Description), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtStartDate.Text) || string.IsNullOrWhiteSpace(TxtStartDate.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_start_date), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtEndDate.Text) || string.IsNullOrWhiteSpace(TxtEndDate.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_end_date), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtWebsite.Text) || string.IsNullOrWhiteSpace(TxtWebsite.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_enter_Website), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtMyPages.Text) || string.IsNullOrWhiteSpace(TxtMyPages.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_page), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtLocation.Text) || string.IsNullOrWhiteSpace(TxtLocation.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Location), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtAudience.Text) || string.IsNullOrWhiteSpace(TxtAudience.Text) || string.IsNullOrEmpty(TotalIdAudienceChecked)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Audience), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtGender.Text) || string.IsNullOrWhiteSpace(TxtGender.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Gender), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtPlacement.Text) || string.IsNullOrWhiteSpace(TxtPlacement.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Placement), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtBudget.Text) || string.IsNullOrWhiteSpace(TxtBudget.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Budget), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(TxtBidding.Text) || string.IsNullOrWhiteSpace(TxtBidding.Text)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Bidding), ToastLength.Short)?.Show(); return; } if (string.IsNullOrEmpty(PathImage)) { Toast.MakeText(this, GetText(Resource.String.Lbl_Please_select_Image), ToastLength.Short)?.Show(); return; } //Show a progress AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading)); if (TotalIdAudienceChecked.Length > 0) { TotalIdAudienceChecked = TotalIdAudienceChecked.Remove(TotalIdAudienceChecked.Length - 1, 1); } var dictionary = new Dictionary <string, string> { { "name", TxtName.Text }, { "website", TxtWebsite.Text }, { "headline", TxtTitle.Text }, { "description", TxtDescription.Text }, { "bidding", BiddingStatus }, { "appears", PlacementStatus }, { "audience-list", TotalIdAudienceChecked }, { "gender", GenderStatus }, { "location", TxtLocation.Text }, { "start", TxtStartDate.Text }, { "end", TxtEndDate.Text }, }; var(apiStatus, respond) = await RequestsAsync.Advertise.CreateAdvertise(dictionary, PathImage); if (apiStatus == 200) { if (respond is CreateAdvertiseObject result) { AndHUD.Shared.ShowSuccess(this); //Add new item to list if (result.Data?.PostClass != null) { result.Data.Value.PostClass.PostType = "ad"; var countList = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ItemCount; var combine = new FeedCombiner(ApiPostAsync.RegexFilterText(result.Data.Value.PostClass), GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer, this); combine.AddAdsPost(); int countIndex = 1; var model1 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); var model2 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); var model3 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.FilterSection); var model4 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); var model5 = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); if (model5 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model5) + 1; } else if (model4 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model4) + 1; } else if (model3 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model3) + 1; } else if (model2 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model2) + 1; } else if (model1 != null) { countIndex += GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.IndexOf(model1) + 1; } else { countIndex = 0; } var emptyStateChecker = GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.EmptyState); if (emptyStateChecker != null && GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.Count > 1) { GlobalContextTabbed.NewsFeedTab.MainRecyclerView.RemoveByRowIndex(emptyStateChecker); } GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.NotifyItemRangeInserted(countIndex, GlobalContextTabbed.NewsFeedTab.PostFeedAdapter.ListDiffer.Count - countList); // My Profile MyProfileActivity myProfileActivity = MyProfileActivity.GetInstance(); if (myProfileActivity != null) { var countList1 = myProfileActivity.PostFeedAdapter.ItemCount; var combine1 = new FeedCombiner(ApiPostAsync.RegexFilterText(result.Data.Value.PostClass), myProfileActivity.PostFeedAdapter.ListDiffer, this); combine1.AddAdsPost(); int countIndex1 = 1; var model11 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); var model21 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); var model31 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.FilterSection); var model41 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); var model51 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); if (model51 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model51) + 1; } else if (model41 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model41) + 1; } else if (model31 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model31) + 1; } else if (model21 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model21) + 1; } else if (model11 != null) { countIndex1 += myProfileActivity.PostFeedAdapter.ListDiffer.IndexOf(model11) + 1; } else { countIndex1 = 0; } var emptyStateChecker1 = myProfileActivity.PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.EmptyState); if (emptyStateChecker1 != null && myProfileActivity.PostFeedAdapter.ListDiffer.Count > 1) { myProfileActivity.MainRecyclerView.RemoveByRowIndex(emptyStateChecker1); } myProfileActivity.PostFeedAdapter.NotifyItemRangeInserted(countIndex1, myProfileActivity.PostFeedAdapter.ListDiffer.Count - countList1); } } Finish(); } } else { Methods.DisplayAndHudErrorResult(this, respond); } } } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); AndHUD.Shared.Dismiss(this); } }
public bool LoadBottomDataApi(List <PostDataObject> list) { try { var countList = NativeFeedAdapter.ItemCount; if (list?.Count > 0) { bool add = false; foreach (var post in from post in list let check = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a?.PostData?.PostId == post.PostId && a?.TypeView == PostFunctions.GetAdapterType(post)) where check == null select post) { add = true; var combiner = new FeedCombiner(null, NativeFeedAdapter.ListDiffer, ActivityContext); if (NativeFeedAdapter.NativePostType == NativeFeedType.Global) { var check1 = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SuggestedGroupsBox); if (check1 == null && AppSettings.ShowSuggestedGroup && NativeFeedAdapter.ListDiffer.Count > 0 && NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowSuggestedGroupCount == 0 && ListUtils.SuggestedGroupList.Count > 0) { combiner.AddSuggestedBoxPostView(PostModelType.SuggestedGroupsBox); } var check2 = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SuggestedUsersBox); if (check2 == null && AppSettings.ShowSuggestedUser && NativeFeedAdapter.ListDiffer.Count > 0 && NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowSuggestedUserCount == 0 && ListUtils.SuggestedUserList.Count > 0) { combiner.AddSuggestedBoxPostView(PostModelType.SuggestedUsersBox); } } if (NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowAdMobNativeCount == 0 && NativeFeedAdapter.ListDiffer.Count > 0 && AppSettings.ShowAdMobNativePost) { switch (LastAdsType) { case PostModelType.AdMob1: LastAdsType = PostModelType.AdMob2; combiner.AddAdsPostView(PostModelType.AdMob1); break; case PostModelType.AdMob2: LastAdsType = PostModelType.AdMob3; combiner.AddAdsPostView(PostModelType.AdMob2); break; case PostModelType.AdMob3: LastAdsType = PostModelType.AdMob1; combiner.AddAdsPostView(PostModelType.AdMob3); break; } } var combine = new FeedCombiner(RegexFilterText(post), NativeFeedAdapter.ListDiffer, ActivityContext); if (post.PostType == "ad") { combine.AddAdsPost(); } else { bool isPromoted = post.IsPostBoosted == "1" || post.SharedInfo.SharedInfoClass != null && post.SharedInfo.SharedInfoClass?.IsPostBoosted == "1"; if (isPromoted) //Promoted { combine.CombineDefaultPostSections("Top"); } else { combine.CombineDefaultPostSections(); } } if (NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowFbNativeAdsCount == 0 && NativeFeedAdapter.ListDiffer.Count > 0 && AppSettings.ShowFbNativeAds) { combiner.AddAdsPostView(PostModelType.FbAdNative); } } if (add) { ActivityContext.RunOnUiThread(() => { try { NativeFeedAdapter.NotifyItemRangeInserted(countList, NativeFeedAdapter.ListDiffer.Count - countList); GC.Collect(); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }); } PostCacheList.RemoveRange(0, list.Count - 1); ActivityContext.RunOnUiThread(ShowEmptyPage); return(add); } return(false); } catch (Exception e) { Methods.DisplayReportResultTrack(e); return(false); } }
public void LoadPost(bool local) { try { var combiner = new FeedCombiner(null, PostFeedAdapter.ListDiffer, Activity); combiner.AddStoryPostView(); combiner.AddPostBoxPostView("feed", -1); if (local) { combiner.AddGreetingAlertPostView(); } SqLiteDatabase dbDatabase = new SqLiteDatabase(); var json = dbDatabase.GetDataPost(); if (!string.IsNullOrEmpty(json) && local) { var postObject = JsonConvert.DeserializeObject <PostObject>(json); if (postObject?.Data.Count > 0) { MainRecyclerView.LoadDataApi(postObject.Status, postObject, "0"); StartApiService("0", "Insert"); } dbDatabase.Dispose(); //Start Updating the news feed every few minus StartHandler(); return; } else { if (PostFeedAdapter.ListDiffer.Count <= 5) { StartApiService(); } else { var item = PostFeedAdapter.ListDiffer.LastOrDefault(); var lastItem = PostFeedAdapter.ListDiffer.IndexOf(item); item = PostFeedAdapter.ListDiffer[lastItem]; string offset; if (item.TypeView == PostModelType.Divider || item.TypeView == PostModelType.ViewProgress || item.TypeView == PostModelType.AdMob1 || item.TypeView == PostModelType.AdMob2 || item.TypeView == PostModelType.FbAdNative || item.TypeView == PostModelType.AdsPost || item.TypeView == PostModelType.SuggestedGroupsBox || item.TypeView == PostModelType.SuggestedUsersBox || item.TypeView == PostModelType.CommentSection || item.TypeView == PostModelType.AddCommentSection) { item = PostFeedAdapter.ListDiffer.LastOrDefault(a => a.TypeView != PostModelType.Divider && a.TypeView != PostModelType.ViewProgress && a.TypeView != PostModelType.AdMob1 && a.TypeView != PostModelType.AdMob2 && a.TypeView != PostModelType.FbAdNative && a.TypeView != PostModelType.AdsPost && a.TypeView != PostModelType.SuggestedGroupsBox && a.TypeView != PostModelType.SuggestedUsersBox && a.TypeView != PostModelType.CommentSection && a.TypeView != PostModelType.AddCommentSection); offset = item?.PostData?.Id ?? "0"; Console.WriteLine(offset); } else { offset = item.PostData?.Id ?? "0"; } StartApiService(offset, "Insert"); } } //Start Updating the news feed every few minus StartHandler(); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
//Result public override void OnActivityResult(int requestCode, int resultCode, Intent data) { try { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 2500 && resultCode == (int)Result.Ok) //add post { if (!string.IsNullOrEmpty(data.GetStringExtra("itemObject"))) { var postData = JsonConvert.DeserializeObject <PostDataObject>(data.GetStringExtra("itemObject") ?? ""); if (postData != null) { var countList = PostFeedAdapter.ItemCount; var combine = new FeedCombiner(postData, PostFeedAdapter.ListDiffer, Context); combine.CombineDefaultPostSections("Top"); int countIndex = 1; var model1 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.Story); var model2 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AddPostBox); var model3 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.AlertBox); var model4 = PostFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SearchForPosts); if (model4 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model4) + 1; } else if (model3 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model3) + 1; } else if (model2 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model2) + 1; } else if (model1 != null) { countIndex += PostFeedAdapter.ListDiffer.IndexOf(model1) + 1; } else { countIndex = 0; } PostFeedAdapter.NotifyItemRangeInserted(countIndex, PostFeedAdapter.ListDiffer.Count - countList); } } else { PollyController.RunRetryPolicyFunction(new List <Func <Task> > { () => MainRecyclerView.FetchNewsFeedApiPosts() }); } } else if (requestCode == 3950 && resultCode == (int)Result.Ok) //Edit post { var postId = data.GetStringExtra("PostId") ?? ""; var postText = data.GetStringExtra("PostText") ?? ""; var diff = PostFeedAdapter.ListDiffer; List <AdapterModelsClass> dataGlobal = diff.Where(a => a.PostData?.Id == postId).ToList(); if (dataGlobal.Count > 0) { foreach (var postData in dataGlobal) { postData.PostData.Orginaltext = postText; var index = diff.IndexOf(postData); if (index > -1) { PostFeedAdapter.NotifyItemChanged(index); } } var checkTextSection = dataGlobal.FirstOrDefault(w => w.TypeView == PostModelType.TextSectionPostPart); if (checkTextSection == null) { var collection = dataGlobal.FirstOrDefault()?.PostData; var item = new AdapterModelsClass { TypeView = PostModelType.TextSectionPostPart, Id = Convert.ToInt32((int)PostModelType.TextSectionPostPart + collection?.Id), PostData = collection, IsDefaultFeedPost = true }; var headerPostIndex = diff.IndexOf(dataGlobal.FirstOrDefault(w => w.TypeView == PostModelType.HeaderPost)); if (headerPostIndex > -1) { diff.Insert(headerPostIndex + 1, item); PostFeedAdapter.NotifyItemInserted(headerPostIndex + 1); } } } } else if (requestCode == 3500 && resultCode == (int)Result.Ok) //Edit post product { if (string.IsNullOrEmpty(data.GetStringExtra("itemData"))) { return; } var item = JsonConvert.DeserializeObject <ProductDataObject>(data.GetStringExtra("itemData") ?? ""); if (item != null) { var diff = PostFeedAdapter.ListDiffer; var dataGlobal = diff.Where(a => a.PostData?.Id == item.PostId).ToList(); if (dataGlobal.Count > 0) { foreach (var postData in dataGlobal) { var index = diff.IndexOf(postData); if (index > -1) { var productUnion = postData.PostData.Product?.ProductClass; if (productUnion != null) { productUnion.Id = item.Id; } productUnion = item; Console.WriteLine(productUnion); PostFeedAdapter.NotifyItemChanged(PostFeedAdapter.ListDiffer.IndexOf(postData)); } } } } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public void LoadDataApi(int apiStatus, dynamic respond, string offset, string typeRun = "Add") { try { if (apiStatus != 200 || !(respond is PostObject result) || result.Data == null) { WRecyclerView.MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(ActivityContext, respond); } else { if (WRecyclerView.SwipeRefreshLayoutView != null && WRecyclerView.SwipeRefreshLayoutView.Refreshing) { WRecyclerView.SwipeRefreshLayoutView.Refreshing = false; } var countList = NativeFeedAdapter.ItemCount; if (result.Data.Count > 0) { result.Data.RemoveAll(a => a.Publisher == null && a.UserData == null); if (offset == "0" && countList > 10 && typeRun == "Insert" && NativeFeedAdapter.NativePostType == NativeFeedType.Global) { result.Data.Reverse(); bool add = false; foreach (var post in from post in result.Data let check = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a?.PostData?.PostId == post.PostId && a.TypeView == PostFunctions.GetAdapterType(post)) where check == null select post) { add = true; NativeFeedAdapter.NewPostList.Add(post); } ActivityContext.RunOnUiThread(() => { try { if (add && WRecyclerView.PopupBubbleView != null && WRecyclerView.PopupBubbleView.Visibility != ViewStates.Visible && AppSettings.ShowNewPostOnNewsFeed) { WRecyclerView.PopupBubbleView.Visibility = ViewStates.Visible; } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }); } else { bool add = false; foreach (var post in from post in result.Data let check = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a?.PostData?.PostId == post.PostId && a?.TypeView == PostFunctions.GetAdapterType(post)) where check == null select post) { add = true; var combiner = new FeedCombiner(null, NativeFeedAdapter.ListDiffer, ActivityContext); if (NativeFeedAdapter.NativePostType == NativeFeedType.Global) { if (result.Data.Count < 6 && NativeFeedAdapter.ListDiffer.Count < 6) { if (!ShowFindMoreAlert) { ShowFindMoreAlert = true; combiner.AddFindMoreAlertPostView("Pages"); combiner.AddFindMoreAlertPostView("Groups"); } } var check1 = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SuggestedGroupsBox); if (check1 == null && AppSettings.ShowSuggestedGroup && NativeFeedAdapter.ListDiffer.Count > 0 && NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowSuggestedGroupCount == 0 && ListUtils.SuggestedGroupList.Count > 0) { combiner.AddSuggestedBoxPostView(PostModelType.SuggestedGroupsBox); } var check2 = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SuggestedUsersBox); if (check2 == null && AppSettings.ShowSuggestedUser && NativeFeedAdapter.ListDiffer.Count > 0 && NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowSuggestedUserCount == 0 && ListUtils.SuggestedUserList.Count > 0) { combiner.AddSuggestedBoxPostView(PostModelType.SuggestedUsersBox); } } if (NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowAdMobNativeCount == 0 && NativeFeedAdapter.ListDiffer.Count > 0 && AppSettings.ShowAdMobNativePost) { switch (LastAdsType) { case PostModelType.AdMob1: LastAdsType = PostModelType.AdMob2; combiner.AddAdsPostView(PostModelType.AdMob1); break; case PostModelType.AdMob2: LastAdsType = PostModelType.AdMob3; combiner.AddAdsPostView(PostModelType.AdMob2); break; case PostModelType.AdMob3: LastAdsType = PostModelType.AdMob1; combiner.AddAdsPostView(PostModelType.AdMob3); break; } } var combine = new FeedCombiner(RegexFilterText(post), NativeFeedAdapter.ListDiffer, ActivityContext); if (post.PostType == "ad") { combine.AddAdsPost(); } else { bool isPromoted = post.IsPostBoosted == "1" || post.SharedInfo.SharedInfoClass != null && post.SharedInfo.SharedInfoClass?.IsPostBoosted == "1"; if (isPromoted) //Promoted { combine.CombineDefaultPostSections("Top"); } else { combine.CombineDefaultPostSections(); } } if (NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowFbNativeAdsCount == 0 && NativeFeedAdapter.ListDiffer.Count > 0 && AppSettings.ShowFbNativeAds) { combiner.AddAdsPostView(PostModelType.FbAdNative); } } if (add) { ActivityContext.RunOnUiThread(() => { try { NativeFeedAdapter.NotifyItemRangeInserted(countList, NativeFeedAdapter.ListDiffer.Count - countList); WRecyclerView.MainScrollEvent.IsLoading = false; GC.Collect(); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }); } //else //{ // Toast.MakeText(ActivityContext, ActivityContext.GetText(Resource.String.Lbl_NoMorePost), ToastLength.Short)?.Show(); //} } } ActivityContext.RunOnUiThread(ShowEmptyPage); if (NativeFeedAdapter.NativePostType == NativeFeedType.Global) { WRecyclerView.DataPostJson = JsonConvert.SerializeObject(result); } } WRecyclerView.MainScrollEvent.IsLoading = false; } catch (Exception e) { Methods.DisplayReportResultTrack(e); WRecyclerView.MainScrollEvent.IsLoading = false; } }