Beispiel #1
0
        public async void Remove(string key)
        {
            storage.Remove(key);

            IStorageItem toDelete = await folder.GetItemAsync(key + ".json");

            await toDelete.DeleteAsync(StorageDeleteOption.Default);
        }
Beispiel #2
0
        public static async void DeleteAsync(string name)
        {
            StorageFolder saveLocation = await ApplicationData.Current.LocalFolder.CreateFolderAsync("SavedMaps", CreationCollisionOption.OpenIfExists);

            IStorageItem folder = await saveLocation.TryGetItemAsync(name);

            if (folder != null)
            {
                await folder.DeleteAsync();
            }
        }
        public static async Task <SafeWrapperResult> DeleteItem(IStorageItem item, bool permanently = false)
        {
            if (item == null)
            {
                return(new SafeWrapperResult(OperationErrorCode.InvalidArgument, new ArgumentNullException(), "The provided storage item is null."));
            }

            SafeWrapperResult result = await SafeWrapperRoutines.SafeWrapAsync(
                () => item.DeleteAsync(permanently ? StorageDeleteOption.PermanentDelete : StorageDeleteOption.Default).AsTask());

            return(result);
        }
        internal async Task DeleteCacheFileAsync(string id, string fileExtension)
        {
            var fileName = id + fileExtension;

            IStorageItem file = null;

            file = await localCacheFolder.TryGetItemAsync(fileName);

            if (file != null)
            {
                await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }
        }
