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);
            }
        }
Пример #2
0
        //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);
            }
        }