Example #1
0
        private async void AddNewAlbum()
        {
            var album = new VkPlaylist()
            {
                Title = "New album"
            };

            var flyout = new FlyoutControl();

            flyout.FlyoutContent = new EditAlbumView(album);
            var result = await flyout.ShowAsync();

            if ((bool)result)
            {
                try
                {
                    var newAlbumId = await ViewModelLocator.Vkontakte.Audio.AddAlbum(album.Title);

                    if (newAlbumId != 0)
                    {
                        album.Id      = newAlbumId;
                        album.OwnerId = ViewModelLocator.Vkontakte.AccessToken.UserId;
                        Albums.Insert(5, album);
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            }
        }
Example #2
0
        public PlaylistVk(VkPlaylist playlist)
        {
            Id          = playlist.Id.ToString();
            OwnerId     = playlist.OwnerId.ToString();
            Title       = playlist.Title;
            TracksCount = playlist.Count;
            IsEditable  = playlist.Original == null && IsAddedByCurrentUser;
            AccessKey   = playlist.AccessKey;
            Description = playlist.Description;
            IsFollowing = playlist.IsFollowing;

            if (playlist.Photo != null)
            {
                Image = playlist.Photo?.Photo135;
            }
            else if (playlist.Thumbs?.Count > 0)
            {
                var thumb = playlist.Thumbs.FirstOrDefault();
                Image = thumb.Photo135;
            }

            if (!playlist.Artists.IsNullOrEmpty())
            {
                Artist = playlist.Artists.First().Name;
            }
        }
Example #3
0
        public EditAlbumView(VkPlaylist album)
        {
            InitializeComponent();

            _album = album;

            TitleTextBox.Text = _album.Title;

            if (album.Id != 0)
            {
                Title.Text = MainResources.EditAlbumTitle;
            }
        }
Example #4
0
        private async Task LoadAlbums()
        {
            OnTaskStarted("albums");

            try
            {
                var response = await DataService.GetUserAlbums(SelectedFriend.Id, 0, 0);

                var albums = response.Items;

                _totalAlbumsCount = response.TotalCount;

                if (albums == null)
                {
                    albums = new List <VkPlaylist>();
                }

                albums.Insert(0, new VkPlaylist()
                {
                    Id = -1, Title = MainResources.MyMusicAllTracks
                });
                albums.Insert(1, new VkPlaylist()
                {
                    Id = -101, Title = MainResources.MyMusicWall
                });
                albums.Insert(2, new VkPlaylist()
                {
                    Id = int.MinValue
                });                                                       //separator

                Albums = new ObservableCollection <VkPlaylist>(albums);

                SelectedAlbum = albums.First();
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);

                OnTaskError("albums", ErrorResources.LoadAudiosErrorCommon);
            }

            OnTaskFinished("albums");
        }
Example #5
0
        private async void EditAlbum(VkPlaylist album)
        {
            var flyout = new FlyoutControl();

            flyout.FlyoutContent = new EditAlbumView(album);

            var result = await flyout.ShowAsync();

            if (result != null && (bool)result)
            {
                try
                {
                    if (await ViewModelLocator.Vkontakte.Audio.EditAlbum(album.Id.ToString(), album.Title))
                    {
                        Albums[Albums.IndexOf(album)].Title = album.Title;
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            }
        }
Example #6
0
        private async void Save()
        {
            var album = new VkPlaylist()
            {
                Title = _album.Artist + " - " + _album.Name
            };

            var flyout = new FlyoutControl();

            flyout.FlyoutContent = new EditAlbumView(album);
            var result = await flyout.ShowAsync();

            if ((bool)result)
            {
                try
                {
                    Debug.WriteLine("Creating new album...");


                    NotificationService.NotifyProgressStarted(MainResources.NotificationSaving);

                    var newAlbumId = await ViewModelLocator.Vkontakte.Audio.AddAlbum(album.Title);

                    Debug.WriteLine("Album created. Id: " + newAlbumId);
                    Debug.WriteLine("Gettings audios...");

                    var progress = new Progress <int>(p => NotificationService.NotifyProgressChanged((int)(p / 2.0f)));

                    var audios = await GetAudioList(progress);

                    Debug.WriteLine("Got audios. Count: " + audios.Count);
                    Debug.WriteLine("Saving audios.");

                    int requestsCount = 0;
                    var audioIds      = new List <long>();

                    bool   captchaNeeded = false;
                    string captchaImg    = string.Empty;
                    string captchaSid    = string.Empty;
                    string captchaKey    = string.Empty;

                    int progressStep = (int)(100.0f / (audios.Count + 1));

                    for (var i = audios.Count - 1; i > 0; i--)
                    {
                        var vkAudio = audios[i];

                        try
                        {
                            var newAudioId = await ViewModelLocator.Vkontakte.Audio.Add(long.Parse(vkAudio.Id), vkAudio.OwnerId, captchaSid : captchaSid, captchaKey : captchaKey);

                            if (newAudioId != 0)
                            {
                                audioIds.Add(newAudioId);

                                captchaNeeded = false;
                                captchaKey    = null;
                                captchaSid    = null;
                            }
                        }
                        catch (VkCaptchaNeededException ex)
                        {
                            captchaNeeded = true;
                            captchaImg    = ex.CaptchaImg;
                            captchaSid    = ex.CaptchaSid;
                        }

                        if (captchaNeeded)
                        {
                            flyout = new FlyoutControl();
                            flyout.FlyoutContent = new CaptchaRequestView(captchaSid, captchaImg);
                            result = await flyout.ShowAsync();

                            if (!string.IsNullOrEmpty((string)result))
                            {
                                captchaKey = (string)result;
                                i          = i - 1;
                                continue;
                            }
                            else
                            {
                                NotificationService.NotifyProgressFinished();
                                return;
                            }
                        }

                        NotificationService.NotifyProgressChanged((int)(progressStep / 2.0f));

                        requestsCount++;

                        if (requestsCount >= 2) //не больше 2-х запросов в секунду
                        {
                            requestsCount = 0;
                            await Task.Delay(1000);
                        }
                    }

                    Debug.WriteLine("Audios saved. Moving to album...");

                    if (audioIds.Count > 0)
                    {
                        if (await ViewModelLocator.Vkontakte.Audio.MoveToAlbum(newAlbumId, audioIds))
                        {
                            Debug.WriteLine("Album saved!");

                            NotificationService.NotifyProgressFinished(MainResources.NotificationSaved);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            }
        }