private async Task LoadRandomGroup(string offset)
        {
            if (Methods.CheckConnectivity())
            {
                var countList = RandomAdapter.GroupList.Count;

                var dictionary = new Dictionary <string, string>
                {
                    { "limit", "30" },
                    { "group_offset", offset },
                    { "search_key", "a" },
                };

                var(respondCode, respondString) = await RequestsAsync.Global.Get_Search(dictionary);

                if (respondCode.Equals(200))
                {
                    if (respondString is GetSearchObject result)
                    {
                        var respondList = result.Groups.Count;
                        if (respondList > 0)
                        {
                            if (countList > 0)
                            {
                                foreach (var item in from item in result.Groups let check = RandomAdapter.GroupList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                                {
                                    RandomAdapter.GroupList.Add(item);
                                }

                                RunOnUiThread(() => { RandomAdapter.NotifyItemRangeInserted(countList, RandomAdapter.GroupList.Count - countList); });
                            }
                            else
                            {
                                RandomAdapter.GroupList = new ObservableCollection <GroupClass>(result.Groups);

                                RunOnUiThread(() =>
                                {
                                    if (RandomGroupInflated == null)
                                    {
                                        RandomGroupInflated = RandomGroupViewStub.Inflate();
                                    }

                                    RecyclerInflaterRandomGroup = new TemplateRecyclerInflater();
                                    RecyclerInflaterRandomGroup.InflateLayout <GroupClass>(this, RandomGroupInflated, RandomAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerVertical, 0, true, GetString(Resource.String.Lbl_RandomGroups));
                                });
                            }
                        }
                        else
                        {
                            if (RecyclerInflaterRandomGroup?.Recyler != null && (RandomAdapter.GroupList.Count > 10 && !RecyclerInflaterRandomGroup.Recyler.CanScrollVertically(1)))
                            {
                                Toast.MakeText(this, GetText(Resource.String.Lbl_NoMoreGroup), ToastLength.Short).Show();
                            }
                        }
                    }
                }
                else
                {
                    Methods.DisplayReportResult(this, respondString);
                }

                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(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
            }
        }
Example #2
0
        private async Task LoadArtists(string offsetArtists = "0")
        {
            int countList = ArtistsAdapter.ArtistsList.Count;

            (int apiStatus, var respond) = await RequestsAsync.User.GetArtistsAsync("20", offsetArtists).ConfigureAwait(false);

            if (apiStatus == 200)
            {
                if (respond is GetUserObject result)
                {
                    var respondList = result.Data?.UserList.Count;
                    if (respondList > 0)
                    {
                        if (countList > 0)
                        {
                            foreach (var item in from item in result.Data?.UserList let check = ArtistsAdapter.ArtistsList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                            {
                                ArtistsAdapter.ArtistsList.Add(item);
                            }

                            Activity.RunOnUiThread(() =>
                            {
                                ArtistsAdapter.NotifyItemRangeInserted(countList - 1, ArtistsAdapter.ArtistsList.Count - countList);
                            });
                        }
                        else
                        {
                            ArtistsAdapter.ArtistsList = new ObservableCollection <UserDataObject>(result.Data?.UserList);

                            Activity.RunOnUiThread(() =>
                            {
                                if (ArtistsInflated == null)
                                {
                                    ArtistsInflated = ArtistsViewStub.Inflate();
                                }

                                TemplateRecyclerInflater recyclerInflater = new TemplateRecyclerInflater();
                                recyclerInflater.InflateLayout <UserDataObject>(Activity, ArtistsInflated, ArtistsAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerHorizontal, 0, true, Context.GetText(Resource.String.Lbl_Artists));
                                if (!recyclerInflater.MainLinear.HasOnClickListeners)
                                {
                                    recyclerInflater.MainLinear.Click += null;
                                    recyclerInflater.MainLinear.Click += ArtistsMoreOnClick;
                                }

                                if (ArtistsScrollEvent == null)
                                {
                                    RecyclerViewOnScrollListener playlistRecyclerViewOnScrollListener = new RecyclerViewOnScrollListener(recyclerInflater.LayoutManager);
                                    ArtistsScrollEvent = playlistRecyclerViewOnScrollListener;
                                    ArtistsScrollEvent.LoadMoreEvent += ArtistsScrollEventOnLoadMoreEvent;
                                    recyclerInflater.Recyler.AddOnScrollListener(playlistRecyclerViewOnScrollListener);
                                    ArtistsScrollEvent.IsLoading = false;
                                }
                            });
                        }
                    }
                    else
                    {
                        Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreArtists), ToastLength.Short).Show();
                    }
                }
            }
            else
            {
                Methods.DisplayReportResult(Activity, respond);
            }

            Activity.RunOnUiThread(ShowEmptyPage);
        }
        private async Task LoadGroup(string offset)
        {
            if (SuggestedGroupScrollEvent != null && SuggestedGroupScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                if (SuggestedGroupScrollEvent != null)
                {
                    SuggestedGroupScrollEvent.IsLoading = true;
                }
                var countList = MAdapter.GroupList.Count;

                var(respondCode, respondString) = await RequestsAsync.Group.GetRecommendedGroups("10", offset);

                if (respondCode.Equals(200))
                {
                    if (respondString is ListGroupsObject result)
                    {
                        var respondList = result.Data.Count;
                        if (respondList > 0)
                        {
                            if (countList > 0)
                            {
                                foreach (var item in from item in result.Data let check = MAdapter.GroupList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                                {
                                    MAdapter.GroupList.Add(item);
                                }

                                RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.GroupList.Count - countList); });
                            }
                            else
                            {
                                MAdapter.GroupList = new ObservableCollection <GroupClass>(result.Data);

                                RunOnUiThread(() =>
                                {
                                    if (SuggestedGroupInflated == null)
                                    {
                                        SuggestedGroupInflated = SuggestedGroupViewStub.Inflate();
                                    }

                                    RecyclerInflaterSuggestedGroup = new TemplateRecyclerInflater();
                                    RecyclerInflaterSuggestedGroup.InflateLayout <GroupClass>(this, SuggestedGroupInflated, MAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerHorizontal, 0, true, GetString(Resource.String.Lbl_SuggestedForYou), "", true);

                                    RecyclerInflaterSuggestedGroup.MainLinear.Click += MainLinearSuggestedGroupOnClick;

                                    if (SuggestedGroupScrollEvent == null)
                                    {
                                        RecyclerViewOnScrollListener playlistRecyclerViewOnScrollListener = new RecyclerViewOnScrollListener(RecyclerInflaterSuggestedGroup.LayoutManager);
                                        SuggestedGroupScrollEvent = playlistRecyclerViewOnScrollListener;
                                        SuggestedGroupScrollEvent.LoadMoreEvent += SuggestedGroupScrollEventOnLoadMoreEvent;
                                        RecyclerInflaterSuggestedGroup.Recyler.AddOnScrollListener(playlistRecyclerViewOnScrollListener);
                                        SuggestedGroupScrollEvent.IsLoading = false;
                                    }
                                });
                            }
                        }
                        else
                        {
                            if (RecyclerInflaterSuggestedGroup?.Recyler != null && MAdapter.GroupList.Count > 10 && !RecyclerInflaterSuggestedGroup.Recyler.CanScrollVertically(1))
                            {
                                Toast.MakeText(this, GetText(Resource.String.Lbl_NoMoreGroup), ToastLength.Short).Show();
                            }
                        }
                    }
                }
                else
                {
                    Methods.DisplayReportResult(this, respondString);
                }

                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(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                if (SuggestedGroupScrollEvent != null)
                {
                    SuggestedGroupScrollEvent.IsLoading = false;
                }
            }
        }
