예제 #1
0
        private async Task LoadHotOrNotAsync(string offset = "0")
        {
            if (Methods.CheckConnectivity())
            {
                //int countList = MAdapter.TrendingList.Count;
                var(apiStatus, respond) = await RequestsAsync.Users.HotOrNotAsync(UserDetails.Gender, "20", offset);

                if (apiStatus != 200 || !(respond is ListUsersObject result) || result.Data == null)
                {
                    if (MainScrollEvent != null)
                    {
                        MainScrollEvent.IsLoading = false;
                    }
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.Data.Count;
                    if (respondList > 0)
                    {
                        var checkList = MAdapter.TrendingList.FirstOrDefault(q => q.Type == ItemType.HotOrNot);
                        if (checkList == null)
                        {
                            var hotOrNot = new Classes.TrendingClass()
                            {
                                Id           = 200,
                                HotOrNotList = new List <UserInfoObject>(),
                                Type         = ItemType.HotOrNot
                            };

                            foreach (var item in from item in result.Data let check = hotOrNot.HotOrNotList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                            {
                                hotOrNot.HotOrNotList.Add(item);
                            }

                            MAdapter.TrendingList.Insert(1, hotOrNot);
                            Activity.RunOnUiThread(() => { MAdapter.NotifyItemInserted(1); });
                        }
                        else
                        {
                            foreach (var item in from item in result.Data let check = checkList.HotOrNotList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                            {
                                checkList.HotOrNotList.Add(item);
                            }
                        }
                    }
                }
            }
            else
            {
                Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
            }
        }
        //private void StartApiServiceWeather()
        //{
        //    if (!Methods.CheckConnectivity())
        //        Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
        //    else
        //        PollyController.RunRetryPolicyFunction(new List<Func<Task>> {async () => await GetWeatherApi(), async () => await GetExchangeCurrencyApi() });
        //}

        private async Task GetWeatherApi()
        {
            switch (AppSettings.ShowWeather)
            {
            case true when Methods.CheckConnectivity():
            {
                GetWeatherObject respond = await ApiRequest.GetWeather();

                if (respond != null)
                {
                    var checkList = GlobalContext.TrendingTab.MAdapter.TrendingList.FirstOrDefault(q => q.Type == Classes.ItemType.Weather);
                    switch (checkList)
                    {
                    case null:
                    {
                        var weather = new Classes.TrendingClass
                        {
                            Id      = 600,
                            Weather = respond,
                            Type    = Classes.ItemType.Weather
                        };

                        GlobalContext.TrendingTab.MAdapter.TrendingList.Add(weather);
                        GlobalContext.TrendingTab.MAdapter.TrendingList.Add(new Classes.TrendingClass
                                {
                                    Type = Classes.ItemType.Divider
                                });
                        break;
                    }

                    default:
                        checkList.Weather = respond;
                        break;
                    }
                }

                Activity?.RunOnUiThread(() => MAdapter.NotifyDataSetChanged());
                break;
            }
            }
        }
예제 #3
0
        //Get General Data Using Api >> notifications , pro_users , promoted_pages , trending_hashTag
        public async Task <(string, string, string, string)> LoadGeneralData(bool seenNotifications, string offset = "")
        {
            try
            {
                switch (MainScrollEvent.IsLoading)
                {
                case true:
                    return("", "", "", "");
                }

                if (Methods.CheckConnectivity())
                {
                    MainScrollEvent.IsLoading = true;

                    var(apiStatus, respond) = await RequestsAsync.Global.GetGeneralDataAsync(seenNotifications, UserDetails.OnlineUsers, UserDetails.DeviceId, UserDetails.DeviceMsgId, offset);

                    switch (apiStatus)
                    {
                    case 200:
                    {
                        switch (respond)
                        {
                        case GetGeneralDataObject result:
                            Activity?.RunOnUiThread(() =>
                                {
                                    try
                                    {
                                        // Notifications
                                        var countNotificationsList = MAdapter.NotificationsList.Count;
                                        var respondList            = result.Notifications.Count;
                                        switch (respondList)
                                        {
                                        case > 0 when countNotificationsList > 0:
                                            {
                                                var listNew = result.Notifications?.Where(c => !MAdapter.NotificationsList.Select(fc => fc.Id).Contains(c.Id)).ToList();
                                                switch (listNew.Count)
                                                {
                                                case > 0:
                                                    {
                                                        foreach (var notification in listNew)
                                                        {
                                                            MAdapter.NotificationsList.Insert(0, notification);
                                                        }

                                                        MAdapter.NotifyItemRangeInserted(countNotificationsList - 1, MAdapter.NotificationsList.Count - countNotificationsList);
                                                        break;
                                                    }
                                                }

                                                break;
                                            }

                                        case > 0:
                                            MAdapter.NotificationsList = new ObservableCollection <NotificationObject>(result.Notifications);
                                            MAdapter.NotifyDataSetChanged();
                                            break;

                                        default:
                                            {
                                                switch (MAdapter.NotificationsList.Count)
                                                {
                                                case > 10 when !MRecycler.CanScrollVertically(1):
                                                    Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreNotifications), ToastLength.Short)?.Show();
                                                    break;
                                                }

                                                break;
                                            }
                                        }

                                        switch (AppSettings.ShowTrendingPage)
                                        {
                                        case true when GlobalContext.TrendingTab != null:
                                            {
                                                // FriendRequests
                                                var respondListFriendRequests = result?.FriendRequests?.Count;
                                                switch (respondListFriendRequests)
                                                {
                                                case > 0:
                                                    {
                                                        ListUtils.FriendRequestsList = new ObservableCollection <UserDataObject>(result.FriendRequests);

                                                        var checkList = GlobalContext.TrendingTab.MAdapter.TrendingList.FirstOrDefault(q => q.Type == Classes.ItemType.FriendRequest);
                                                        switch (checkList)
                                                        {
                                                        case null:
                                                            {
                                                                var friendRequests = new Classes.TrendingClass
                                                                {
                                                                    Id       = 400,
                                                                    UserList = new List <UserDataObject>(),
                                                                    Type     = Classes.ItemType.FriendRequest
                                                                };

                                                                var list = result.FriendRequests.TakeLast(4).ToList();
                                                                switch (list.Count)
                                                                {
                                                                case > 0:
                                                                    friendRequests.UserList.AddRange(list);
                                                                    break;
                                                                }

                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Add(friendRequests);

                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Add(new Classes.TrendingClass
                                                                {
                                                                    Type = Classes.ItemType.Divider
                                                                });
                                                                break;
                                                            }

                                                        default:
                                                            {
                                                                switch (checkList.UserList.Count)
                                                                {
                                                                case < 3:
                                                                    {
                                                                        var list = result.FriendRequests.TakeLast(4).ToList();
                                                                        switch (list.Count)
                                                                        {
                                                                        case > 0:
                                                                            checkList.UserList.AddRange(list);
                                                                            break;
                                                                        }
                                                                        break;
                                                                    }
                                                                }

                                                                break;
                                                            }
                                                        }

                                                        break;
                                                    }
                                                }

                                                // TrendingHashtag
                                                var respondListHashTag = result?.TrendingHashtag?.Count;
                                                switch (respondListHashTag)
                                                {
                                                case > 0 when AppSettings.ShowTrendingHashTags:
                                                    {
                                                        ListUtils.HashTagList = new ObservableCollection <TrendingHashtag>(result.TrendingHashtag);

                                                        var checkList = GlobalContext.TrendingTab.MAdapter.TrendingList.FirstOrDefault(q => q.Type == Classes.ItemType.HashTag);
                                                        switch (checkList)
                                                        {
                                                        case null:
                                                            {
                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Add(new Classes.TrendingClass
                                                                {
                                                                    Id          = 900,
                                                                    Title       = Activity.GetText(Resource.String.Lbl_TrendingHashTags),
                                                                    SectionType = Classes.ItemType.HashTag,
                                                                    Type        = Classes.ItemType.Section,
                                                                });

                                                                var list = result.TrendingHashtag.Take(5).ToList();

                                                                foreach (var item in from item in list let check = GlobalContext.TrendingTab.MAdapter.TrendingList.FirstOrDefault(a => a.HashTags?.Id == item.Id && a.Type == Classes.ItemType.HashTag) where check == null select item)
                                                                {
                                                                    GlobalContext.TrendingTab.MAdapter.TrendingList.Add(new Classes.TrendingClass
                                                                    {
                                                                        Id       = long.Parse(item.Id),
                                                                        HashTags = item,
                                                                        Type     = Classes.ItemType.HashTag
                                                                    });
                                                                }

                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Add(new Classes.TrendingClass
                                                                {
                                                                    Type = Classes.ItemType.Divider
                                                                });
                                                                break;
                                                            }
                                                        }

                                                        break;
                                                    }
                                                }

                                                // PromotedPages
                                                var respondListPromotedPages = result.PromotedPages?.Count;
                                                switch (respondListPromotedPages)
                                                {
                                                case > 0 when AppSettings.ShowPromotedPages:
                                                    {
                                                        var checkList = GlobalContext.TrendingTab.MAdapter.TrendingList.FirstOrDefault(q => q.Type == Classes.ItemType.ProPage);
                                                        switch (checkList)
                                                        {
                                                        case null:
                                                            {
                                                                var proPage = new Classes.TrendingClass
                                                                {
                                                                    Id       = 200,
                                                                    PageList = new List <PageClass>(),
                                                                    Type     = Classes.ItemType.ProPage
                                                                };

                                                                foreach (var item in from item in result.PromotedPages let check = proPage.PageList.FirstOrDefault(a => a.PageId == item.PageId) where check == null select item)
                                                                {
                                                                    proPage.PageList.Add(item);
                                                                }

                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Insert(0, proPage);
                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Insert(1, new Classes.TrendingClass
                                                                {
                                                                    Type = Classes.ItemType.Divider
                                                                });
                                                                break;
                                                            }

                                                        default:
                                                            {
                                                                foreach (var item in from item in result.PromotedPages let check = checkList.PageList.FirstOrDefault(a => a.PageId == item.PageId) where check == null select item)
                                                                {
                                                                    checkList.PageList.Add(item);
                                                                }

                                                                break;
                                                            }
                                                        }

                                                        break;
                                                    }
                                                }

                                                // ProUsers
                                                var respondListProUsers = result?.ProUsers?.Count;
                                                switch (respondListProUsers)
                                                {
                                                case > 0 when AppSettings.ShowProUsersMembers:
                                                    {
                                                        var checkList = GlobalContext.TrendingTab.MAdapter.TrendingList.FirstOrDefault(q => q.Type == Classes.ItemType.ProUser);
                                                        switch (checkList)
                                                        {
                                                        case null:
                                                            {
                                                                var proUser = new Classes.TrendingClass
                                                                {
                                                                    Id       = 100,
                                                                    UserList = new List <UserDataObject>(),
                                                                    Type     = Classes.ItemType.ProUser
                                                                };

                                                                foreach (var item in from item in result.ProUsers let check = proUser.UserList.FirstOrDefault(a => a.UserId == item.UserId) where check == null select item)
                                                                {
                                                                    proUser.UserList.Add(item);
                                                                }

                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Insert(0, proUser);
                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Insert(1, new Classes.TrendingClass
                                                                {
                                                                    Type = Classes.ItemType.Divider
                                                                });
                                                                break;
                                                            }

                                                        default:
                                                            {
                                                                foreach (var item in from item in result.ProUsers let check = checkList.UserList.FirstOrDefault(a => a.UserId == item.UserId) where check == null select item)
                                                                {
                                                                    checkList.UserList.Add(item);
                                                                }

                                                                break;
                                                            }
                                                        }

                                                        break;
                                                    }
                                                }

                                                switch (AppSettings.ShowInfoCoronaVirus)
                                                {
                                                case true:
                                                    {
                                                        var check = GlobalContext.TrendingTab.MAdapter.TrendingList.FirstOrDefault(q => q.Type == Classes.ItemType.CoronaVirus);
                                                        switch (check)
                                                        {
                                                        case null:
                                                            {
                                                                var coronaVirus = new Classes.TrendingClass
                                                                {
                                                                    Id   = 20316,
                                                                    Type = Classes.ItemType.CoronaVirus
                                                                };

                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Insert(0, coronaVirus);
                                                                GlobalContext.TrendingTab.MAdapter.TrendingList.Insert(1, new Classes.TrendingClass
                                                                {
                                                                    Type = Classes.ItemType.Divider
                                                                });
                                                                break;
                                                            }
                                                        }

                                                        break;
                                                    }
                                                }

                                                GlobalContext.TrendingTab.MAdapter.NotifyDataSetChanged();
                                                break;
                                            }
                                        }

                                        MainScrollEvent.IsLoading = false;
                                        ShowEmptyPage();
                                    }
                                    catch (Exception e)
                                    {
                                        Methods.DisplayReportResultTrack(e);
                                    }
                                });
                            return(result.NewNotificationsCount, result.NewFriendRequestsCount, result.CountNewMessages, result.Announcement?.AnnouncementClass?.TextDecode);
                        }

                        break;
                    }

                    default:
                        Methods.DisplayReportResult(Activity, respond);
                        break;
                    }

                    Activity?.RunOnUiThread(ShowEmptyPage);
                    MainScrollEvent.IsLoading = false;

                    return("", "", "", "");
                }
                else
                {
                    Inflated = EmptyStateLayout.Inflate();
                    EmptyStateInflater x = new EmptyStateInflater();
                    x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection);
                    switch (x.EmptyStateButton.HasOnClickListeners)
                    {
                    case false:
                        x.EmptyStateButton.Click += null !;
                        x.EmptyStateButton.Click += EmptyStateButtonOnClick;
                        break;
                    }

                    Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                }
            }
            catch (Exception e)
            {
                MainScrollEvent.IsLoading = false;
                Methods.DisplayReportResultTrack(e);
            }
            MainScrollEvent.IsLoading = false;
            return("", "", "", "");
        }
