private async void DownloadLanguageCompleted(OcrLanguage language, Exception error) { if (language != null && language.Tag != null) { await Device.InvokeOnMainThreadAsync(() => (language.Tag as Label).IsEnabled = true); } if (error == null) { // Download completed successfully, then remove the downloaded language from the downloadable languages list and add it to the inactive languages list. await Device.InvokeOnMainThreadAsync(async() => { if (language != null && !language.CancellationTokenSource.IsCancellationRequested) { DownloadableLanguages = OcrLanguageManager.DownloadableLanguages; var langs = InactiveLanguages.Where(l => l.Language.Equals(language.Language)); if (langs == null || langs.Count() == 0) { InactiveLanguages.Add(language); } language.IsDownloadable = false; await Device.InvokeOnMainThreadAsync(() => ReloadCachedLanguagesInfo()); } }); } else { // Error occurred while downloading this language await Device.InvokeOnMainThreadAsync(async() => { ReloadCachedLanguagesInfo(); await DisplayAlert("Error Downloading File", $"Encountered an error while trying to download the {language.LocalizedName} language: {error.Message}", "OK"); }); } }
private void DeleteLanguageButton_Tapped(object sender, EventArgs e) { OcrLanguage ocrLanguage = (sender as SvgImage).BindingContext as OcrLanguage; if (ocrLanguage == null) { return; } OcrLanguageManager.DeleteLanguage(ocrLanguage.Language); ocrLanguage.IsDownloadable = true; // Manually remove from active/inactive languages, then manually add to downloadable languages if (ActiveLanguages.Contains(ocrLanguage)) { ActiveLanguages.Remove(ocrLanguage); } else if (InactiveLanguages.Contains(ocrLanguage)) { InactiveLanguages.Remove(ocrLanguage); } if (!DownloadableLanguages.Contains(ocrLanguage)) { // Take the language from OcrLanguageManager.DownloadableLanguages instead of the local downloadable languages list since that one // has the updated class members like file size and what not. var langs = OcrLanguageManager.DownloadableLanguages.Where(l => l.Language.Equals(ocrLanguage.Language)); if (langs != null && langs.Count() > 0) { ocrLanguage = langs.ElementAt(0); } DownloadableLanguages.Add(ocrLanguage); } ReloadCachedLanguagesInfo(); }
private void PopulateActiveInactiveLanguages() { InactiveLanguages.Clear(); foreach (OcrLanguage localLanguage in OcrLanguageManager.LocalLanguages) { localLanguage.IsDefaultLanguage = false; if (!ActiveLanguages.Any(l => l.Language.Equals(localLanguage.Language))) { InactiveLanguages.Add(localLanguage); } } foreach (OcrLanguage activeLanguage in ActiveLanguages) { activeLanguage.IsDefaultLanguage = ActiveLanguages[0].Equals(activeLanguage); } var inactiveLanguages = InactiveLanguages.OrderBy(firstOrder => firstOrder.CanBeDeleted).ThenBy(secondOrder => secondOrder.LocalizedName); InactiveLanguages = new ObservableCollection <OcrLanguage>(inactiveLanguages); RefreshActiveInactiveListViews(); }