Example #4
0
        private void ShowEmptyPage()
        {
            try
            {
                SwipeRefreshLayout.OnFinishFreshAndLoad();

                if (ProgressBar.Visibility == ViewStates.Visible)
                {
                    ProgressBar.Visibility = ViewStates.Gone;
                }

                if (RecommendedList?.Count > 0)
                {
                    if (ViewPagerView.Adapter == null)
                    {
                        ViewPagerView.Adapter     = new ImageCoursalViewPager(Activity, RecommendedList);
                        ViewPagerView.CurrentItem = 0;
                        ViewPagerCircleIndicator.SetViewPager(ViewPagerView);
                    }
                    ViewPagerView.Adapter.NotifyDataSetChanged();
                }

                if (NewReleasesSoundAdapter.SoundsList?.Count > 0)
                {
                    if (NewReleasesInflated == null)
                    {
                        NewReleasesInflated = NewReleasesViewStub.Inflate();
                    }

                    TemplateRecyclerInflater recyclerInflater = new TemplateRecyclerInflater();
                    recyclerInflater.InflateLayout <SoundDataObject>(Activity, NewReleasesInflated, NewReleasesSoundAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerHorizontal, 0, true, Context.GetText(Resource.String.Lbl_LatestSongs_Title), Context.GetText(Resource.String.Lbl_LatestSongs_Description));
                    if (!recyclerInflater.MainLinear.HasOnClickListeners)
                    {
                        recyclerInflater.MainLinear.Click += null;
                        recyclerInflater.MainLinear.Click += NewReleasesMoreOnClick;
                    }
                }

                if (RecentlyPlayedSoundAdapter.SoundsList?.Count > 0)
                {
                    if (RecentlyPlayedInflated == null)
                    {
                        RecentlyPlayedInflated = RecentlyPlayedViewStub.Inflate();
                    }

                    TemplateRecyclerInflater recyclerInflater = new TemplateRecyclerInflater();
                    recyclerInflater.InflateLayout <SoundDataObject>(Activity, RecentlyPlayedInflated, RecentlyPlayedSoundAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerHorizontal, 0, true, Context.GetText(Resource.String.Lbl_RecentlyPlayed));
                    if (!recyclerInflater.MainLinear.HasOnClickListeners)
                    {
                        recyclerInflater.MainLinear.Click += null;
                        recyclerInflater.MainLinear.Click += RecentlyPlayedMoreOnClick;
                    }

                    SqLiteDatabase dbDatabase = new SqLiteDatabase();
                    dbDatabase.InsertOrReplace_PublicRecentlyPlayedSoundList(RecentlyPlayedSoundAdapter.SoundsList);
                    dbDatabase.Dispose();
                }

                if (PopularSoundAdapter.SoundsList?.Count > 0)
                {
                    if (PopularInflated == null)
                    {
                        PopularInflated = PopularViewStub.Inflate();
                    }

                    TemplateRecyclerInflater recyclerInflater = new TemplateRecyclerInflater();
                    recyclerInflater.InflateLayout <SoundDataObject>(Activity, PopularInflated, PopularSoundAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerHorizontal, 0, true, Context.GetText(Resource.String.Lbl_Popular_Title));
                    if (!recyclerInflater.MainLinear.HasOnClickListeners)
                    {
                        recyclerInflater.MainLinear.Click += null;
                        recyclerInflater.MainLinear.Click += PopularMoreOnClick;
                    }
                }

                if (GenresAdapter.GenresList.Count == 0)
                {
                    GenresAdapter.GenresList = ListUtils.GenresList;
                }

                if (GenresAdapter.GenresList.Count > 0)
                {
                    if (BrowseInflated == null)
                    {
                        BrowseInflated = BrowseViewStub.Inflate();
                    }

                    TemplateRecyclerInflater recyclerInflater = new TemplateRecyclerInflater();
                    recyclerInflater.InflateLayout <GenresObject.DataGenres>(Activity, BrowseInflated, GenresAdapter, TemplateRecyclerInflater.TypeLayoutManager.LinearLayoutManagerHorizontal, 0, true, Context.GetText(Resource.String.Lbl_Browse), Context.GetText(Resource.String.Lbl_Browse_Description));
                    if (!recyclerInflater.MainLinear.HasOnClickListeners)
                    {
                        recyclerInflater.MainLinear.Click += null;
                        recyclerInflater.MainLinear.Click += BrowseMoreOnClick;
                    }
                }

                if (RecommendedList?.Count == 0 && NewReleasesSoundAdapter?.SoundsList?.Count == 0 && RecentlyPlayedSoundAdapter?.SoundsList?.Count == 0 &&
                    PopularSoundAdapter?.SoundsList?.Count == 0 && GenresAdapter?.GenresList?.Count == 0 && ArtistsAdapter.ArtistsList?.Count == 0)
                {
                    if (Inflated == null)
                    {
                        Inflated = EmptyStateLayout.Inflate();
                    }

                    EmptyStateInflater x = new EmptyStateInflater();
                    x.InflateLayout(Inflated, EmptyStateInflater.Type.NoSound);
                    if (x.EmptyStateButton.HasOnClickListeners)
                    {
                        x.EmptyStateButton.Click += null;
                    }
                    EmptyStateLayout.Visibility = ViewStates.Visible;
                }
            }
            catch (Exception e)
            {
                SwipeRefreshLayout.OnFinishFreshAndLoad();
                if (ProgressBar.Visibility == ViewStates.Visible)
                {
                    ProgressBar.Visibility = ViewStates.Gone;
                }
                Console.WriteLine(e);
            }
        }