Beispiel #5
0
        public static async Task <bool> TryDeleteItemAsync(this IStorageItem item)
        {
            try
            {
                await item.DeleteAsync(StorageDeleteOption.PermanentDelete);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #6
0
        public async Task <bool> DeleteFile(string fileName)
        {
            StorageFolder folder = ApplicationData.Current.LocalFolder;
            IStorageItem  f      = await folder.TryGetItemAsync(fileName);

            if (f != null)
            {
                await f.DeleteAsync(StorageDeleteOption.PermanentDelete);

                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Check if NoArchive folder exists. Return storageFolderNoArchive if found or created successfully, null otherwise.
        /// Output messages are written to public MainPage variable stringFolderCheckOutput if needed.
        /// User can delete NoArchive folder at any time so may need to check if exists.
        /// </summary>
        /// <returns></returns>
        public async Task <StorageFolder> FolderCheckNoArchiveAsync()
        {
            try
            {
                List <string> list_stringFolderCheckOutput = new List <string>();
                StorageFolder storageFolderNoArchive       = null;
                // Debug.WriteLine($"MainPage.FolderCheckNoArchiveAsync(): storageFolderLocker.Path={storageFolderLocker.Path}");
                IStorageItem iStorageItem = await storageFolderLocker.TryGetItemAsync(stringFoldernameNoArchive);

                if (iStorageItem != null)   // Item found but don't know if it was folder or file.
                {
                    if (iStorageItem.IsOfType(StorageItemTypes.Folder))
                    {
                        storageFolderNoArchive = (StorageFolder)iStorageItem;     // Found folder.
                    }
                    else
                    {
                        // Item found was not a folder as expected but is using App reserved name.
                        // Delete item to Recycle Bin to be safe and create NoArchive folder.
                        await iStorageItem.DeleteAsync();

                        storageFolderNoArchive = await storageFolderLocker.CreateFolderAsync(stringFoldernameNoArchive);
                    }
                }
                else    // iStorageItem is null, so create NoArchive folder.
                {
                    storageFolderNoArchive = await storageFolderLocker.CreateFolderAsync(stringFoldernameNoArchive);
                }
                if (storageFolderNoArchive != null)
                {
                    list_stringFolderCheckOutput.Add(resourceLoader.GetString("MP_Success_FolderCheck_NoArchive"));     // Found or created folder
                }
                else
                {
                    list_stringFolderCheckOutput.Add(resourceLoader.GetString("MP_Error_FolderCheck_NoArchive"));       // Could not find or create folder
                }
                list_stringFolderCheckOutput.Add(storageFolderNoArchive.Name);
                stringFolderCheckOutput = LibMPC.JoinListString(list_stringFolderCheckOutput, EnumStringSeparator.OneSpace);
                // Debug.WriteLine($"MainPage.FolderCheckNoArchiveAsync(): stringFolderCheckOutput={stringFolderCheckOutput}");
                // Debug.WriteLine($"MainPage.FolderCheckNoArchiveAsync(): storageFolderNoArchive.Path={storageFolderNoArchive.Path}");
                // throw new ArgumentException("Throw exception to test exception methods. Comment this out when satisfied all is working.");
                return(storageFolderNoArchive);    // Is null on error.
            }
            catch (Exception ex)
            {
                stringFolderCheckOutput = UnhandledExceptionMessage("MainPage.FolderCheckNoArchiveAsync()", ex.GetType());
                return(null);

                throw;
            }
        }
Beispiel #8
0
        /// <summary>
        /// Exports all logs as a .zip file to the selected path.
        /// </summary>
        public static async Task ExportLogsAsync()
        {
            // Get the target path/file:
            StorageFile targetFile = await GetTargetPathAsync();

            if (targetFile is null)
            {
                Info("Exporting logs canceled.");
                return;
            }
            Info("Started exporting logs to: " + targetFile.Path);

            // Delete existing log export zip files:
            IStorageItem zipItem = await ApplicationData.Current.LocalFolder.TryGetItemAsync("LogsExport.zip");

            if (zipItem != null)
            {
                await zipItem.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }

            StorageFolder logsFolder = await GetLogFolderAsync();

            ZipFile.CreateFromDirectory(logsFolder.Path, GetExportedLogsPath(), CompressionLevel.Fastest, true);

            try
            {
                zipItem = await ApplicationData.Current.LocalFolder.TryGetItemAsync("LogsExport.zip");

                if (zipItem is null)
                {
                    Error("Failed to export logs - zipItem is null");
                }
                else if (zipItem is StorageFile zipFile)
                {
                    await zipFile.MoveAndReplaceAsync(targetFile);

                    Info("Exported logs successfully to:" + targetFile.Path);
                }
                else
                {
                    Error("Failed to export logs - zipItem is no StorageFile");
                }
            }
            catch (Exception e)
            {
                Error("Error during exporting logs", e);
            }
        }
Beispiel #9
0
        //Delete a file
        public async Task <bool> FileDelete(string FileName)
        {
            try
            {
                IStorageItem IStorageItem = await ApplicationData.Current.LocalFolder.GetItemAsync(FileName);

                await IStorageItem.DeleteAsync(StorageDeleteOption.PermanentDelete);

                return(true);
            }
            catch
            {
                Debug.WriteLine("Could not delete a local file: " + FileName);
                return(false);
            }
        }
Beispiel #10
0
        public async Task DeleteFileDataAsync(Guid fileDataId)
        {
            string fileName = fileDataId.ToString();

            IStorageItem file = await _localUserDataFolder.TryGetItemAsync(fileName);

            if (file != null)
            {
                await CoreHelper.RetryAsync(async() =>
                {
                    await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
                }).ConfigureAwait(false);
            }

            _logger.LogEvent(DeleteFileEvent, string.Empty);
        }
        public override async Task ResetSettingsAsync()
        {
            try
            {
                IStorageItem storageItem = await ApplicationData.Current.LocalCacheFolder.TryGetItemAsync(_xmlFilePath);

                if (storageItem != null)
                {
                    await storageItem.DeleteAsync(StorageDeleteOption.Default);
                }
            }
            catch (Exception e)
            {
                _loggerService.LogException(e);
            }
        }
Beispiel #12
0
        static public async Task <bool> DeleteFeed(string FeedId)
        {
            try
            {
                string[][]          RequestHeader = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppVariables.ApplicationSettings["ConnectApiAuth"].ToString() } };
                HttpStringContent   PostContent   = new HttpStringContent("ac=unsubscribe&s=feed/" + FeedId, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/x-www-form-urlencoded");
                HttpResponseMessage PostHttp      = await AVDownloader.SendPostRequestAsync(7500, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/edit"), PostContent);

                if (PostHttp != null && (PostHttp.Content.ToString() == "OK" || PostHttp.Content.ToString().Contains("<error>Not found</error>")))
                {
                    //Wait for busy database
                    await ApiUpdate.WaitForBusyDatabase();

                    //Clear feed from database
                    await SQLConnection.ExecuteAsync("DELETE FROM TableFeeds WHERE feed_id = ('" + FeedId + "')");

                    //Clear items from database
                    await SQLConnection.ExecuteAsync("DELETE FROM TableItems WHERE item_feed_id = ('" + FeedId + "') AND item_star_status = ('0')");

                    //Delete the feed icon
                    IStorageItem LocalFile = await ApplicationData.Current.LocalFolder.TryGetItemAsync(FeedId + ".png");

                    if (LocalFile != null)
                    {
                        try { await LocalFile.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch { }
                    }

                    Debug.WriteLine("Deleted the feed and items off: " + FeedId);
                    return(true);
                }
                else
                {
                    Debug.WriteLine("Failed to delete feed: " + FeedId + " / server error.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to delete feed: " + FeedId + " / " + ex.Message);
                return(false);
            }
        }
Beispiel #13
0
        public static async Task HousekeepExtractedFramesFolder()
        {
            try
            {
                string        ExtractedFrameFolderPath = APPConfig.instance.getConfigProperties("ExtractedFramesFolder");
                String        outputDrivePath          = APPConfig.instance.getConfigProperties("Drive");
                StorageFolder outputDrive = await StorageFolder.GetFolderFromPathAsync(outputDrivePath);

                if (await outputDrive.TryGetItemAsync(ExtractedFrameFolderPath) != null)
                {
                    IStorageItem ExtractedFramesFolder = await outputDrive.GetItemAsync(ExtractedFrameFolderPath);

                    await ExtractedFramesFolder.DeleteAsync(StorageDeleteOption.PermanentDelete);
                }
            }
            catch (Exception ex)
            {
                UIOperations.ShowContentDialog("Housekeep Folder Error", "Please go to Settings > Privacy > File system and enable the file access right of DTP." + Environment.NewLine + ex.ToString());
            }
        }
Beispiel #14
0
        /// <summary>
        /// Exports all logs as a .zip file to the selected path.
        /// </summary>
        /// <returns>An async Task.</returns>
        public static async Task exportLogs()
        {
            StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync("Logs");

            if (folder != null)
            {
                StorageFile target = await getTargetPathAsync();

                if (target == null)
                {
                    return;
                }
                await Task.Run(async() =>
                {
                    try
                    {
                        IStorageItem file = await ApplicationData.Current.LocalFolder.TryGetItemAsync("Logs.zip");
                        if (file != null)
                        {
                            await file.DeleteAsync();
                        }
                        ZipFile.CreateFromDirectory(folder.Path, ApplicationData.Current.LocalFolder.Path + @"\Logs.zip", CompressionLevel.Optimal, false);
                        file = await ApplicationData.Current.LocalFolder.GetFileAsync("Logs.zip");
                        if (file != null && file is StorageFile)
                        {
                            StorageFile f = file as StorageFile;
                            await f.CopyAndReplaceAsync(target);
                        }
                        Info("Exported logs successfully to:" + target.Path);
                    }
                    catch (Exception e)
                    {
                        Error("Error during exporting logs", e);
                    }
                });
            }
        }
Beispiel #15
0
        } //Achievementtien saavutus tarkistetaan jokaisen rahanlisäyksen jälkeen

        public async void saveButton_Click(object sender, RoutedEventArgs e)
        {
            // folder
            StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
            // delete file if exists
            IStorageItem employeesItem = await storageFolder.TryGetItemAsync("friends.dat");

            if (await storageFolder.TryGetItemAsync("friends.dat") != null)
            {
                await employeesItem.DeleteAsync();
            }

            StorageFile employeesFile = await storageFolder.CreateFileAsync("friends.dat", CreationCollisionOption.OpenIfExists);

            // save friends to disk
            Stream stream = await employeesFile.OpenStreamForWriteAsync();

            DataContractSerializer serializer = new DataContractSerializer(typeof(List <Opettaja>));

            serializer.WriteObject(stream, opettajat);
            await stream.FlushAsync();

            stream.Dispose();
        }//Tallennus, syistä tuntemattomista ei toimi niinkuin pitäisi
Beispiel #16
0
 public static async void DeletItem(IStorageItem item)
 {
     await item.DeleteAsync();
 }
        public async Task <bool> DeleteItem(IStorageItem item, StorageDeleteOption deletionOption)
        {
            await item.DeleteAsync(deletionOption);

            return(true);
        }
Beispiel #18
0
 public static async Task DeleteStorageItemAsync(IStorageItem storageItem)
 {
     await storageItem.DeleteAsync(StorageDeleteOption.PermanentDelete);
 }
 public static void Delete(this IStorageItem storageItem, IProgress progress = null) => storageItem.DeleteAsync(progress).GetAwaiter().GetResult();
Beispiel #20
0
 /// <summary>
 /// Deletes the specified item. This may be called if an operation has been canceled.
 /// </summary>
 /// <param name="item">The item to be deleted.</param>
 public static async void Delete(IStorageItem item)
 {
     await item.DeleteAsync();
 }
Beispiel #21
0
        private async void LoadAsync()
        {
            // First run experience
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            if (localSettings.Values.ContainsKey("FirstRun"))
            {
                IsFirstRun = false;
            }

            // Load server settings
            IStorageItem file = await ApplicationData.Current.LocalFolder.TryGetItemAsync("settings.json");

            if (file != null)
            {
                try
                {
                    using (Stream inStream = await((StorageFile)file).OpenStreamForReadAsync())
                    {
                        DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(RedmineSettings));
                        Client.Settings = json.ReadObject(inStream) as RedmineSettings;
                    }

                    if (Client.Settings != null)
                    {
                        // Load credentials
                        PasswordVault vault = new PasswordVault();

                        if (string.IsNullOrEmpty(Client.Settings.Username))
                        {
                            PasswordCredential apiKey = vault.Retrieve("Redmine", "ApiKey");
                            Client.Settings.ApiKey = apiKey.Password;
                        }
                        else
                        {
                            PasswordCredential account = vault.Retrieve("Redmine", Client.Settings.Username);
                            Client.Settings.Password = account.Password;
                        }
                    }
                }
                catch
                {
                    // TODO: Feedback
                }

                // Load server data
                if (Client.Settings != null)
                {
                    DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings()
                    {
                        UseSimpleDictionaryFormat = true
                    };
                    IEnumerable <PropertyInfo> props = Client.GetType().GetProperties().Where(prop => prop.IsDefined(typeof(DataMemberAttribute), false));
                    foreach (PropertyInfo pi in props)
                    {
                        file = await ApplicationData.Current.LocalFolder.TryGetItemAsync($"{pi.Name}.json");

                        if (file != null)
                        {
                            try
                            {
                                using (Stream inStream = await((StorageFile)file).OpenStreamForReadAsync())
                                {
                                    DataContractJsonSerializer json = new DataContractJsonSerializer(pi.PropertyType, settings);
                                    pi.SetValue(Client, json.ReadObject(inStream));
                                }
                            }
                            catch
                            {
                                // TODO: Add logging

                                // Corrupted file, remove it
                                await file.DeleteAsync();
                            }
                        }
                    }
                }
            }
        }
Beispiel #22
0
        public static void ShowPopupMenu(this Page page, object mediaItem, object sender, Point point, MediaItemType type)
        {
            currentPage = page;
            MenuFlyout menu = new MenuFlyout()
            {
                MenuFlyoutPresenterStyle = Application.Current.Resources["MenuFlyoutModernStyle"] as Style,
            };

            // SE O MENU FOR DO TIPO SONG
            if (type == MediaItemType.Song)
            {
                Song song = mediaItem as Song;

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(songs));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(songs);
                    }
                };

                menu.Items.Add(item3);


                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs, true));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(song, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);

                //MenuFlyoutItem item6 = new MenuFlyoutItem()
                //{
                //    Text = "Editar",
                //    Tag = "",
                //    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                //};
                //item6.Click += (s, a) =>
                //{
                //    PageHelper.MainPage.PageFrame.Navigate(typeof(TagEditor), song);
                //};

                //menu.Items.Add(item6);
            }
            // SE O MENU FOR DO TIPO ALBUM
            else if (type == MediaItemType.Album)
            {
                Album         album = mediaItem as Album;
                List <Song>   songs = CollectionHelper.GetSongsByAlbumID(album.AlbumID);
                List <string> list  = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(album, type) == false)
                    {
                        MessageDialog md = new MessageDialog("Não foi possível compartilhar este item");
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            // SE O MENU FOR DO TIPO ARTIST
            else if (type == MediaItemType.Artist)
            {
                Artist        artist = mediaItem as Artist;
                List <Song>   songs  = CollectionHelper.GetSongsByArtist(artist.Name);
                List <string> list   = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(artist, type) == false)
                    {
                        MessageDialog md = new MessageDialog("Não foi possível compartilhar este item");
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            // SE O MENU FOR DO TIPO PLAYLIST
            else if (type == MediaItemType.Playlist)
            {
                Playlist playlist = mediaItem as Playlist;

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(playlist.Songs));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item2);


                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs, true));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item3);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(playlist, type) == false)
                    {
                        MessageDialog md = new MessageDialog("Não foi possível compartilhar este item");
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Delete"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessage"), ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessageTitle"));
                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("Yes"), async(t) =>
                    {
                        StorageFolder playlistsFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Playlists", CreationCollisionOption.OpenIfExists);

                        IStorageItem playlistItem = await playlistsFolder.TryGetItemAsync(playlist.PlaylistFileName);

                        if (playlistItem != null)
                        {
                            try
                            {
                                await playlistItem.DeleteAsync(StorageDeleteOption.PermanentDelete);

                                if (PageHelper.PlaylistPage != null)
                                {
                                    if (PageHelper.MainPage != null)
                                    {
                                        PageHelper.MainPage.GoBack();
                                    }
                                }
                                else if (PageHelper.Playlists != null)
                                {
                                    PageHelper.Playlists.LoadPlaylists();
                                }
                            }
                            catch
                            {
                            }
                        }
                    }));

                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("No")));

                    md.CancelCommandIndex  = 1;
                    md.DefaultCommandIndex = 1;

                    await md.ShowAsync();
                };

                menu.Items.Add(item5);
            }

            try
            {
                menu.ShowAt(sender as FrameworkElement, point);
            }
            catch
            {
                menu.ShowAt(sender as FrameworkElement);
            }
        }
