SettingsElement CreateLanguagePicker(string title) { SettingsElement element = null; var currentCulture = string.IsNullOrWhiteSpace(Settings.LanguageOverride) ? Strings.Default : new CultureInfo(Settings.LanguageOverride).NativeName; element = new SettingsElement(title, () => { var sheet = new ActionSheet(title); sheet.Add(Strings.Default, () => { Settings.LanguageOverride = null; }); cultures.ForEach(x => sheet.Add(x.NativeName, () => { Strings.Culture = x; Settings.LanguageOverride = x.Name; element.Value = x.NativeName; })); sheet.Show(this, TableView); }) { style = UITableViewCellStyle.Value1, Value = currentCulture, }; return(element); }
public void ShowNowPlaying(UIView view) { var song = Database.Main.GetObject <Song, TempSong>(Settings.CurrentSong); if (string.IsNullOrWhiteSpace(song?.Id)) { return; } var controller = new ActionSheet(song.Name, song.DetailText); if (ShouldShowPlayVideoButton(song)) { controller.Add("Play Video", () => { PlaybackManager.Shared.PlayNow(song, true); }); } AddNavigateTo(controller, song); AddPlaylistButtons(controller, song); AddShuffleButton(controller, song); AddRadioStationButton(controller, song); AddToLibrary(controller, song); AddRemoveFromLibrary(controller, song); AddOfflineButtons(controller, song); controller.Add("Cancel", null, true); PresentController(controller, view); }
static void AddNavigateTo(ActionSheet controller, MediaItemBase item) { var song = item as Song; if (song == null) { return; } if (!string.IsNullOrWhiteSpace(song.AlbumId)) { controller.Add("Go to Album", () => { NotificationManager.Shared.ProcGoToAlbum(song.AlbumId); }); } controller.Add("Go to Artist", () => { NotificationManager.Shared.ProcGoToArtist(song.ArtistId); }); }
static void AddToLibrary(ActionSheet controller, MediaItemBase item) { if (!ShouldShowAddToLibrary(item)) { return; } controller.Add("Add to Library", async() => { var onlineSong = item as OnlineSong; if (onlineSong?.TrackData?.ServiceType == ServiceType.YouTube) { //Prompt for meta data var editor = new SongTagEditor { Song = onlineSong }; await GetCurrentViewController().PresentViewControllerAsync(new UINavigationController(editor), true); var s = await editor.GetValues(); if (!s) { return; } } var success = await MusicManager.Shared.AddToLibrary(item); if (!success) { App.ShowAlert("Error", "There was an error please try again"); } }); }
static void AddRadioStationButton(ActionSheet controller, MediaItemBase item) { //TODO check if we can add station to the item; if (!SouldShowStartRadio(item)) { return; } controller.Add("Start Radio Station", async() => { using (new Spinner("Creating Station")) { try { var station = await MusicManager.Shared.CreateRadioStation(item); if (station != null) { PlaybackManager.Shared.Play(station); } else { App.ShowAlert("Error", "There was an error creating the radio station"); } } catch (Exception ex) { LogManager.Shared.Report(ex); } } }); }
static void AddOfflineButtons(ActionSheet controller, MediaItemBase item) { if (item is RadioStation) { return; } var song = item as Song; if (song != null) { bool canOffline = false; foreach (var serviceType in song.ServiceTypes) { switch (serviceType) { case ServiceType.iPod: case ServiceType.FileSystem: return; case ServiceType.Amazon: case ServiceType.DropBox: case ServiceType.Google: canOffline = true; break; } } if (!canOffline) { return; } } var localTitle = item.ShouldBeLocal() || item.OfflineCount > 0 ? "Remove from Device" : "Download to Device"; controller.Add(localTitle, () => { OfflineManager.Shared.ToggleOffline(item); }); }
static void AddShuffleButton(ActionSheet controller, MediaItemBase item) { if (!ShouldShowShuffle(item)) { return; } controller.Add("Shuffle", () => { Settings.ShuffleSongs = true; PlaybackManager.Shared.Play(item); }); }
static void AddRemoveFromLibrary(ActionSheet controller, MediaItemBase item) { if (!ShouldRemoveFromLibrary(item)) { return; } controller.Add("Remove from Library", async() => { var success = await MusicManager.Shared.Delete(item); //TODO: Show Alert Console.WriteLine(success); }); }
public ActionSheet CreateController(MediaItemBase song) { var controller = new ActionSheet(song.Name, song.DetailText); AddPlaybackButtons(controller, song); AddShuffleButton(controller, song); AddPlaylistButtons(controller, song); AddRadioStationButton(controller, song); AddToLibrary(controller, song); AddRemoveFromLibrary(controller, song); AddOfflineButtons(controller, song); controller.Add("Cancel", null, true); return(controller); }
static void AddPlaybackButtons(ActionSheet controller, MediaItemBase item) { if (!ShouldShowQueueButtons(item)) { return; } if (ShouldShowPlayNowButton(item)) { controller.Add("Play", () => { PlaybackManager.Shared.Play(item); }); } if (ShouldShowPlayVideoButton(item)) { controller.Add("Play Video", () => { PlaybackManager.Shared.PlayNow(item as Song, true); }); } controller.Add("Play Next", () => { PlaybackManager.Shared.PlayNext(item); }); controller.Add("Add to Queue", () => { PlaybackManager.Shared.AddtoQueue(item); }); }
static void AddOfflineButtons(ActionSheet controller, MediaItemBase item) { if (item is RadioStation || item is AutoPlaylist) { return; } var song = item as Song; if (song != null) { bool canOffline = song.ServiceTypes.Any(x => AllowedOffLineTypes.Contains(x)); if (!canOffline) { return; } } var localTitle = item.ShouldBeLocal() || item.OfflineCount > 0 ? "Remove from Device" : "Download to Device"; controller.Add(localTitle, () => { OfflineManager.Shared.ToggleOffline(item); }); }
SettingsElement CreateThemePicker(string title) { SettingsElement element = null; element = new SettingsElement(title, () => { var sheet = new ActionSheet("Theme"); MusicPlayer.iOS.Style.AvailableStyles.ForEach(x => sheet.Add(x.Id, () => { Settings.CurrentStyle = x.Id; element.Value = x.Id; })); sheet.Show(this, TableView); }) { style = UITableViewCellStyle.Value1, Value = Settings.CurrentStyle, }; return(element); }
public static void AddPlaylistButtons(ActionSheet controller, MediaItemBase item) { if (!ShouldShowAddPlaylist(item)) { return; } controller.Add("Add to Playlist", async() => { try { var playlistPicker = new PlaylistPickerViewController { FilterBy = item, ShouldHideMenu = true }; PresentController(new UINavigationController(playlistPicker)); var playlist = await playlistPicker.SelectPlaylist(); Console.WriteLine(playlist); using (new Spinner("Adding to Playlist")) { var success = await MusicManager.Shared.AddToPlaylist(item, playlist); if (!success) { App.ShowAlert("Error adding to playlist", "Please try again later"); } } } catch (TaskCanceledException canceledException) { Console.WriteLine("Canceled"); } catch (Exception ex) { App.ShowAlert("Error adding to playlist", "Please try again later"); LogManager.Shared.Report(ex); } }); }
public SettingViewController() : base(UITableViewStyle.Plain, null) { Title = Strings.Settings; accountsSection = new MenuSection("Accounts") { (addNewAccountElement = new SettingsElement("Add Streaming Service", async() => { try{ var vc = new ServicePickerViewController(); this.PresentModalViewController(new UINavigationController(vc), true); var service = await vc.GetServiceTypeAsync(); await ApiManager.Shared.CreateAndLogin(service); UpdateAccounts(); } catch (TaskCanceledException) { } catch (Exception ex) { Console.WriteLine(ex); } })), (lastFmElement = string.IsNullOrEmpty(ApiConstants.LastFmApiKey) ? null : new SettingsSwitch("Last.FM", Settings.LastFmEnabled)), (twitterScrobbleElement = new SettingsSwitch("Auto Tweet", Settings.TwitterEnabled) { Detail = Settings.TwitterDisplay }), new SettingsSwitch("Import iPod Music", Settings.IncludeIpod) { ValueUpdated = ToggleIPod }, new MenuHelpTextElement( "Automatically imports and plays music from your local library. This saves data and space on your phone."), }; Root = new RootElement(Strings.Settings) { accountsSection, new MenuSection(Strings.Playback) { new SettingsSwitch(Strings.EnableLikeOnTheLockScreen, Settings.ThubsUpOnLockScreen) { ValueUpdated = (b => { Settings.ThubsUpOnLockScreen = b; RemoteControlHandler.SetupThumbsUp(); }) }, new MenuHelpTextElement(Strings.EnableLikeHint), new SettingsSwitch(Strings.EnableGaplessPlayback, Settings.ThubsUpOnLockScreen) { ValueUpdated = (b => { Settings.ThubsUpOnLockScreen = b; RemoteControlHandler.SetupThumbsUp(); }) }, new MenuHelpTextElement(Strings.EnableGapplessHint), new SettingsSwitch(Strings.PlayVideosWhenAvailable, Settings.PreferVideos) { ValueUpdated = (b => { Settings.PreferVideos = b; }) }, new MenuHelpTextElement(Strings.PlaysMusicVideoHint), new SettingsSwitch(Strings.PlayCleanVersionsOfSongs, Settings.FilterExplicit) { ValueUpdated = (b => { Settings.FilterExplicit = b; }) }, new MenuHelpTextElement(Strings.PlayesCleanVersionOfSongsHint), }, new MenuSection(Strings.Streaming) { new SettingsSwitch(Strings.DisableAllAccess, Settings.DisableAllAccess) { ValueUpdated = (on) => { Settings.DisableAllAccess = on; } }, new MenuHelpTextElement(Strings.DisableAllAccessHint), (CreateQualityPicker(Strings.CellularAudioQuality, Settings.MobileStreamQuality, (q) => Settings.MobileStreamQuality = q)), (CreateQualityPicker(Strings.WifiAudioQuality, Settings.WifiStreamQuality, (q) => Settings.WifiStreamQuality = q)), (CreateQualityPicker(Strings.VideoQuality, Settings.VideoStreamQuality, (q) => Settings.VideoStreamQuality = q)), (CreateQualityPicker(Strings.OfflineAudioQuality, Settings.DownloadStreamQuality, (q) => Settings.DownloadStreamQuality = q)), new MenuHelpTextElement(Strings.QualityHints) }, new MenuSection(Strings.Feedback) { new SettingsElement(Strings.SendFeedback, SendFeedback) { TextColor = iOS.Style.DefaultStyle.MainTextColor }, new SettingsElement($"{Strings.PleaseRate} {AppDelegate.AppName}", RateAppStore) { TextColor = iOS.Style.DefaultStyle.MainTextColor }, (ratingMessage = new MenuHelpTextElement(Strings.NobodyHasRatedYet)) }, new MenuSection(Strings.Settings) { CreateThemePicker("Theme"), new SettingsElement(Strings.ResyncDatabase, () => { Settings.ResetApiModes(); ApiManager.Shared.ReSync(); }), new MenuHelpTextElement(Strings.ResyncDatabaseHint), new SettingsElement(Strings.DownloadQueue, () => NavigationController.PushViewController(new DownloadViewController(), true)), (songsElement = new SettingsElement(Strings.SongsCount)) } }; if (lastFmElement != null) { lastFmElement.ValueUpdated = async b => { if (!b) { Settings.LastFmEnabled = false; ScrobbleManager.Shared.LogOut(); return; } var success = false; try { success = await ScrobbleManager.Shared.LoginToLastFm(); } catch (TaskCanceledException ex) { lastFmElement.Value = Settings.LastFmEnabled = false; TableView.ReloadData(); return; } Settings.LastFmEnabled = success; if (success) { return; } lastFmElement.Value = false; ReloadData(); App.ShowAlert($"{Strings.ErrorLoggingInto} Last.FM", Strings.PleaseTryAgain); }; } twitterScrobbleElement.ValueUpdated = async b => { if (!b) { Settings.TwitterEnabled = false; Settings.TwitterDisplay = ""; Settings.TwitterAccount = ""; twitterScrobbleElement.Detail = ""; return; } var store = new ACAccountStore(); var accountType = store.FindAccountType(ACAccountType.Twitter); var success = false; var result = await store.RequestAccessAsync(accountType); success = result.Item1; if (!success) { Settings.TwitterEnabled = false; twitterScrobbleElement.Value = false; ReloadData(); return; } var accounts = store.FindAccounts(accountType); if ((accounts?.Length ?? 0) == 0) { Settings.TwitterEnabled = false; twitterScrobbleElement.Value = false; ReloadData(); return; } if (accounts?.Length == 1) { Settings.TwitterEnabled = true; var a = accounts[0]; Settings.TwitterAccount = a.Identifier; twitterScrobbleElement.Detail = Settings.TwitterDisplay = a.UserFullName; ReloadData(); return; } var sheet = new ActionSheet("Twitter"); foreach (var a in accounts) { sheet.Add(a.Identifier, () => { Settings.TwitterEnabled = true; Settings.TwitterAccount = a.Identifier; twitterScrobbleElement.Detail = Settings.TwitterDisplay = a.UserFullName; ReloadData(); }); } sheet.Add(Strings.Nevermind, null, true); sheet.Show(this, TableView); }; }