Пример #1
0
 /// <summary>
 /// Load Application Settings from the db
 /// </summary>
 /// <param name="mainActivity"></param>
 public static void LoadApplicationSettings(IMainActivity mainActivity)
 {
     mainActivity.YDeveloperKey     = ControllerRepository.Db(x => x.GetSetting("YoutubeDeveloperKey")).Value;
     mainActivity.AdsApplicationIds = ControllerRepository.Db(x => x.GetSetting("AdsApplicationIds")).Value;
     mainActivity.BannerAdd         = ControllerRepository.Db(x => x.GetSetting("BannerAdd")).Value;
     mainActivity.RewardAddId       = ControllerRepository.Db(x => x.GetSetting("RewardAddId")).Value;
 }
Пример #2
0
        public static async Task SaveUserChanges()
        {
            MethodInformation info = null;

            CurrentUser = ControllerRepository.Db(x => x.SaveUser(CurrentUser), (u, i) => { info = u; });
            await info?.ExecuteTrigger();
        }
Пример #3
0
        /// <summary>
        /// Reward the user after watching an ads
        /// </summary>
        public static void Reward()
        {
            var amount = decimal.Parse(ControllerRepository.Db(x => x.GetSetting("VideoRewardAmount")).Value);

            UserData.CurrentUser.DownloadCoins += amount;
            UserData.SaveUserChanges();
        }
Пример #4
0
        public static async Task DownloadCompleted(string fullPath)
        {
            var data = ParseLocalVideoPath(fullPath);

            if (data != null)
            {
                data = ObjectCacher.DownloadingFiles.ContainsKey(data.VideoId)
                    ? ObjectCacher.DownloadingFiles[data.VideoId]
                    : data;
                if (ObjectCacher.DownloadingFiles.ContainsKey(data.VideoId))
                {
                    ObjectCacher.DownloadingFiles.Remove(data.VideoId);
                }
                var category = ControllerRepository.Db(x => x.GetVideoCategory(UserData.CurrentUser.EntityId.Value, data.category_Id)).FirstOrDefault();
                if (category != null)
                {
                    category.Videos = new List <VideoData>();
                    category.Videos.Add(new VideoData
                    {
                        Video_Id    = data.VideoId,
                        Title       = data.Title,
                        ThumpUrl    = data.ThumpUrl,
                        Quality     = data.Quality,
                        Duration    = data.Duration,
                        Description = data.Description,
                        Auther      = data.Auther,
                        Resolution  = data.Resolution
                    });
                    /// Save the changes to DownloadCoins, that has been made in FileService
                    await UserData.SaveUserChanges();

                    await UserData.SaveCategory(category);
                }
            }
        }
Пример #5
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();
        }
Пример #6
0
        private void _btnDislike_Clicked(object sender, EventArgs e)
        {
            var item = (sender as ImageButton).BindingContext as VideoCategoryView;

            ControllerRepository.Db(x => x.Vote(VideoSearchType.PlayList, Ratingtype.Down, item.EntityId.Value, UserData.CurrentUser.EntityId.Value)).Await();
            DataBinder();
        }
Пример #7
0
 /// <summary>
 /// Reload/Load the userData
 /// </summary>
 /// <returns></returns>
 public static void LoadUserData(bool forceReload = true)
 {
     if (CurrentUser == null)
     {
         return;
     }
     if (forceReload)
     {
         VideoCategoryViews = CurrentUser?.EntityId.HasValue ?? false?ControllerRepository.Db(x => x.GetVideoCategory(CurrentUser.EntityId, null)) : new List <VideoCategoryView>();
     }
 }
Пример #8
0
        private void PlayListSuggesting_SelectedItemChanged(object sender, EventArgs e)
        {
            var category      = playListSuggesting.SelectedItem as VideoCategoryView;
            var videos        = ControllerRepository.Db(x => x.GetVideoData(null, category.EntityId, null, 1)).Await();
            var videoWrappers = videos?.Select(x => new VideoWrapper(x)).ToList();
            var playList      = new VideoWrapper()
            {
                Title = videoWrappers.First().Title, Videos = videoWrappers, IsVideo = false, IsPlaylist = true
            };

            new Video(playList, videoWrappers).LoadData().Open();
            playListSuggesting.SelectedItem = null;
        }