예제 #4
0
        private async Task LoadDataChannelAsync()
        {
            if (!UserDetails.IsLogin)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                var(apiStatus, respond) = await RequestsAsync.Video.PopularChannels_Http();

                if (apiStatus != 200 || !(respond is GetPopularChannelsObject result) || result.Channels == null)
                {
                    MainScrollEvent.IsLoading = false;
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.Channels.Count;
                    if (respondList > 0)
                    {
                        var checkList = MAdapter.TrendingList.FirstOrDefault(q => q.Type == ItemType.Channel);
                        if (checkList == null)
                        {
                            var channel = new Classes.TrendingClass()
                            {
                                Id          = 200,
                                ChannelList = new List <GetPopularChannelsObject.Channel>(),
                                Type        = ItemType.Channel
                            };

                            foreach (var item in from item in result.Channels let check = channel.ChannelList.FirstOrDefault(a => a.UserData?.Id == item.UserData?.Id) where check == null select item)
                            {
                                channel.ChannelList.Add(item);
                            }

                            MAdapter.TrendingList.Insert(0, channel);
                        }
                        else
                        {
                            foreach (var item in from item in result.Channels let check = checkList.ChannelList.FirstOrDefault(a => a.UserData?.Id == item.UserData?.Id) where check == null select item)
                            {
                                checkList.ChannelList.Add(item);
                            }
                        }
                    }
                }

                //Activity.RunOnUiThread(ShowEmptyPage);
            }
            else
            {
                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(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
            }
        }
