private static async Task<ItemViewModel> CreateBookmarkModel(Bookmarks bookmark) { var group = Resources.bookmarks; if (bookmark.Tags != null && bookmark.Tags.Count > 0) group = bookmark.Tags[0].Name; if (bookmark.Ayah != null && bookmark.Surah != null) { string title = QuranUtils.GetSurahNameFromPage(bookmark.Page, true); string details = ""; if (await FileUtils.HaveArabicSearchFile()) { try { using (var dbArabic = new QuranDatabaseHandler<ArabicAyah>(FileUtils.QURAN_ARABIC_DATABASE)) { var ayahSurah = await new TaskFactory().StartNew( () => dbArabic.GetVerse(bookmark.Surah.Value, bookmark.Ayah.Value)); title = ayahSurah.Text; } } catch (Exception ex) { telemetry.TrackException(ex, new Dictionary<string, string> { { "Scenario", "OpenArabicDatabase" } }); } details = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}, {3} {4}", QuranUtils.GetSurahName(bookmark.Surah.Value, true), Resources.verse, bookmark.Ayah.Value, QuranUtils.GetJuzTitle(), QuranUtils.GetJuzFromPage(bookmark.Page)); } else { details = string.Format(CultureInfo.InvariantCulture, "{0} {1}, {2} {3}, {4} {5}", Resources.quran_page, bookmark.Page, Resources.verse, bookmark.Ayah.Value, QuranUtils.GetJuzTitle(), QuranUtils.GetJuzFromPage(bookmark.Page)); } if (title.Length > maxBookmarkTitle) { for (int i = maxBookmarkTitle; i > 1; i--) { if (title[i] == ' ') { title = title.Substring(0, i - 1); break; } } } return new ItemViewModel { Id = bookmark.Id.ToString(CultureInfo.InvariantCulture), Title = title, Details = details, PageNumber = bookmark.Page, SelectedAyah = new QuranAyah(bookmark.Surah.Value, bookmark.Ayah.Value), Image = new BitmapImage(new Uri("ms-appx:///Assets/Images/favorite.png")), ItemType = ItemViewModelType.Bookmark, Group = group }; } else { return new ItemViewModel { Id = bookmark.Id.ToString(CultureInfo.InvariantCulture), Title = QuranUtils.GetSurahNameFromPage(bookmark.Page, true), Details = string.Format(CultureInfo.InvariantCulture, "{0} {1}, {2} {3}", Resources.quran_page, bookmark.Page, QuranUtils.GetJuzTitle(), QuranUtils.GetJuzFromPage(bookmark.Page)), PageNumber = bookmark.Page, Image = new BitmapImage(new Uri("ms-appx:///Assets/Images/favorite.png")), ItemType = ItemViewModelType.Bookmark, Group = group }; } }
public int AddBookmark(int? surah, int? ayah, int page) { var bookmark = new Bookmarks { Ayah = ayah, Surah = surah, Page = page }; dbConnection.Insert(bookmark); PageCache.Add(page); return bookmark.Id; }
private static async Task<ItemViewModel> createBookmarkModel(Bookmarks bookmark) { var group = AppResources.bookmarks; if (bookmark.Tags != null && bookmark.Tags.Count > 0) group = bookmark.Tags[0].Name; if (bookmark.Ayah != null && bookmark.Surah != null) { string title = QuranUtils.GetSurahNameFromPage(bookmark.Page, true); string details = ""; if (FileUtils.HaveArabicSearchFile()) { try { using (var dbArabic = new QuranDatabaseHandler<ArabicAyah>(FileUtils.QURAN_ARABIC_DATABASE)) { var ayahSurah = await new TaskFactory().StartNew( () => dbArabic.GetVerse(bookmark.Surah.Value, bookmark.Ayah.Value)); title = ayahSurah.Text; } } catch { //Not able to get Arabic text - skipping } details = string.Format(CultureInfo.InvariantCulture, "{0} {1} {2}, {3} {4}", QuranUtils.GetSurahName(bookmark.Surah.Value, true), AppResources.verse, bookmark.Ayah.Value, QuranUtils.GetJuzTitle(), QuranUtils.GetJuzFromPage(bookmark.Page)); } else { details = string.Format(CultureInfo.InvariantCulture, "{0} {1}, {2} {3}, {4} {5}", AppResources.quran_page, bookmark.Page, AppResources.verse, bookmark.Ayah.Value, QuranUtils.GetJuzTitle(), QuranUtils.GetJuzFromPage(bookmark.Page)); } if (title.Length > maxBookmarkTitle) { for (int i = maxBookmarkTitle; i > 1; i--) { if (title[i] == ' ') { title = title.Substring(0, i - 1); break; } } } return new ItemViewModel { Id = bookmark.Id.ToString(CultureInfo.InvariantCulture), Title = title, Details = details, PageNumber = bookmark.Page, SelectedAyah = new QuranAyah(bookmark.Surah.Value, bookmark.Ayah.Value), Image = new Uri("/Assets/Images/favorite.png", UriKind.Relative), ItemType = ItemViewModelType.Bookmark, Group = group }; } else { return new ItemViewModel { Id = bookmark.Id.ToString(CultureInfo.InvariantCulture), Title = QuranUtils.GetSurahNameFromPage(bookmark.Page, true), Details = string.Format(CultureInfo.InvariantCulture, "{0} {1}, {2} {3}", AppResources.quran_page, bookmark.Page, QuranUtils.GetJuzTitle(), QuranUtils.GetJuzFromPage(bookmark.Page)), PageNumber = bookmark.Page, Image = new Uri("/Assets/Images/favorite.png", UriKind.Relative), ItemType = ItemViewModelType.Bookmark, Group = group }; } }