private void AddCategory() { try { //Category var respondList = CategoriesController.ListCategories.Count; if (respondList > 0) { var checkList = MAdapter.MainVideoList.FirstOrDefault(q => q.Type == ItemType.Category); if (checkList == null) { var category = new Classes.MainVideoClass() { Id = 400, CategoryList = new List <Classes.Category>(), Type = ItemType.Category }; category.CategoryList = new List <Classes.Category>(CategoriesController.ListCategories); MAdapter.MainVideoList.Insert(0, category); } else { checkList.CategoryList = new List <Classes.Category>(CategoriesController.ListCategories); } } } catch (Exception e) { Console.WriteLine(e); } }
private async Task LoadVideos(string featuredOffset = "0", string topOffset = "0", string latestOffset = "0", string favOffset = "0") { if (MainScrollEvent.IsLoading) { return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; var(apiStatus, respond) = await RequestsAsync.Video.Get_Videos_Http(featuredOffset, topOffset, latestOffset, favOffset, "20"); if (apiStatus == 200) { if (respond is GetVideosObject result) { if (result.DataResult.Featured?.Count > 0) { result.DataResult.Featured = AppTools.ListFilter(result.DataResult.Featured); if (ListUtils.FeaturedVideosList.Count > 0) { foreach (var item in from item in result.DataResult.Featured let check = ListUtils.FeaturedVideosList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { ListUtils.FeaturedVideosList.Add(item); } } else { var result2 = result.DataResult.Featured.GroupBy(x => x.VideoId).Where(x => x.Count() == 1).Select(x => x.First()); ListUtils.FeaturedVideosList = new ObservableCollection <VideoObject>(result2); } } //Top var respondList = result.DataResult.Top.Count; if (respondList > 0) { result.DataResult.Top = AppTools.ListFilter(result.DataResult.Top); var checkList = MAdapter.MainVideoList.FirstOrDefault(q => q.Type == ItemType.TopVideos); if (checkList == null) { var topVideos = new Classes.MainVideoClass() { Id = 101, TopVideoList = new List <VideoObject>(), Type = ItemType.TopVideos }; foreach (var item in from item in result.DataResult.Top let check = topVideos.TopVideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { if (topVideos.TopVideoList.Count <= AppSettings.CountVideosTop) { topVideos.TopVideoList.Add(item); } else { var c = OtherVideosList.FirstOrDefault(a => a.VideoId == item.VideoId); if (c == null) { OtherVideosList.Add(item); } } } MAdapter.MainVideoList.Add(topVideos); } else { foreach (var item in from item in result.DataResult.Top let check = checkList.TopVideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { if (checkList.TopVideoList.Count <= AppSettings.CountVideosTop) { checkList.TopVideoList.Add(item); } else { var c = OtherVideosList.FirstOrDefault(a => a.VideoId == item.VideoId); if (c == null) { OtherVideosList.Add(item); } } } } } //Latest var respondLatestList = result.DataResult.Latest.Count; if (respondLatestList > 0) { result.DataResult.Latest = AppTools.ListFilter(result.DataResult.Latest); var checkList = MAdapter.MainVideoList.FirstOrDefault(q => q.Type == ItemType.LatestVideos); if (checkList == null) { var latestVideos = new Classes.MainVideoClass() { Id = 102, LatestVideoList = new List <VideoObject>(), Type = ItemType.LatestVideos }; foreach (var item in from item in result.DataResult.Latest let check = latestVideos.LatestVideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { if (latestVideos.LatestVideoList.Count <= AppSettings.CountVideosLatest) { latestVideos.LatestVideoList.Add(item); } else { var c = OtherVideosList.FirstOrDefault(a => a.VideoId == item.VideoId); if (c == null) { OtherVideosList.Add(item); } } } MAdapter.MainVideoList.Add(latestVideos); } else { foreach (var item in from item in result.DataResult.Latest let check = checkList.LatestVideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { if (checkList.LatestVideoList.Count <= AppSettings.CountVideosLatest) { checkList.LatestVideoList.Add(item); } else { var c = OtherVideosList.FirstOrDefault(a => a.VideoId == item.VideoId); if (c == null) { OtherVideosList.Add(item); } } } } } //Fav var respondFavList = result.DataResult.Fav.Count; if (respondFavList > 0) { result.DataResult.Fav = AppTools.ListFilter(result.DataResult.Fav); var checkList = MAdapter.MainVideoList.FirstOrDefault(q => q.Type == ItemType.FavVideos); if (checkList == null) { var favVideos = new Classes.MainVideoClass() { Id = 103, FavVideoList = new List <VideoObject>(), Type = ItemType.FavVideos }; foreach (var item in from item in result.DataResult.Fav let check = favVideos.FavVideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { if (favVideos.FavVideoList.Count <= AppSettings.CountVideosFav) { favVideos.FavVideoList.Add(item); } else { var c = OtherVideosList.FirstOrDefault(a => a.VideoId == item.VideoId); if (c == null) { OtherVideosList.Add(item); } } } MAdapter.MainVideoList.Add(favVideos); } else { foreach (var item in from item in result.DataResult.Fav let check = checkList.FavVideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { if (checkList.FavVideoList.Count <= AppSettings.CountVideosFav) { checkList.FavVideoList.Add(item); } else { var c = OtherVideosList.FirstOrDefault(a => a.VideoId == item.VideoId); if (c == null) { OtherVideosList.Add(item); } } } } } //Other var respondOtherList = OtherVideosList.Count; if (respondOtherList > 0) { foreach (var users in from item in OtherVideosList let check = MAdapter.MainVideoList.FirstOrDefault(a => a.VideoData?.VideoId == item.VideoId) where check == null select new Classes.MainVideoClass() { Id = Convert.ToInt32(item.Id), VideoData = item, Type = ItemType.OtherVideos }) { MAdapter.MainVideoList.Add(users); } } else { if (OtherVideosList.Count > 10 && !MRecycler.CanScrollVertically(1)) { Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreVideos), ToastLength.Short).Show(); } } } } else { MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(Activity, respond); } 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, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show(); } MainScrollEvent.IsLoading = false; }