예제 #5
0
        private async Task LoadUsersAsync(string offset = "0")
        {
            if (MainScrollEvent != null && MainScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                if (MainScrollEvent != null)
                {
                    MainScrollEvent.IsLoading = true;
                }

                if (UserDetails.Lat == "" && UserDetails.Lng == "")
                {
                    var locator = CrossGeolocator.Current;
                    locator.DesiredAccuracy = 50;
                    var position = await locator.GetPositionAsync(TimeSpan.FromMilliseconds(10000));

                    Console.WriteLine("Position Status: {0}", position.Timestamp);
                    Console.WriteLine("Position Latitude: {0}", position.Latitude);
                    Console.WriteLine("Position Longitude: {0}", position.Longitude);

                    UserDetails.Lat = position.Latitude.ToString(CultureInfo.InvariantCulture);
                    UserDetails.Lng = position.Longitude.ToString(CultureInfo.InvariantCulture);
                }

                UserDetails.Location = ListUtils.MyUserInfo.FirstOrDefault()?.Location;

                var dictionary = new Dictionary <string, string>
                {
                    { "limit", "25" },
                    { "offset", offset },
                    { "_gender", UserDetails.Gender },
                    { "_located", UserDetails.Located },
                    { "_location", UserDetails.Location },
                    { "_age_from", UserDetails.AgeMin.ToString() },
                    { "_age_to", UserDetails.AgeMax.ToString() },
                    { "_lat", UserDetails.Lat },
                    { "_lng", UserDetails.Lng },
                    { "_body", UserDetails.Body ?? "" },
                    { "_ethnicity", UserDetails.Ethnicity ?? "" },
                    { "_religion", UserDetails.Religion ?? "" },
                    { "_drink", UserDetails.Drink ?? "" },
                    { "_smoke", UserDetails.Smoke ?? "" },
                    { "_education", UserDetails.Education ?? "" },
                    { "_pets", UserDetails.Pets ?? "" },
                    { "_relationship", UserDetails.RelationShip ?? "" },
                    { "_language", UserDetails.Language ?? GlobalConstants.FilterOptionLanguage },
                    { "_interest", UserDetails.Interest ?? "" },
                    { "_height_from", UserDetails.FromHeight ?? GlobalConstants.FilterOptionFromHeight },
                    { "_height_to", UserDetails.ToHeight ?? GlobalConstants.FilterOptionToHeight },
                };

                var(apiStatus, respond) = await RequestsAsync.Users.SearchAsync(dictionary);

                if (apiStatus != 200 || !(respond is ListUsersObject result) || result.Data == null)
                {
                    if (MainScrollEvent != null)
                    {
                        MainScrollEvent.IsLoading = false;
                    }
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.Data.Count;
                    if (respondList > 0)
                    {
                        foreach (var item in result.Data)
                        {
                            var check = MAdapter.TrendingList.FirstOrDefault(a => a.Id == item.Id);
                            if (check == null)
                            {
                                var users = new Classes.TrendingClass()
                                {
                                    Id        = item.Id,
                                    UsersData = item,
                                    Type      = ItemType.Users
                                };

                                if (UserDetails.SwitchState)
                                {
                                    var online = QuickDateTools.GetStatusOnline(item.Lastseen, item.Online);
                                    if (!online)
                                    {
                                        continue;
                                    }
                                    MAdapter.TrendingList.Add(users);
                                }
                                else
                                {
                                    MAdapter.TrendingList.Add(users);
                                }
                            }
                        }
                    }
                }

                Activity.RunOnUiThread(ShowEmptyPage);
            }
            else
            {
                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(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                if (MainScrollEvent != null)
                {
                    MainScrollEvent.IsLoading = false;
                }
            }
            if (MainScrollEvent != null)
            {
                MainScrollEvent.IsLoading = false;
            }
        }
예제 #6
0
        private async Task LoadProUser()
        {
            if (Methods.CheckConnectivity())
            {
                //int countList = MAdapter.TrendingList.Count;
                (int apiStatus, var respond) = await RequestsAsync.Users.GetProAsync("20");

                if (apiStatus != 200 || !(respond is ListUsersObject result) || result.Data == null)
                {
                    if (MainScrollEvent != null)
                    {
                        MainScrollEvent.IsLoading = false;
                    }
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.Data.Count;
                    if (respondList > 0)
                    {
                        var checkList = MAdapter.TrendingList.FirstOrDefault(q => q.Type == ItemType.ProUser);
                        if (checkList == null)
                        {
                            var proUser = new Classes.TrendingClass()
                            {
                                Id          = 100,
                                ProUserList = new List <UserInfoObject>(),
                                Type        = ItemType.ProUser
                            };

                            var data = ListUtils.MyUserInfo?.FirstOrDefault();
                            if (data?.IsPro != "1")
                            {
                                if (!AppSettings.EnableAppFree)
                                {
                                    var dataOwner = proUser.ProUserList.FirstOrDefault(a => a.Type == "Your");
                                    if (dataOwner == null && data != null)
                                    {
                                        data.Type     = "Your";
                                        data.Username = Context.GetText(Resource.String.Lbl_AddMe);
                                        data.IsOwner  = true;
                                        proUser.ProUserList.Insert(0, data);
                                    }
                                }
                            }

                            foreach (var item in from item in result.Data let check = proUser.ProUserList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                            {
                                proUser.ProUserList.Add(item);
                            }

                            MAdapter.TrendingList.Insert(0, proUser);
                        }
                        else
                        {
                            foreach (var item in from item in result.Data let check = checkList.ProUserList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                            {
                                checkList.ProUserList.Add(item);
                            }
                        }
                    }
                }
            }
            else
            {
                Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
            }
        }