static async Task UpdateSubtitles() { _ = ActionPopup.StartIndeterminateLoadinbar("Loading Subtitles..."); if (subtitleIndex != -1) { await ChangeSubtitles(subtitles[subtitleIndex].data, subtitles[subtitleIndex].name, subtitleDelay); } else { await ChangeSubtitles("", "", 0); } await ActionPopup.StopIndeterminateLoadinbar(); }
public async void SelectSubtitleOption() { List <string> options = new List <string>(); if (subtitles.Count == 0) { options.Add($"Download Subtitles ({Settings.NativeSubLongName})"); } else { // if (subtitleIndex != -1) { // options.Add($"Turn {(HasSubtitlesOn ? "Off" : $"On ({subtitles[subtitleIndex].name})")}"); //} if (HasSubtitlesOn) { //if (subtitleIndex != -1) { // options.Add($"Turn off"); //} options.Add($"Change Delay ({subtitleDelay} ms)"); } options.Add("Select Subtitles"); } options.Add("Download Subtitles"); async Task UpdateSubtitles() { ActionPopup.StartIndeterminateLoadinbar("Loading Subtitles..."); if (subtitleIndex != -1) { await ChangeSubtitles(subtitles[subtitleIndex].data, subtitles[subtitleIndex].name, subtitleDelay); } else { await ChangeSubtitles("", "", 0); } await ActionPopup.StopIndeterminateLoadinbar(); } string action = await ActionPopup.DisplayActionSheet("Subtitles", options.ToArray()); if (action == "Download Subtitles") { string subAction = await ActionPopup.DisplayActionSheet("Download Subtitles", subtitleNames); if (subAction != "Cancel") { int index = subtitleNames.IndexOf(subAction); PopulateSubtitle(subtitleShortNames[index], subAction); } } else if (action == "Select Subtitles") { List <string> subtitlesList = subtitles.Select(t => t.name).ToList(); subtitlesList.Insert(0, "None"); string subAction = await ActionPopup.DisplayActionSheet("Select Subtitles", subtitleIndex + 1, subtitlesList.ToArray()); if (subAction != "Cancel") { int setTo = subtitlesList.IndexOf(subAction) - 1; if (setTo != subtitleIndex) { subtitleIndex = setTo; HasSubtitlesOn = subtitleIndex != -1; await Task.Delay(100); await UpdateSubtitles(); } } } else if (action == $"Download Subtitles ({Settings.NativeSubLongName})") { PopulateSubtitle(); } else if (action.StartsWith("Turn off")) { subtitleIndex = -1; await UpdateSubtitles(); // await MainChrome.ToggleSubtitles(!HasSubtitlesOn); HasSubtitlesOn = !HasSubtitlesOn; } else if (action.StartsWith("Change Delay")) { int del = await ActionPopup.DisplayIntEntry("ms", "Subtitle Delay", 50, false, subtitleDelay.ToString(), "Set Delay"); if (del != -1) { subtitleDelay = del; await Task.Delay(100); await UpdateSubtitles(); } } }