private void SharedVideos() { try { if (Methods.CheckConnectivity()) { MAdapter.VideoList.Clear(); var sqlEntity = new SqLiteDatabase(); var likedVideos = sqlEntity.Get_SharedVideos(); if (likedVideos.Count > 0) { MAdapter.VideoList = new ObservableCollection <VideoObject>(AppTools.ListFilter(new List <VideoObject>(likedVideos))); MAdapter.NotifyDataSetChanged(); } sqlEntity.Dispose(); GlobalContext.LibrarySynchronizer.AddToShareVideo(MAdapter.VideoList.FirstOrDefault(), MAdapter.VideoList.Count); 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(); } } catch (Exception exception) { Console.WriteLine(exception); } }
private async Task LoadDataAsync(string topOffset = "0", string latestOffset = "0", string favOffset = "0") { if (MainScrollEvent.IsLoading) { return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; int countList = MAdapter.VideoList.Count; var(apiStatus, respond) = await RequestsAsync.Video.Get_Videos_Http("0", topOffset, latestOffset, favOffset, "25"); if (apiStatus != 200 || !(respond is GetVideosObject result) || result.DataResult == null) { MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(Activity, respond); } else { int respondList = 0; if (TypeVideo.Contains("Top")) { result.DataResult.Top = AppTools.ListFilter(new List <VideoObject>(result.DataResult.Top)); respondList = result.DataResult.Top.Count; } else if (TypeVideo.Contains("Latest")) { result.DataResult.Latest = AppTools.ListFilter(new List <VideoObject>(result.DataResult.Latest)); respondList = result.DataResult.Latest.Count; } else if (TypeVideo.Contains("Fav")) { result.DataResult.Fav = AppTools.ListFilter(new List <VideoObject>(result.DataResult.Fav)); respondList = result.DataResult.Fav.Count; } if (respondList > 0) { if (countList > 0) { if (TypeVideo.Contains("Top")) { foreach (var item in from item in result.DataResult.Top let check = MAdapter.VideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { MAdapter.VideoList.Add(item); } } else if (TypeVideo.Contains("Latest")) { foreach (var item in from item in result.DataResult.Latest let check = MAdapter.VideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { MAdapter.VideoList.Add(item); } } else if (TypeVideo.Contains("Fav")) { foreach (var item in from item in result.DataResult.Fav let check = MAdapter.VideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { MAdapter.VideoList.Add(item); } } Activity.RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); } else { if (TypeVideo.Contains("Top")) { MAdapter.VideoList = new ObservableCollection <VideoObject>(result.DataResult.Top); } else if (TypeVideo.Contains("Latest")) { MAdapter.VideoList = new ObservableCollection <VideoObject>(result.DataResult.Latest); } else if (TypeVideo.Contains("Fav")) { MAdapter.VideoList = new ObservableCollection <VideoObject>(result.DataResult.Fav); } Activity.RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); } } else { if (MAdapter.VideoList.Count > 10 && !MRecycler.CanScrollVertically(1)) { Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreVideos), ToastLength.Short).Show(); } } } 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(); } MainScrollEvent.IsLoading = false; }
private async Task LoadDataAsync(string offset = "0") { if (MainScrollEvent.IsLoading) { return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; var(apiStatus, respond) = await RequestsAsync.Video.Get_Subscriptions_VideosOrChannel_Http("false", offset, "20"); if (apiStatus != 200 || !(respond is GetVideosListObject result) || result.VideoList == null) { MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(Activity, respond); } else { var respondList = result.VideoList.Count; if (respondList > 0) { result.VideoList = AppTools.ListFilter(result.VideoList); foreach (var users in from item in result.VideoList let check = MAdapter.SubscriptionsList.FirstOrDefault(a => a.VideoData?.VideoId == item.VideoId) where check == null select new Classes.SubscriptionsClass() { Id = Convert.ToInt32(item.Id), VideoData = item, Type = ItemType.Video }) { MAdapter.SubscriptionsList.Add(users); } } else { if (MAdapter.SubscriptionsList.Count > 10 && !MRecycler.CanScrollVertically(1)) { Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreVideos), ToastLength.Short).Show(); } } } 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(); } MainScrollEvent.IsLoading = false; }
private async Task LoadDataAsync(string offset = "0") { if (MainScrollEvent.IsLoading) { return; } if (Methods.CheckConnectivity()) { MainScrollEvent.IsLoading = true; int countList = MAdapter.VideoList.Count; var(apiStatus, respond) = await RequestsAsync.Video.Get_Liked_Videos_Http("25", offset); if (apiStatus != 200 || !(respond is GetVideosListObject result) || result.VideoList == null) { MainScrollEvent.IsLoading = false; Methods.DisplayReportResult(Activity, respond); } else { var respondList = result.VideoList.Count; if (respondList > 0) { result.VideoList = AppTools.ListFilter(result.VideoList); if (countList > 0) { foreach (var item in from item in result.VideoList let check = MAdapter.VideoList.FirstOrDefault(a => a.VideoId == item.VideoId) where check == null select item) { MAdapter.VideoList.Add(item); } Activity.RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.VideoList.Count - countList); }); } else { MAdapter.VideoList = new ObservableCollection <VideoObject>(result.VideoList); Activity.RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); }); } } else { if (MAdapter.VideoList.Count > 10 && !MRecycler.CanScrollVertically(1)) { Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreVideos), ToastLength.Short).Show(); } } } GlobalContext.LibrarySynchronizer.AddToLiked(MAdapter.VideoList.FirstOrDefault(), MAdapter.VideoList.Count); 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(); } MainScrollEvent.IsLoading = false; }
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; }