Пример #1
0
        public Video LoadData()
        {
            if (!_video.IsVideo)
            {
                var title = _video.Title;
                _video.LoadVideos();
                if (!_video.Videos.Any())
                {
                    return(this);
                }

                var v = _video.Videos.FirstOrDefault(x => x.IsVideo);

                v.Videos      = _video.Videos;
                _video        = v;
                PlayListTitle = title;
                LoadlstPlayListVideos();
            }
            else
            {
                var index = searchedVideos.FindIndex(x => x.Id == _video.Id);
                searchedVideos = ControllerRepository.Y(x => x.SearchAsync(UserData.CurrentUser.EntityId.Value, "", 30, 1, _video.Title, VideoSearchType.Mix)).Await().ToItemList(); // get relevant Videos
                searchedVideos.RemoveAll(x => x.Id == _video.Id);
                searchedVideos.Insert(0, _video);
                LoadlstVideos();
            }

            return(this);
        }
Пример #2
0
        private async void _txtSearch_QuerySubmitted(object sender, AutoSuggestBoxQuerySubmittedEventArgs e)
        {
            if (!await Methods.AppSettings.ValidateStoragePermission() || string.IsNullOrEmpty(_txtSearch.Text))
            {
                return;
            }

            var text = _txtSearch.Text;

            if (e?.ChosenSuggestion != null)
            {
                text = e.ChosenSuggestion.ToString();
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            var l = await this.StartLoading();

            var videos = ControllerRepository.Y(x => x.SearchAsync(UserData.CurrentUser.EntityId.Value, text, 6, 1, null, VideoSearchType.All)).Await();
            var src    = new SearchView(videos, _txtSearch.Text);

            src.Open();
            l.EndLoading();
        }
Пример #3
0
        public async Task DataBinder(MethodInformation method = null)
        {
            if (!this.UserIsLogedIn())
            {
                return;
            }


            var l = await this.StartLoading();

            myPlaylist.ItemsSource              = UserData.VideoCategoryViews;
            myPlaylist.Header.IsVisible         = myPlaylist.HasItems;
            playListSuggesting.ItemsSource      = ControllerRepository.Db(x => x.GetUserSuggestion(UserData.CurrentUser.EntityId.Value));
            playListSuggesting.Header.IsVisible = playListSuggesting.HasItems;
            playListUserSeach.ItemsSource       = ControllerRepository.Y(x => x.SearchAsync(UserData.CurrentUser.EntityId.Value, "", 10, 1, null, VideoSearchType.Recommendation)).Await()?.ToItemList();
            playListUserSeach.Header.IsVisible  = playListUserSeach.HasItems;
            //adsBanner.IsVisible = UserData.CurrentUser.UserType != UserType.Premium;
            l.EndLoading();

            if (!myPlaylist.HasItems && !UserData.Notified)
            {
                UserData.Notified = true;
                var config = new ToastConfig("BackgroundModeMessage".GetString())
                             .SetDuration(TimeSpan.FromSeconds(8))
                             .SetMessageTextColor(Color.Red)
                             .SetBackgroundColor(Color.WhiteSmoke)
                             .SetPosition(ToastPosition.Bottom);
                UserDialogs.Instance.Toast(config);
            }
            // start the ads
            //await Methods.ReguastNewAdd?.Invoke();
        }
Пример #4
0
 private void _txtSearch_TextChanged(object sender, dotMorten.Xamarin.Forms.AutoSuggestBoxTextChangedEventArgs e)
 {
     if (e.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
     {
         Task.Run(async() =>
         {
             var source = ControllerRepository.Y(x => x.GetSuggestQueries(_txtSearch.Text)).Await()?.ToList();
             Device.BeginInvokeOnMainThread(() =>
             {
                 _txtSearch.ItemsSource = source;
             });
         });
     }
 }
Пример #5
0
        public void DownloadVideo(YFileDownloadItem video)
        {
            if (!UserData.CanDownload())
            {
                Toast.MakeText(_context, "You dont have enough coins.", ToastLength.Long).Show();
            }

            var videos = ControllerRepository.Y(x => x.GetVideoAsync(video.VideoId, 18)).Await();

            if (!(videos?.Any() ?? false))
            {
                Toast.MakeText(_context, "Download unavailable", ToastLength.Long).Show();
                Logger?.Error($"Video [{video.VideoId}] unavailable");
                return;
            }

            if (!ObjectCacher.DownloadingFiles.ContainsKey(video.VideoId))
            {
                video.Auther      = videos.First().Auther;
                video.Duration    = videos.First().Duration;
                video.Description = videos.First().Description;
                video.Resolution  = videos.First().Resolution;
                video.Size        = videos.First().Size;
                video.FormatCode  = videos.First().FormatCode;
                video.Quality     = videos.First().Quality;
                ObjectCacher.DownloadingFiles.Add(video.VideoId, video);
                var intent = new Intent(_context, typeof(FileService));
                intent.PutExtra(FileService.URL, videos.FirstOrDefault()?.Url);
                intent.PutExtra(FileService.Title, video.Title);
                intent.PutExtra(FileService.DirectoryName, UserData.DirectoryManager.Folder(video.Playlist).Create().DirectoryPath);
                intent.PutExtra(FileService.FileName, video.GenerateLocalPath(videos.FirstOrDefault()));

                if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
                {
                    _context.StartForegroundService(intent);
                }
                else
                {
                    _context.StartService(intent);
                }
            }
        }
Пример #6
0
        public async Task <SearchResult> DataBind()
        {
            var l = await this.StartLoading();

            _videos = ControllerRepository.Y(x => x.SearchAsync(UserData.CurrentUser.EntityId.Value, _searchfor, 20, 1, null, _videoSearchType)).Await();
            if (_videoSearchType == VideoSearchType.Album)
            {
                stVideoContainer.SourceItems = _videos.Albums;
            }
            else if (_videoSearchType == VideoSearchType.PlayList)
            {
                stVideoContainer.SourceItems = _videos.Playlists;
            }
            else
            {
                stVideoContainer.SourceItems = _videos.Videos;
            }
            l.EndLoading();
            return(this);
        }
Пример #7
0
        public async void DataBind()
        {
            var loader = await this.StartLoading();

            try
            {
                _category = _category ?? UserData.VideoCategoryViews.Find(x => x.EntityId == _category_Id)
                ;

                _videos = _videos ?? ControllerRepository.Db(x => x.GetVideoData(null, _category_Id, null, 1)).Await();

                var directoryManager = UserData.DirectoryManager.Folder(_category.Name).Create();

                _category.Videos = new List <VideoData>();
                if (!_localVideos.Any())
                {
                    var files = directoryManager.GetFiles();
                    _category.Videos = new List <VideoData>();
                    _localVideos     = files.Any()
                        ? files.Select(x => Methods.ParseLocalVideoPath(x.Name)).GroupBy(x => x.VideoId)
                                       .Select(x => x.FirstOrDefault()).Where(x => x != null && !string.IsNullOrEmpty(x.VideoId))
                                       .ToDictionary(x => x.VideoId, x => x)
                        : new Dictionary <string, YFileDownloadItem>();

                    foreach (var value in _localVideos.Values)
                    {
                        if (string.IsNullOrEmpty(value.VideoId))
                        {
                            continue;
                        }
                        var video = _videos.FirstOrDefault(x => x.Video_Id == value.VideoId) ?? ControllerRepository.Db(x => x.GetVideoData(value.VideoId, _category.EntityId, null, 1)).Await().FirstOrDefault();
                        if (video == null)
                        {
                            var videoInfo = ControllerRepository.Y(x => x.GetVideoAsync(value.VideoId, 18)).Await()?.FirstOrDefault();
                            _category.Videos.Add(new VideoData
                            {
                                Title       = value.Title.Substring(0, value.Title.IndexOf("[")),
                                Video_Id    = value.VideoId,
                                ThumpUrl    = $"https://img.youtube.com/vi/{value.VideoId}/0.jpg",
                                Auther      = videoInfo?.Auther,
                                Description = videoInfo?.Description,
                                Duration    = videoInfo?.Duration,
                                Quality     = videoInfo?.Quality,
                                Resolution  = videoInfo.Resolution
                            });
                        }
                    }

                    if (_category.Videos.Any())
                    {
                        UserData.SaveCategory(_category);
                        return;
                    }
                }

                foreach (var v in _videos)
                {
                    if (!_localVideos.ContainsKey(v.Video_Id) || string.IsNullOrEmpty(_localVideos[v.Video_Id].Title))
                    {
                        v.Playable = false;
                    }
                    else
                    {
                        v.LocalPath = new Uri(Path.Combine(_localPath, _category.Name, _localVideos[v.Video_Id].Title)).AbsoluteUri;
                    }
                }



                if (lVideo.State != PlayerState.Playing)
                {
                    try
                    {
                        Play();
                    }
                    catch
                    {
                        // Ignore
                    }
                }

                SetSource();
            }
            catch (Exception e)
            {
                Methods.AppSettings.Logger?.Error(e);
            }
            finally
            {
                loader.EndLoading();
                //Device.BeginInvokeOnMainThread(() => { Methods.ClearLoader(); });
            }
        }