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);
            }
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
        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 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 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);
            }
        }
        //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);
            }
        }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
        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;
            }
        }
        //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);
            }
        }
Esempio n. 13
0
        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);
            }
        }