Beispiel #23
0
        //Update the feed icon
        private async void UpdateFeedIcon(object sender, RightTappedRoutedEventArgs e)
        {
            try
            {
                ListView SendListView = sender as ListView;
                Feeds    SelectedItem = (Feeds)SendListView.SelectedItem;
                if (SelectedItem != null)
                {
                    int MsgBoxResult = await new MessagePopup().OpenPopup("Change the feed icon", "Would you like to set a custom feed icon for " + SelectedItem.feed_title + "?", "Set custom icon", "Reset the icon", "", "", "", true);
                    if (MsgBoxResult == 1)
                    {
                        System.Diagnostics.Debug.WriteLine("Changing icon for feed: " + SelectedItem.feed_id + " / " + SelectedItem.feed_title);

                        FileOpenPicker FileOpenPicker = new FileOpenPicker();
                        FileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
                        FileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                        FileOpenPicker.FileTypeFilter.Add(".png");

                        //Save and replace feed icon locally
                        StorageFile StorageFile = await FileOpenPicker.PickSingleFileAsync();

                        if (StorageFile != null)
                        {
                            await StorageFile.CopyAndReplaceAsync(await ApplicationData.Current.LocalFolder.CreateFileAsync(SelectedItem.feed_id + ".png", CreationCollisionOption.ReplaceExisting));

                            //Load the feed icon
                            BitmapImage FeedIcon = null;
                            if (SelectedItem.feed_id.StartsWith("user/"))
                            {
                                FeedIcon = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconUser-Dark.png", false);
                            }
                            else
                            {
                                FeedIcon = await AVImage.LoadBitmapImage("ms-appdata:///local/" + SelectedItem.feed_id + ".png", false);
                            }
                            if (FeedIcon == null)
                            {
                                FeedIcon = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconRSS-Dark.png", false);
                            }

                            SelectedItem.feed_icon = FeedIcon;
                        }
                    }
                    else if (MsgBoxResult == 2)
                    {
                        //Delete the feed icon
                        IStorageItem LocalFile = await ApplicationData.Current.LocalFolder.TryGetItemAsync(SelectedItem.feed_id + ".png");

                        if (LocalFile != null)
                        {
                            try { await LocalFile.DeleteAsync(StorageDeleteOption.PermanentDelete); } catch { }
                        }

                        //Load default feed icon
                        SelectedItem.feed_icon = await AVImage.LoadBitmapImage("ms-appx:///Assets/iconRSS-Dark.png", false);

                        //Reset the online status
                        OnlineUpdateFeeds = true;
                        ApiMessageError   = string.Empty;

                        await new MessagePopup().OpenPopup("Feed icon reset", "The feed icon has been reset and will be refreshed on the next online feed update, you can refresh the feeds by clicking on the refresh icon above.", "Ok", "", "", "", "", false);
                    }
                }
            }
            catch { }
        }
        public static async void ShowPopupMenu(this FrameworkElement fwe, object mediaItem, object sender, Point point, MediaItemType type)
        {
            page = fwe;

            MenuFlyout menu = new MenuFlyout()
            {
                MenuFlyoutPresenterStyle = Application.Current.Resources["MenuFlyoutModernStyle"] as Style,
            };

            // SE O MENU FOR DO TIPO SONG
            if (type == MediaItemType.Song)
            {
                Song song = Ctr_Song.Current.GetSong(mediaItem as Song);

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(songs));
                };

                menu.Items.Add(item1);

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(songs);
                    }
                };

                menu.Items.Add(item3);


                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs, true));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(song, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);

                MenuFlyoutItem item6 = new MenuFlyoutItem()
                {
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };

                if (song.IsFavorite)
                {
                    item6.Text = ApplicationInfo.Current.Resources.GetString("RemoveFromFavoritesString");
                    item6.Tag  = "";
                }
                else
                {
                    item6.Text = ApplicationInfo.Current.Resources.GetString("AddToFavoritesString");
                    item6.Tag  = "";
                }

                item6.Click += (s, a) =>
                {
                    //remove favorite mark
                    if (song.IsFavorite)
                    {
                        Ctr_Song.Current.SetFavoriteState(song, false);
                    }
                    //add favorite mark
                    else
                    {
                        Ctr_Song.Current.SetFavoriteState(song, true);
                    }
                };

                menu.Items.Add(item6);

                MenuFlyoutItem item7 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("GoToArtistString"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item7.Click += (s, a) =>
                {
                    Artist artist = new Artist();
                    artist.Name = song.Artist;

                    PageHelper.MainPage?.Navigate(typeof(ArtistPage), artist);
                };

                menu.Items.Add(item7);

                MenuFlyoutItem item8 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("GoToAlbumString"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item8.Click += (s, a) =>
                {
                    Album album = new Album()
                    {
                        Name     = song.Album,
                        Artist   = song.Artist,
                        AlbumID  = song.AlbumID,
                        Year     = Convert.ToInt32(song.Year),
                        Genre    = song.Genre,
                        HexColor = song.HexColor
                    };

                    PageHelper.MainPage?.Navigate(typeof(AlbumPage), album);
                };

                menu.Items.Add(item8);

                //MenuFlyoutItem item6 = new MenuFlyoutItem()
                //{
                //    Text = "Editar",
                //    Tag = "",
                //    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                //};
                //item6.Click += (s, a) =>
                //{
                //    PageHelper.MainPage.PageFrame.Navigate(typeof(TagEditor), song);
                //};

                //menu.Items.Add(item6);
            }
            // SE O MENU FOR DO TIPO ALBUM
            else if (type == MediaItemType.Album)
            {
                Album         album = mediaItem as Album;
                List <Song>   songs = Ctr_Song.Current.GetSongsByAlbum(album);
                List <string> list  = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(album, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);

                MenuFlyoutItem item6 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("GoToArtistString"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item6.Click += (s, a) =>
                {
                    Artist artist = new Artist();
                    artist.Name = album.Artist;

                    PageHelper.MainPage?.Navigate(typeof(ArtistPage), artist);
                };

                menu.Items.Add(item6);
            }
            // SE O MENU FOR DO TIPO ARTIST
            else if (type == MediaItemType.Artist)
            {
                Artist        artist = mediaItem as Artist;
                List <Song>   songs  = Ctr_Song.Current.GetSongsByArtist(artist);
                List <string> list   = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(artist, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            //SE O MENU FOR DO TIPO FOLDER
            else if (type == MediaItemType.Folder)
            {
                List <string> list = new List <string>();

                FolderItem item = mediaItem as FolderItem;

                StorageFolder subFolder = await StorageFolder.GetFolderFromPathAsync(item.Path);

                var subFolderItems = await StorageHelper.ReadFolder(subFolder);

                foreach (StorageFile f in subFolderItems)
                {
                    if (StorageHelper.IsMusicFile(f.Path))
                    {
                        list.Add(f.Path);
                    }
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(item, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            // SE O MENU FOR DO TIPO PLAYLIST
            else if (type == MediaItemType.Playlist)
            {
                Playlist playlist = mediaItem as Playlist;

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(playlist.Songs));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item2);


                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs, true));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item3);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(playlist, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Delete"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessage"), ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessageTitle"));
                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("Yes"), async(t) =>
                    {
                        StorageFolder playlistsFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Playlists", CreationCollisionOption.OpenIfExists);

                        IStorageItem playlistItem = await playlistsFolder.TryGetItemAsync(playlist.PlaylistFileName);

                        if (playlistItem != null)
                        {
                            try
                            {
                                await playlistItem.DeleteAsync(StorageDeleteOption.PermanentDelete);

                                if (PageHelper.PlaylistPage != null)
                                {
                                    if (PageHelper.MainPage != null)
                                    {
                                        PageHelper.MainPage.GoBack();
                                    }
                                }
                                else if (PageHelper.Playlists != null)
                                {
                                    PageHelper.Playlists.LoadPlaylists();
                                }
                            }
                            catch
                            {
                            }
                        }
                    }));

                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("No")));

                    md.CancelCommandIndex  = 1;
                    md.DefaultCommandIndex = 1;

                    await md.ShowAsync();
                };

                menu.Items.Add(item5);
            }

            try
            {
                menu.ShowAt(sender as FrameworkElement, point);
            }
            catch
            {
                menu.ShowAt(sender as FrameworkElement);
            }
        }