Пример #1
0
        public void Get_ManagePages()
        {
            try
            {
                if (PagesManage_Type == "Manage_UserPages")
                {
                    ManagePagesSection.Visibility     = ViewStates.Gone;
                    ManagePagesRecylerView.Visibility = ViewStates.Gone;
                    Txt_Create.Visibility             = ViewStates.Gone;
                    Btn_SearchRandom.Visibility       = ViewStates.Gone;
                }
                else if (PagesManage_Type == "Manage_MyPages")
                {
                    //Get Manage Pages From Database
                    var dbDatabase = new SqLiteDatabase();
                    var localList  = dbDatabase.GetAll_ManagePages();
                    if (localList != null)
                    {
                        ManagePagesAdapter.mAllUserPagesList =
                            new ObservableCollection <Get_User_Data_Object.Liked_Pages>(localList);
                        ManagePagesAdapter.BindEnd();
                    }

                    dbDatabase.Dispose();
                }


                Get_CommunitiesList_Page();
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
            }
        }
Пример #2
0
        // Get List Page Using API
        public async void Get_CommunitiesList_Page_API()
        {
            try
            {
                if (!IMethods.CheckConnectivity())
                {
                    swipeRefreshLayout.Refreshing = false;
                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)
                    .Show();
                }
                else
                {
                    Settings st = new Settings();
                    var(Api_status, Respond) = await Client.Global.Get_Community(st, UserID);

                    if (Api_status == 200)
                    {
                        if (Respond is Get_Community_Object result)
                        {
                            if (result.Groups.Count <= 0 && result.likedPages.Count <= 0 && result.Pages.Count <= 0)
                            {
                                swipeRefreshLayout.Refreshing = false;
                            }

                            var dbDatabase = new SqLiteDatabase();

                            //Add Data
                            //=======================================
                            if (PagesManage_Type == "Manage_UserPages")
                            {
                                // pages
                                if (result.Pages.Count > 0)
                                {
                                    PageAdapter.mPageList =
                                        new ObservableCollection <Get_Community_Object.Page>(result.Pages);
                                }


                                if (result.likedPages.Count > 0)
                                {
                                    var likedPagesList =
                                        new ObservableCollection <Get_Community_Object.LikedPages>(result.likedPages);
                                    var list = likedPagesList.Select(page => new Get_Community_Object.Page
                                    {
                                        PageId          = page.PageId,
                                        UserId          = page.UserId,
                                        PageName        = page.PageName,
                                        PageTitle       = page.PageTitle,
                                        PageDescription = page.PageDescription,
                                        Avatar          = page.Avatar,
                                        Cover           = page.Cover,
                                        PageCategory    = page.PageCategory,
                                        Website         = page.Website,
                                        Facebook        = page.Facebook,
                                        Google          = page.Google,
                                        Vk                    = page.Vk,
                                        Twitter               = page.Twitter,
                                        Linkedin              = page.Linkedin,
                                        Company               = page.Company,
                                        Phone                 = page.Phone,
                                        Address               = page.Address,
                                        CallActionType        = page.CallActionType,
                                        CallActionTypeUrl     = page.CallActionTypeUrl,
                                        BackgroundImage       = page.BackgroundImage,
                                        BackgroundImageStatus = page.BackgroundImageStatus,
                                        Instgram              = page.Instgram,
                                        Youtube               = page.Youtube,
                                        Verified              = page.Verified,
                                        Registered            = page.Registered,
                                        Boosted               = page.Boosted,
                                        About                 = page.About,
                                        Id                    = page.Id,
                                        Type                  = page.Type,
                                        Url                   = page.Url,
                                        Name                  = page.Name,
                                        //Rating = page.Rating,
                                        Category    = page.Category,
                                        IsPageOnwer = page.IsPageOnwer,
                                        Username    = page.Username
                                    }).ToList();

                                    //Bring new item
                                    var listnew = list?.Where(c =>
                                                              !PageAdapter.mPageList.Select(fc => fc.PageId).Contains(c.PageId)).ToList();
                                    if (listnew.Count > 0)
                                    {
                                        var lastCountItem = PageAdapter.ItemCount;
                                        //Results differ
                                        Classes.AddRange(PageAdapter.mPageList, listnew);
                                    }
                                }

                                PageAdapter.BindEnd();
                            }
                            else if (PagesManage_Type == "Manage_MyPages")
                            {
                                // likedPages
                                if (result.likedPages.Count > 0)
                                {
                                    var likedPagesList =
                                        new ObservableCollection <Get_Community_Object.LikedPages>(result.likedPages);

                                    //Update All Data To Database
                                    if (UserID == UserDetails.User_id)
                                    {
                                        var list = likedPagesList.Select(page => new Get_Community_Object.Page
                                        {
                                            PageId          = page.PageId,
                                            UserId          = page.UserId,
                                            PageName        = page.PageName,
                                            PageTitle       = page.PageTitle,
                                            PageDescription = page.PageDescription,
                                            Avatar          = page.Avatar,
                                            Cover           = page.Cover,
                                            PageCategory    = page.PageCategory,
                                            Website         = page.Website,
                                            Facebook        = page.Facebook,
                                            Google          = page.Google,
                                            Vk                    = page.Vk,
                                            Twitter               = page.Twitter,
                                            Linkedin              = page.Linkedin,
                                            Company               = page.Company,
                                            Phone                 = page.Phone,
                                            Address               = page.Address,
                                            CallActionType        = page.CallActionType,
                                            CallActionTypeUrl     = page.CallActionTypeUrl,
                                            BackgroundImage       = page.BackgroundImage,
                                            BackgroundImageStatus = page.BackgroundImageStatus,
                                            Instgram              = page.Instgram,
                                            Youtube               = page.Youtube,
                                            Verified              = page.Verified,
                                            Registered            = page.Registered,
                                            Boosted               = page.Boosted,
                                            About                 = page.About,
                                            Id                    = page.Id,
                                            Type                  = page.Type,
                                            Url                   = page.Url,
                                            Name                  = page.Name,
                                            //Rating = page.Rating,
                                            Category    = page.Category,
                                            IsPageOnwer = page.IsPageOnwer,
                                            Username    = page.Username
                                        }).ToList();

                                        // pages
                                        if (PageAdapter.mPageList.Count > 0)
                                        {
                                            //Bring new pages
                                            var listNew = list.Where(c =>
                                                                     !PageAdapter.mPageList.Select(fc => fc.PageId).Contains(c.PageId))
                                                          .ToList();
                                            if (listNew.Count > 0)
                                            {
                                                var chkList = listNew.Where(a => a.UserId != UserDetails.User_id)
                                                              .ToList();
                                                if (chkList.Count > 0)
                                                {
                                                    //Results differ
                                                    Classes.AddRange(PageAdapter.mPageList, chkList);
                                                    PageAdapter.BindEnd();

                                                    //Insert Or Replace Just New Data To Database
                                                    if (UserID == UserDetails.User_id)
                                                    {
                                                        dbDatabase.Insert_Or_Replace_PagesTable(
                                                            new ObservableCollection <Get_Community_Object.Page>(
                                                                chkList));
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            var chkList = list.Where(a => a.UserId != UserDetails.User_id).ToList();
                                            if (chkList.Count > 0)
                                            {
                                                PageAdapter.mPageList =
                                                    new ObservableCollection <Get_Community_Object.Page>(chkList);
                                                PageAdapter.BindEnd();

                                                //Insert Or Replace Data To Database
                                                if (UserID == UserDetails.User_id)
                                                {
                                                    dbDatabase.Insert_Or_Replace_PagesTable(PageAdapter.mPageList);
                                                }
                                            }
                                        }

                                        dbDatabase.Insert_Or_Replace_PagesTable(
                                            new ObservableCollection <Get_Community_Object.Page>(list));
                                    }
                                }

                                //====================================

                                if (result.Pages.Count > 0)
                                {
                                    // pages
                                    if (PageAdapter.mPageList.Count > 0)
                                    {
                                        //Bring new pages
                                        var listNew = result.Pages.Where(c =>
                                                                         !PageAdapter.mPageList.Select(fc => fc.PageId).Contains(c.PageId)).ToList();
                                        if (listNew.Count > 0)
                                        {
                                            var chkList = listNew.Where(a => a.UserId != UserDetails.User_id).ToList();
                                            if (chkList.Count > 0)
                                            {
                                                //Results differ
                                                Classes.AddRange(PageAdapter.mPageList, chkList);
                                                PageAdapter.BindEnd();

                                                //Insert Or Replace Just New Data To Database
                                                if (UserID == UserDetails.User_id)
                                                {
                                                    dbDatabase.Insert_Or_Replace_PagesTable(
                                                        new ObservableCollection <Get_Community_Object.Page>(chkList));
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var chkList = result.Pages?.Where(a => a.UserId != UserDetails.User_id)
                                                      .ToList();
                                        if (chkList.Count > 0)
                                        {
                                            PageAdapter.mPageList =
                                                new ObservableCollection <Get_Community_Object.Page>(chkList);
                                            PageAdapter.BindEnd();

                                            //Insert Or Replace Data To Database
                                            if (UserID == UserDetails.User_id)
                                            {
                                                dbDatabase.Insert_Or_Replace_PagesTable(PageAdapter.mPageList);
                                            }
                                        }
                                    }

                                    //Manage
                                    if (ManagePagesAdapter.mAllUserPagesList.Count > 0)
                                    {
                                        var chkListManage = result.Pages.Where(a => a.UserId == UserDetails.User_id)
                                                            .ToList();
                                        if (chkListManage.Count > 0)
                                        {
                                            //Bring new page
                                            var listNew = chkListManage.Where(c =>
                                                                              !ManagePagesAdapter.mAllUserPagesList.Select(fc => fc.page_id)
                                                                              .Contains(c.PageId)).ToList();
                                            if (listNew.Count > 0)
                                            {
                                                var list = listNew.Select(page => new Get_User_Data_Object.Liked_Pages
                                                {
                                                    page_id          = page.PageId,
                                                    user_id          = page.UserId,
                                                    page_name        = page.PageName,
                                                    page_title       = page.PageTitle,
                                                    page_description = page.PageDescription,
                                                    avatar           = page.Avatar,
                                                    cover            = page.Cover,
                                                    page_category    = page.PageCategory,
                                                    website          = page.Website,
                                                    facebook         = page.Facebook,
                                                    google           = page.Google,
                                                    vk                      = page.Vk,
                                                    twitter                 = page.Twitter,
                                                    linkedin                = page.Linkedin,
                                                    company                 = page.Company,
                                                    phone                   = page.Phone,
                                                    address                 = page.Address,
                                                    call_action_type        = page.CallActionType,
                                                    call_action_type_url    = page.CallActionTypeUrl,
                                                    background_image        = page.BackgroundImage,
                                                    background_image_status = page.BackgroundImageStatus,
                                                    instgram                = page.Instgram,
                                                    youtube                 = page.Youtube,
                                                    verified                = page.Verified,
                                                    registered              = page.Registered,
                                                    boosted                 = page.Boosted,
                                                    about                   = page.About,
                                                    id                      = page.Id,
                                                    type                    = page.Type,
                                                    url                     = page.Url,
                                                    name                    = page.Name,
                                                    //rating = page.Rating,
                                                    category      = page.Category,
                                                    is_page_onwer = page.IsPageOnwer,
                                                    username      = page.Username
                                                }).ToList();

                                                //Results differ
                                                Classes.AddRange(ManagePagesAdapter.mAllUserPagesList, list);
                                                ManagePagesAdapter.BindEnd();

                                                //Insert Or Replace Just New Data To Database
                                                if (UserID == UserDetails.User_id)
                                                {
                                                    dbDatabase.InsertOrReplace_ManagePagesTable(
                                                        new ObservableCollection <Get_User_Data_Object.Liked_Pages>(
                                                            list));
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var chkListManage = result.Pages.Where(a => a.UserId == UserDetails.User_id)
                                                            .ToList();
                                        if (chkListManage.Count > 0)
                                        {
                                            var list = chkListManage.Select(page => new Get_User_Data_Object.Liked_Pages
                                            {
                                                page_id          = page.PageId,
                                                user_id          = page.UserId,
                                                page_name        = page.PageName,
                                                page_title       = page.PageTitle,
                                                page_description = page.PageDescription,
                                                avatar           = page.Avatar,
                                                cover            = page.Cover,
                                                page_category    = page.PageCategory,
                                                website          = page.Website,
                                                facebook         = page.Facebook,
                                                google           = page.Google,
                                                vk                      = page.Vk,
                                                twitter                 = page.Twitter,
                                                linkedin                = page.Linkedin,
                                                company                 = page.Company,
                                                phone                   = page.Phone,
                                                address                 = page.Address,
                                                call_action_type        = page.CallActionType,
                                                call_action_type_url    = page.CallActionTypeUrl,
                                                background_image        = page.BackgroundImage,
                                                background_image_status = page.BackgroundImageStatus,
                                                instgram                = page.Instgram,
                                                youtube                 = page.Youtube,
                                                verified                = page.Verified,
                                                registered              = page.Registered,
                                                boosted                 = page.Boosted,
                                                about                   = page.About,
                                                id                      = page.Id,
                                                type                    = page.Type,
                                                url                     = page.Url,
                                                name                    = page.Name,
                                                //rating = page.Rating,
                                                category      = page.Category,
                                                is_page_onwer = page.IsPageOnwer,
                                                username      = page.Username
                                            }).ToList();

                                            ManagePagesAdapter.mAllUserPagesList =
                                                new ObservableCollection <Get_User_Data_Object.Liked_Pages>(list);
                                            ManagePagesAdapter.BindEnd();

                                            //Insert Or Replace Just New Data To Database
                                            if (UserID == UserDetails.User_id)
                                            {
                                                dbDatabase.InsertOrReplace_ManagePagesTable(
                                                    new ObservableCollection <Get_User_Data_Object.Liked_Pages>(list));
                                            }
                                        }
                                    }
                                }

                                //====================================

                                // groups
                                if (result.Groups.Count > 0)
                                {
                                    var groupsList =
                                        new ObservableCollection <Get_Community_Object.Group>(result.Groups);

                                    //Update All Data To Database
                                    if (UserID == UserDetails.User_id)
                                    {
                                        dbDatabase.Insert_Or_Replace_GroupsTable(groupsList);
                                    }
                                }
                            }

                            dbDatabase.Dispose();
                        }
                    }
                    else if (Api_status == 400)
                    {
                        if (Respond is Error_Object error)
                        {
                            var errorText = error._errors.Error_text;
                            //Toast.MakeText(this, errortext, ToastLength.Short).Show();

                            if (errorText.Contains("Invalid or expired access_token"))
                            {
                                API_Request.Logout(this);
                            }
                        }
                    }
                    else if (Api_status == 404)
                    {
                        var error = Respond.ToString();
                        //Toast.MakeText(this, error, ToastLength.Short).Show();
                    }
                }

                //Show Empty Page >>
                //===============================================================

                if (PagesManage_Type == "Manage_UserPages")
                {
                    if (PageAdapter.mPageList.Count > 0)
                    {
                        PagesSection.Visibility          = ViewStates.Visible;
                        LikedPagesRecylerView.Visibility = ViewStates.Visible;
                        Page_Empty.Visibility            = ViewStates.Gone;
                    }
                    else
                    {
                        PagesSection.Visibility          = ViewStates.Gone;
                        LikedPagesRecylerView.Visibility = ViewStates.Gone;
                        Page_Empty.Visibility            = ViewStates.Visible;
                    }
                }
                else if (PagesManage_Type == "Manage_MyPages")
                {
                    //if Manage_MyPages list count == 0 >> show empty page
                    if (ManagePagesAdapter.mAllUserPagesList.Count > 0)
                    {
                        Txt_Count_ManagePages.Text = ManagePagesAdapter.mAllUserPagesList.Count.ToString();

                        ManagePagesSection.Visibility     = ViewStates.Visible;
                        ManagePagesRecylerView.Visibility = ViewStates.Visible;
                    }
                    else
                    {
                        Txt_Count_ManagePages.Text = "0";

                        ManagePagesSection.Visibility     = ViewStates.Gone;
                        ManagePagesRecylerView.Visibility = ViewStates.Gone;
                    }

                    if (PageAdapter.mPageList.Count > 0)
                    {
                        PagesSection.Visibility          = ViewStates.Visible;
                        LikedPagesRecylerView.Visibility = ViewStates.Visible;
                        Page_Empty.Visibility            = ViewStates.Gone;
                    }
                    else
                    {
                        PagesSection.Visibility          = ViewStates.Gone;
                        LikedPagesRecylerView.Visibility = ViewStates.Gone;
                        Page_Empty.Visibility            = ViewStates.Visible;
                    }

                    if (PageAdapter.mPageList.Count == 0 && ManagePagesAdapter.mAllUserPagesList.Count == 0)
                    {
                        Page_Empty.Visibility = ViewStates.Visible;

                        ManagePagesSection.Visibility     = ViewStates.Gone;
                        ManagePagesRecylerView.Visibility = ViewStates.Gone;

                        PagesSection.Visibility          = ViewStates.Gone;
                        LikedPagesRecylerView.Visibility = ViewStates.Gone;
                    }
                    else
                    {
                        Page_Empty.Visibility = ViewStates.Gone;
                    }
                }

                swipeRefreshLayout.Refreshing = false;
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                Get_CommunitiesList_Page_API();
            }
        }