Пример #9
0
        /// <summary>
        ///     Save VideoCategory
        /// </summary>
        /// <param name="videoCategories"></param>
        public static async Task <long> SaveCategory(VideoCategory videoCategory)
        {
            MethodInformation info = null;

            if (videoCategory.State == State.Removed)
            {
                UserData.DirectoryManager.Folder(videoCategory.Name).Delete();
            }
            var id = ControllerRepository.Db(x => x.SaveCategory(videoCategory), (i, x) => info = i).Await();

            LoadUserData(true);
            await info.ExecuteTrigger();

            return(await Task.FromResult(id));
        }
Пример #10
0
        /// <summary>
        ///     Prepare a downloadable object
        /// </summary>
        /// <param name="ytubeItem"></param>
        /// <param name="videoCategory"></param>
        /// <returns></returns>
        public static YFileDownloadItem GetDownloadableItem(this VideoData ytubeItem)
        {
            var videoCategory = ControllerRepository.Db(x => x.GetVideoCategory(UserData.CurrentUser.EntityId, ytubeItem.Category_Id)).FirstOrDefault();

            if (ytubeItem.Video_Id.ToLower().Contains("youtube"))
            {
                ytubeItem.Video_Id = ytubeItem.Video_Id.Split('=').Last();
            }
            var v = new YFileDownloadItem();

            v.Playlist    = videoCategory?.Name;
            v.VideoId     = ytubeItem.Video_Id;
            v.Title       = ytubeItem.Title;
            v.category_Id = videoCategory?.EntityId;
            v.ThumpUrl    = ytubeItem.ThumpUrl;
            return(v);
        }
Пример #11
0
 public static async void SaveVideo(params VideoData[] videos)
 {
     foreach (var v in videos)
     {
         ControllerRepository.Db(x => x.SaveVideo(v)).Await();
         if (v.State == State.Removed)
         {
             var cat = ControllerRepository.Db(x => x.GetVideoCategory(null, v.Category_Id)).FirstOrDefault();
             var directoryManager = UserData.DirectoryManager.Folder(cat.Name).Create();
             foreach (var file in directoryManager.GetFiles(System.IO.SearchOption.TopDirectoryOnly, v.Video_Id))
             {
                 file.File.Delete();
             }
         }
     }
     UserData.LoadUserData(true);
     await ControllerRepository.GetInfo <IDbController, Task>((x) => x.SaveVideo(null)).ExecuteTrigger();
 }
Пример #12
0
 public async Task <List <AppBillingProduct> > GetProducts()
 {
     try
     {
         var products = ControllerRepository.Db(x => x.GetProductLinks(null));
         if (!products.Any() || !await CanPurchase())
         {
             return(new List <AppBillingProduct>());
         }
         var items = (await CrossInAppBilling.Current.GetProductInfoAsync(ItemType.InAppPurchase, products.Select(x => x.Product_Id).ToArray())).Where(x => products.Any(a => a.Product_Id == x.ProductId)).ToList().Astype <List <AppBillingProduct> >();
         items.ForEach(x => x.CoinsAmount = products.Find(a => a.Product_Id == x.ProductId).CoinsAmount);
         return(items);
     }
     catch (Exception e)
     {
         Logger?.Error(e.Message, LogLevel.Debug);
         return(new List <AppBillingProduct>());
     }
 }
Пример #13
0
        public static async Task LogIn(string email, string password = null, string imageUrl = "")
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                password = "******";
            }
            DirectoryManager = null;
            MethodInformation info = null;

            ControllerRepository.Db(x => x.LogIn(email, imageUrl, password), (x, data) => { CurrentUser = data; info = x; });
            if (CurrentUser != null)
            {
                Methods.AppSettings.UserLocalSettings.UserName = CurrentUser.Email;
                Methods.AppSettings.UserLocalSettings.Password = CurrentUser.Password;
                Methods.AppSettings.UserLocalSettings.Image    = CurrentUser.Picture;
                Methods.AppSettings.Logger.CurrentUserEmail    = CurrentUser.Email;
            }


            LoadUserData(true);
            await info.ExecuteTrigger();
        }
Пример #14
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(); });
            }
        }