Beispiel #1
0
        private async Task LoadCurrentPage()
        {
            await LoadPage(CurrentPage);

            if (CurrentPageIndex - 1 > 0)
            {
                LoadPage(Pages[CurrentPageIndex - 1]);
            }

            if (CurrentPageIndex + 1 < Pages.Count)
            {
                LoadPage(Pages[CurrentPageIndex + 1]);
            }

            var pageNumber = GetPageNumberFromIndex(CurrentPageIndex);

            CurrentSurahName   = QuranUtils.GetSurahNameFromPage(pageNumber, false);
            CurrentSurahNumber = QuranUtils.GetSurahNumberFromPage(pageNumber);
            var rub = QuranUtils.GetRub3FromPage(pageNumber);

            CurrentJuzName = string.Format("{0} {1}{2} {3} {4}", QuranUtils.GetJuzTitle(),
                                           QuranUtils.GetJuzFromPage(pageNumber),
                                           getJuzPart(rub), Resources.quran_rub3, rub + 1);
            CurrentPageBookmarked = BookmarksDatabaseHandler.IsPageBookmarked(CurrentPageNumber);

            if (!IsLoading)
            {
                SettingsUtils.Set <int>(Constants.PREF_LAST_PAGE, pageNumber);
            }
        }
        private async Task LoadBookmarkList()
        {
            Bookmarks.Clear();
            var lastPage = SettingsUtils.Get <int>(Constants.PREF_LAST_PAGE);

            if (lastPage > 0)
            {
                var lastPageItem = new ItemViewModel();
                lastPageItem.Title   = QuranUtils.GetSurahNameFromPage(lastPage, true);
                lastPageItem.Details = string.Format("{0} {1}, {2} {3}", Resources.quran_page, lastPage,
                                                     QuranUtils.GetJuzTitle(),
                                                     QuranUtils.GetJuzFromPage(lastPage));
                lastPageItem.PageNumber = lastPage;
                lastPageItem.Image      = new BitmapImage(new Uri("ms-appx:///Assets/Images/favorite.png"));
                lastPageItem.ItemType   = ItemViewModelType.Bookmark;
                lastPageItem.Group      = Resources.bookmarks_current_page;
                lastPageItem.Id         = lastPageItem.Group;
                Bookmarks.Add(lastPageItem);
            }

            using (var bookmarksAdapter = new BookmarksDatabaseHandler())
            {
                try
                {
                    var bookmarks = bookmarksAdapter.GetBookmarks(true, BoomarkSortOrder.Location);
                    if (bookmarks.Count > 0)
                    {
                        //Load untagged first
                        foreach (var bookmark in bookmarks)
                        {
                            if (bookmark.Tags == null)
                            {
                                Bookmarks.Add(await CreateBookmarkModel(bookmark));
                            }
                        }

                        //Load tagged
                        foreach (var bookmark in bookmarks)
                        {
                            if (bookmark.Tags != null)
                            {
                                Bookmarks.Add(await CreateBookmarkModel(bookmark));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    telemetry.TrackException(ex, new Dictionary <string, string> {
                        { "Scenario", "LoadingBookmarks" }
                    });
                    QuranApp.NativeProvider.Log("failed to load bookmarks: " + ex.Message);
                }
            }
        }
 private void LoadSuraList()
 {
     for (int surah = 1; surah <= Constants.SURAS_COUNT; surah++)
     {
         string title = QuranUtils.GetSurahName(surah, true);
         Surahs.Add(new ItemViewModel
         {
             Id         = surah.ToString(CultureInfo.InvariantCulture),
             Title      = title,
             Details    = QuranUtils.GetSuraListMetaString(surah),
             PageNumber = QuranUtils.SURA_PAGE_START[surah - 1],
             ItemType   = ItemViewModelType.Surah,
             Group      = QuranUtils.GetJuzTitle() + " " + QuranUtils.GetJuzFromAyah(surah, 1)
         });
     }
 }
Beispiel #4
0
        private async Task LoadCurrentPage()
        {
            var tempCurrentPageIndex = CurrentPageIndex;
            var _currentPage         = GetPageFromIndex(tempCurrentPageIndex);

            if (_currentPage == null)
            {
                return;
            }

            await _currentPage.Load(this.TranslationFile, _bismillahTranslation);

            var pageNumber = GetPageNumberFromIndex(tempCurrentPageIndex);

            CurrentSurahName   = QuranUtils.GetSurahNameFromPage(pageNumber, false);
            CurrentSurahNumber = QuranUtils.GetSurahNumberFromPage(pageNumber);
            var rub = QuranUtils.GetRub3FromPage(pageNumber);

            CurrentJuzName = string.Format("{0} {1}{2} {3} {4}", QuranUtils.GetJuzTitle(),
                                           QuranUtils.GetJuzFromPage(pageNumber),
                                           getJuzPart(rub), Resources.quran_rub3, rub + 1);
            CurrentPageBookmarked = BookmarksDatabaseHandler.IsPageBookmarked(pageNumber);

            // Load previous and next pages
            var _previousPage = GetPageFromIndex(tempCurrentPageIndex - 1);

            if (_previousPage != null)
            {
                await _previousPage.Load(this.TranslationFile, _bismillahTranslation);
            }
            var _nextPage = GetPageFromIndex(tempCurrentPageIndex + 1);

            if (_nextPage != null)
            {
                await _nextPage.Load(this.TranslationFile, _bismillahTranslation);
            }

            if (!IsLoading)
            {
                SettingsUtils.Set <int>(Constants.PREF_LAST_PAGE, pageNumber);
            }
        }
        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 = "";

                try
                {
                    using (var dbArabic = new QuranDatabaseHandler <ArabicAyah>(FileUtils.ArabicDatabase))
                    {
                        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));

                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 IEnumerable <IGrouping <KeyValuePair <string, string>, ItemViewModel> > GetGrouppedSurahItems()
 {
     return(from b in Surahs
            group b by new KeyValuePair <string, string>(b.Group.Substring(QuranUtils.GetJuzTitle().Length + 1), b.Group) into g
            select g);
 }