private void StartApiService(string offset = "0", string typeRun = "Add")
 {
     if (!Methods.CheckConnectivity())
     {
         Toast.MakeText(Activity, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
     }
     else
     {
         PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
             LoadStory, () => MainRecyclerView.FetchNewsFeedApiPosts(offset, typeRun)
         });
     }
 }
예제 #2
0
 private void StartApiService(string offset = "0")
 {
     if (!Methods.CheckConnectivity())
     {
         Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
     }
     else
     {
         PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
             () => MainRecyclerView.FetchNewsFeedApiPosts(offset, "Add", Tag.Replace("#", ""))
         });
     }
 }
예제 #3
0
            public async void Run()
            {
                try
                {
                    await MainRecyclerView.FetchNewsFeedApiPosts("0", "Insert");

                    TabbedMainActivity.GetInstance()?.Get_Notifications();
                    await ApiRequest.Get_MyProfileData_Api(Activity).ConfigureAwait(false);

                    MainHandler.PostDelayed(new ApiPostUpdaterHelper(Activity, MainRecyclerView, MainHandler), 30000);
                    Console.WriteLine("Allen Post + started" + DateTime.Now);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("Allen Post + failed");
                }
            }
        //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);
            }
        }
예제 #5
0
        //Result
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            try
            {
                base.OnActivityResult(requestCode, resultCode, data);

                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));
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }