public OcrLanguagesPage(ObservableCollection <OcrLanguage> activeLanguages)
        {
            BindingContext = this;

            if (activeLanguages == null)
            {
                ActiveLanguages = new ObservableCollection <OcrLanguage>();
            }
            else
            {
                ActiveLanguages = new ObservableCollection <OcrLanguage>(activeLanguages);
            }

            if (OcrLanguageManager.DownloadableLanguages == null)
            {
                string embeddedLanguagesManifestFilePath = Assembly.GetExecutingAssembly().GetManifestResourceNames().Single(rn => rn.EndsWith("embedded_ocr_languages_manifest.json"));
                if (!string.IsNullOrWhiteSpace(embeddedLanguagesManifestFilePath))
                {
                    OcrLanguageManager.UpdateDownloadableLanguagesInfo(embeddedLanguagesManifestFilePath, null);
                }
            }

            DownloadableLanguages = OcrLanguageManager.DownloadableLanguages;

            InitializeComponent();
            AfterInitializeComponent();

            TitleExtraButtonTapped += EditButton_TitleExtraButtonTapped;
            PageClosing            += OcrLanguagesPage_PageClosing;

            ReloadCachedLanguagesInfo();
        }
        private void CancelLanguageDownloadButton_Tapped(object sender, EventArgs e)
        {
            OcrLanguage ocrLanguage = (sender as Label).BindingContext as OcrLanguage;

            if (ocrLanguage == null)
            {
                return;
            }

            OcrLanguageManager.CancelDownloadForLanguage(ocrLanguage.Language);
        }
        private void DownloadLanguageButton_Tapped(object sender, EventArgs e)
        {
            Label downloadButton = sender as Label;

            downloadButton.IsEnabled = false;
            OcrLanguage ocrLanguage = (sender as Label).BindingContext as OcrLanguage;

            if (ocrLanguage == null)
            {
                return;
            }

            ocrLanguage.Tag = sender;
            OcrLanguageManager.DownloadLanguage(ocrLanguage.Language, null, new OcrLanguageManager.CompletionDelegate(DownloadLanguageCompleted));
        }
        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();
        }