Exemple #1
0
        public async Task CopyAyahToClipboard(QuranAyah ayah)
        {
            if (ayah == null)
            {
                return;
            }

            if (ayah.Translation != null)
            {
                QuranApp.NativeProvider.CopyToClipboard(ayah.Translation);
            }
            else if (ayah.Text != null)
            {
                QuranApp.NativeProvider.CopyToClipboard(ayah.Text);
            }
            else
            {
                try
                {
                    using (var dbArabic = new QuranDatabaseHandler <ArabicAyah>(FileUtils.ArabicDatabase))
                    {
                        var ayahSurah =
                            await new TaskFactory().StartNew(() => dbArabic.GetVerse(ayah.Surah, ayah.Ayah));
                        QuranApp.NativeProvider.CopyToClipboard(ayahSurah.Text);
                    }
                }
                catch (Exception e)
                {
                    telemetry.TrackException(e, new Dictionary <string, string> {
                        { "Scenario", "OpenArabicDatabase" }
                    });
                }
            }
        }
Exemple #2
0
 public bool AddAyahBookmark(QuranAyah ayah)
 {
     try
     {
         using (var adapter = new BookmarksDatabaseHandler())
         {
             if (ayah == null)
             {
                 adapter.AddBookmarkIfNotExists(null, null, CurrentPageNumber);
             }
             else
             {
                 adapter.AddBookmarkIfNotExists(ayah.Surah, ayah.Ayah, CurrentPageNumber);
             }
         }
         CurrentPageBookmarked = BookmarksDatabaseHandler.IsPageBookmarked(CurrentPageNumber);
         return(true);
     }
     catch (Exception e)
     {
         QuranApp.NativeProvider.Log("error creating bookmark");
         telemetry.TrackException(e, new Dictionary <string, string> {
             { "Scenario", "AddBookmark" }
         });
         return(false);
     }
 }
Exemple #3
0
        public void QuranAyahFromStringAndToStringAreTheSame()
        {
            string ayahString = "1:2";
            var    ayah       = QuranAyah.FromString(ayahString);

            Assert.Equal(ayahString, ayah.ToString());
        }
 private void UpdateSelectedAyah(QuranAyah ayahInfo)
 {
     if (ayahInfo == null)
     {
         canvas.Opacity = 0;
     }
     else
     {
         var currentModel = this.DataContext as VerseViewModel;
         if (currentModel != null && currentModel.Surah == ayahInfo.Surah &&
             currentModel.Ayah == ayahInfo.Ayah)
         {
             canvas.Opacity = 1.0;
             if (QuranApp.DetailsViewModel.AudioPlayerState == AudioState.Playing)
             {
                 canvasStoryboard.Seek(new TimeSpan(1));
                 canvasStoryboard.Stop();
             }
             else
             {
                 canvasStoryboard.Begin();
             }
         }
         else
         {
             canvas.Opacity = 0;
         }
     }
 }
Exemple #5
0
        public async Task <string> GetAyahString(QuranAyah ayah)
        {
            if (ayah == null)
            {
                return(null);
            }

            else if (ayah.Text != null)
            {
                return(ayah.Text);
            }
            else
            {
                try
                {
                    return(await Task.Run <string>(() =>
                    {
                        using (var dbArabic = new QuranDatabaseHandler <ArabicAyah>(FileUtils.ArabicDatabase))
                        {
                            var ayahSurah = dbArabic.GetVerse(ayah.Surah, ayah.Ayah);
                            string ayahText = ayahSurah.Text;
                            return ayahText;
                        }
                    }));
                }
                catch (Exception e)
                {
                    telemetry.TrackException(e, new Dictionary <string, string> {
                        { "Scenario", "OpenArabicDatabase" }
                    });
                }
            }
            return(null);
        }
Exemple #6
0
 public void QuranAyahFromStringThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => QuranAyah.FromString(null));
     Assert.Throws <ArgumentException>(() => QuranAyah.FromString(""));
     Assert.Throws <ArgumentException>(() => QuranAyah.FromString("1"));
     Assert.Throws <ArgumentException>(() => QuranAyah.FromString("a:b"));
 }
Exemple #7
0
        public async Task Play()
        {
            if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Playing)
            {
                // Do nothing
                return;
            }
            else if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Paused)
            {
                QuranApp.NativeProvider.AudioProvider.Play();
                return;
            }
            else
            {
                var       bounds = QuranUtils.GetPageBounds(CurrentPageNumber);
                QuranAyah ayah   = new QuranAyah
                {
                    Surah = bounds[0],
                    Ayah  = bounds[1]
                };

                if (ayah.Ayah == 1 && ayah.Surah != Constants.SURA_TAWBA &&
                    ayah.Surah != Constants.SURA_FIRST)
                {
                    ayah.Ayah = 0;
                }

                await PlayFromAyah(ayah);
            }
        }
        public AudioRequest(int reciterId, QuranAyah verse, RepeatInfo repeat, int currentRepeatIteration, AudioDownloadAmount audioDownloadAmount)
        {
            if (verse == null)
                throw new ArgumentNullException("verse");

            if (verse == null || verse.Surah < 1 || verse.Surah > 114)
                throw new ArgumentException("verse");

            this.Reciter = AudioUtils.GetReciterById(reciterId);
            this.AudioDownloadAmount = audioDownloadAmount;
            this.FromAyah = verse;
            this.CurrentAyah = verse;
            this.ToAyah = AudioUtils.GetLastAyahToPlay(verse, audioDownloadAmount);

            if (repeat != null)
            {
                this.RepeatInfo = repeat;
            }
            else
            {
                this.RepeatInfo = new RepeatInfo();
            }

            this.repeatManager = new RepeatManager(this.RepeatInfo, verse, currentRepeatIteration);
        }
        public async Task Play()
        {
            if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Playing)
            {
                // Do nothing
                return;
            }
            else if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Paused)
            {
                QuranApp.NativeProvider.AudioProvider.Play();
                return;
            }
            else
            {
                var bounds = QuranUtils.GetPageBounds(CurrentPageNumber);
                QuranAyah ayah = new QuranAyah
                {
                    Surah = bounds[0],
                    Ayah = bounds[1]
                };

                if (ayah.Ayah == 1 && ayah.Surah != Constants.SURA_TAWBA &&
                    ayah.Surah != Constants.SURA_FIRST)
                {
                    ayah.Ayah = 0;
                }

                await PlayFromAyah(ayah);
            }
        }
Exemple #10
0
        private static QuranAyah GetLastAyahToPlayForSura(QuranAyah startAyah)
        {
            int surah    = startAyah.Surah;
            int lastAyah = QuranUtils.GetSurahNumberOfAyah(surah);

            return(new QuranAyah(surah, lastAyah));
        }
 private void UpdateSelectedAyah(QuranAyah ayahInfo)
 {
     if (ayahInfo == null)
     {
         canvas.Opacity = 0;
     }
     else
     {
         var currentModel = this.DataContext as VerseViewModel;
         if (currentModel != null && currentModel.Surah == ayahInfo.Surah &&
             currentModel.Ayah == ayahInfo.Ayah &&
             currentModel.Ayah != 0 &&
             currentModel.Surah != 0)
         {
             canvas.Opacity = 1.0;
             if (QuranApp.DetailsViewModel.AudioPlayerState == AudioState.Playing)
             {
                 canvasStoryboard.Seek(new TimeSpan(1));
                 canvasStoryboard.Stop();
             }
             else
             {
                 canvasStoryboard.Begin();
             }
         }
         else
         {
             canvas.Opacity = 0;
         }
     }
 }
 private static QuranAyah GetLastAyahFromAyahCount(QuranAyah firstAyah, int count)
 {
     var currentAyah = firstAyah;
     for (int i = 1; i < count; i++)
     {
         currentAyah = QuranUtils.GetNextAyah(currentAyah, false);
     }
     return currentAyah;
 }
        private async void AyahContextMenuClick(object sender, RoutedEventArgs e)
        {
            var menuFlyoutItem = sender as MenuFlyoutItem;

            if (menuFlyoutItem == null)
            {
                return;
            }

            QuranAyah selectedAyah = menuFlyoutItem.DataContext as QuranAyah;

            if (selectedAyah == null)
            {
                return;
            }

            var menuItem = menuFlyoutItem.Text;

            if (menuItem == Core.Properties.Resources.bookmark_ayah)
            {
                ViewModel.AddAyahBookmark(selectedAyah);
            }
            else if (menuItem == Core.Properties.Resources.copy)
            {
                ViewModel.CopyAyahToClipboard(selectedAyah);
            }
            else if (menuItem == Core.Properties.Resources.share_ayah)
            {
                _ayahToShare      = selectedAyah;
                _ayahToShare.Text = await ViewModel.GetAyahString(_ayahToShare);

                DataTransferManager.ShowShareUI();
            }
            else if (menuItem == Core.Properties.Resources.recite_ayah)
            {
                int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI));
                if (currentQari == -1)
                {
                    Frame.Navigate(typeof(RecitersListView), null, new DrillInNavigationTransitionInfo());
                }
                else
                {
                    try
                    {
                        await ViewModel.PlayFromAyah(selectedAyah);

                        UpdateAudioControls(AudioState.Playing);
                    }
                    catch (Exception ex)
                    {
                        telemetry.TrackException(ex);
                    }
                }
            }

            ViewModel.SelectedAyah = null;
        }
Exemple #14
0
        private static QuranAyah GetLastAyahToPlayForPage(QuranAyah startAyah)
        {
            var page = QuranUtils.GetPageFromSurahAyah(startAyah.Surah, startAyah.Ayah);
            if (page == -1)
                return null;

            int[] pageBounds = QuranUtils.GetPageBounds(page);

            return new QuranAyah(pageBounds[2], pageBounds[3]);
        }
        private void ShowContextMenu(QuranAyah data, UIElement target, Point offset)
        {
            ViewModel.SelectedAyah = data;
            var ayahContextMenu = this.Resources["AyahContextMenu"] as MenuFlyout;

            foreach (MenuFlyoutItem item in ayahContextMenu.Items)
            {
                item.DataContext = data;
            }
            ayahContextMenu.ShowAt(target, offset);
        }
 public static bool IsValid(QuranAyah selectedAyah)
 {
     if (selectedAyah == null || selectedAyah.Surah < 1 || selectedAyah.Surah > 114)
     {
         return(false);
     }
     if (selectedAyah.Ayah < 0 || selectedAyah.Ayah > GetSurahNumberOfAyah(selectedAyah.Surah))
     {
         return(false);
     }
     return(true);
 }
        public RepeatManager(RepeatInfo info, QuranAyah firstAyah, int currentIteration)
        {
            if (firstAyah == null)
                throw new ArgumentNullException("firstAyah");

            RepeatInfo = info ?? new RepeatInfo();

            Counter = currentIteration;

            FirstAyah = firstAyah;
            GenerateLastAyah();
        }
Exemple #18
0
        private static QuranAyah GetLastAyahToPlayForPage(QuranAyah startAyah)
        {
            var page = QuranUtils.GetPageFromAyah(startAyah.Surah, startAyah.Ayah);

            if (page == -1)
            {
                return(null);
            }

            int[] pageBounds = QuranUtils.GetPageBounds(page);

            return(new QuranAyah(pageBounds[2], pageBounds[3]));
        }
Exemple #19
0
 public static QuranAyah GetLastAyahToPlay(QuranAyah startAyah, AudioDownloadAmount mode)
 {
     switch (mode)
     {
         case AudioDownloadAmount.Page:
             return GetLastAyahToPlayForPage(startAyah);
         case AudioDownloadAmount.Surah:
             return GetLastAyahToPlayForSura(startAyah);
         case AudioDownloadAmount.Juz:
             return GetLastAyahToPlayForJuz(startAyah);
         default:
             return GetLastAyahToPlayForPage(startAyah);
     }
 }
 private void GenerateLastAyah()
 {
     if (RepeatInfo.RepeatAmount == RepeatAmount.None)
     {
         LastAyah = FirstAyah;
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.OneAyah)
     {
         LastAyah = GetLastAyahFromAyahCount(FirstAyah, 1);
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.ThreeAyah)
     {
         LastAyah = GetLastAyahFromAyahCount(FirstAyah, 3);
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.FiveAyah)
     {
         LastAyah = GetLastAyahFromAyahCount(FirstAyah, 5);
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.TenAyah)
     {
         LastAyah = GetLastAyahFromAyahCount(FirstAyah, 10);
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.Page)
     {
         int page = QuranUtils.GetPageFromAyah(FirstAyah);
         int[] pageBounds = QuranUtils.GetPageBounds(page);
         FirstAyah = new QuranAyah(pageBounds[0], pageBounds[1]);
         LastAyah = new QuranAyah(pageBounds[2], pageBounds[3]);
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.Surah)
     {
         int surah = FirstAyah.Surah;
         int lastAyah = QuranUtils.GetSurahNumberOfAyah(surah);
         FirstAyah = new QuranAyah(surah, 1);
         LastAyah = new QuranAyah(surah, lastAyah);
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.Rub)
     {
         var rub = QuranUtils.GetRub3FromAyah(FirstAyah.Surah, FirstAyah.Ayah);
         FirstAyah = QuranUtils.GetRub3FirstAyah(rub);
         LastAyah = QuranUtils.GetRub3LastAyah(rub);
     }
     else if (RepeatInfo.RepeatAmount == RepeatAmount.Juz)
     {
         var juz = QuranUtils.GetJuzFromAyah(FirstAyah.Surah, FirstAyah.Ayah);
         FirstAyah = QuranUtils.GetJuzFirstAyah(juz);
         LastAyah = QuranUtils.GetJuzLastAyah(juz);
     }
 }
Exemple #21
0
        public AudioRequest(int reciterId, QuranAyah verse, AudioDownloadAmount audioDownloadAmount)
        {
            if (verse == null)
                throw new ArgumentNullException("verse");

            if (verse == null || verse.Surah < 1 || verse.Surah > 114)
                throw new ArgumentException("verse");

            this.Reciter = AudioUtils.GetReciterById(reciterId);
            this.AudioDownloadAmount = audioDownloadAmount;
            this.FromAyah = verse;
            this.CurrentAyah = verse;
            this.ToAyah = AudioUtils.GetLastAyahToPlay(verse, audioDownloadAmount);
            this.RepeatInfo = new RepeatInfo();
        }
 private void DataShareRequested(DataTransferManager sender, DataRequestedEventArgs args)
 {
     if (_ayahToShare != null)
     {
         args.Request.Data.Properties.Title = Core.Properties.Resources.share_ayah;
         if (_ayahToShare.Translation != null)
         {
             args.Request.Data.SetText(_ayahToShare.Translation);
         }
         else
         {
             args.Request.Data.SetText(_ayahToShare.Text);
         }
         _ayahToShare = null;
     }
 }
        public QuranAudioTrack(int reciterId, QuranAyah verse, ScreenInfo qsi)
        {
            if (verse == null)
            {
                throw new ArgumentNullException(nameof(verse));
            }

            if (verse == null || verse.Surah < 1 || verse.Surah > 114)
            {
                throw new ArgumentException("Invalid Surah number.", nameof(verse));
            }

            this.ReciterId = reciterId;
            this.Surah = verse.Surah;
            this.Ayah = verse.Ayah;
            this.ScreenInfo = qsi;
        }
Exemple #24
0
        public async Task PlayFromAyah(QuranAyah ayah)
        {
            int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get <string>(Constants.PREF_ACTIVE_QARI));

            if (currentQari == -1)
            {
                return;
            }

            var request = new QuranAudioTrack(currentQari, ayah,
                                              FileUtils.ScreenInfo);

            // if necessary download aya position file
            await DownloadAyahPositionFile();

            QuranApp.NativeProvider.AudioProvider.SetTrack(request);
        }
Exemple #25
0
        public static QuranAyah GetLastAyahToPlay(QuranAyah startAyah, AudioDownloadAmount mode)
        {
            switch (mode)
            {
            case AudioDownloadAmount.Page:
                return(GetLastAyahToPlayForPage(startAyah));

            case AudioDownloadAmount.Surah:
                return(GetLastAyahToPlayForSura(startAyah));

            case AudioDownloadAmount.Juz:
                return(GetLastAyahToPlayForJuz(startAyah));

            default:
                return(GetLastAyahToPlayForPage(startAyah));
            }
        }
        private async void UpdateSelectedAyah(QuranAyah ayahInfo)
        {
            PageViewModel page = DataContext as PageViewModel;

            if (ayahInfo != null && page != null)
            {
                // Wait for translations to load
                await _listLoaded.WaitAsync();

                VerseViewModel selectedTranslation = page.Translations.FirstOrDefault(t => t.Surah == SelectedAyah.Surah && t.Ayah == SelectedAyah.Ayah);
                if (selectedTranslation != null)
                {
                    TranslationListBox.ScrollIntoView(selectedTranslation);
                    SelectedAyahDelayed = ayahInfo;
                }
            }
        }
        public static ICollection <QuranAyah> GetAllAyah(QuranAyah fromAyah, QuranAyah toAyah)
        {
            var verses = new List <QuranAyah>();

            // Add first verse
            verses.Add(fromAyah);
            if (!Equals(fromAyah, toAyah))
            {
                var nextVerse = GetNextAyah(fromAyah, false);
                while (!Equals(nextVerse, toAyah))
                {
                    verses.Add(nextVerse);
                    nextVerse = GetNextAyah(nextVerse, false);
                }
                // Add last verse
                verses.Add(nextVerse);
            }
            return(verses);
        }
Exemple #28
0
 private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     if (!string.IsNullOrEmpty(tbPageNumber.Text))
     {
         int page = 0;
         if (int.TryParse(tbPageNumber.Text, NumberStyles.Integer,
                          CultureInfo.InvariantCulture, out page))
         {
             Page = page;
         }
     }
     else if (cbSurahs.SelectedIndex >= 0)
     {
         var ayah  = cbAyah.SelectedIndex + 1;
         var surah = cbSurahs.SelectedIndex + 1;
         Ayah = new QuranAyah(surah, ayah);
         Page = QuranUtils.GetPageFromAyah(Ayah);
     }
 }
 private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     if (!string.IsNullOrEmpty(tbPageNumber.Text))
     {
         int page = 0;
         if (int.TryParse(tbPageNumber.Text, NumberStyles.Integer, 
             CultureInfo.InvariantCulture, out page))
         {
             Page = page;
         }
     }
     else if (cbSurahs.SelectedIndex >= 0)
     {
         var ayah = cbAyah.SelectedIndex + 1;
         var surah = cbSurahs.SelectedIndex + 1;
         Ayah = new QuranAyah(surah, ayah);
         Page = QuranUtils.GetPageFromAyah(Ayah);
     }
 }
Exemple #30
0
        public static string GetFileName(QuranAyah ayah, ReciterItem reciter)
        {
            string fileName;

            if (reciter.IsGapless)
            {
                fileName = string.Format(reciter.GetFilePattern(), ayah.Surah);
            }
            else
            {
                if (ayah.Ayah == 0)
                {
                    fileName = string.Format(reciter.GetFilePattern(), 1, 1);
                }
                else
                {
                    fileName = string.Format(reciter.GetFilePattern(), ayah.Surah, ayah.Ayah);
                }
            }

            return(fileName);
        }
        private async Task ImageHoldingOrRightTapped(object sender, Func <UIElement, Point> getPosition)
        {
            if (sender != null)
            {
                if (!await FileUtils.HaveAyaPositionFile())
                {
                    await ViewModel.DownloadAyahPositionFile();
                }

                var cachedImage = sender as CachedImage;
                if (cachedImage == null)
                {
                    return;
                }

                QuranAyah ayah = await CachedImage.GetAyahFromGesture(getPosition(cachedImage.Image),
                                                                      ViewModel.CurrentPageNumber,
                                                                      radSlideView.ActualWidth);

                ShowContextMenu(ayah, null, getPosition(ThisPage));
            }
        }
Exemple #32
0
        private object getMatchedItem(QuranAyah ayah)
        {
            ICollection listboxItems = null;

            if (QuranApp.DetailsViewModel.CurrentPage == null ||
                (this.listBox.RealizedItems != null && this.listBox.RealizedItems.Length > 0))
            {
                listboxItems = this.listBox.RealizedItems;
            }
            else
            {
                listboxItems = QuranApp.DetailsViewModel.CurrentPage.Translations;
            }

            foreach (VerseViewModel item in listboxItems)
            {
                if (item.Surah == ayah.Surah && item.Ayah == ayah.Ayah)
                {
                    return(item);
                }
            }
            return(null);
        }
 public static bool IsBismillah(QuranAyah ayah)
 {
     if (ayah == null)
     {
         return(false);
     }
     if (ayah.Surah == Constants.SURA_TAWBA)
     {
         return(false);
     }
     if (ayah.Surah == Constants.SURA_FIRST && ayah.Ayah == 1)
     {
         return(true);
     }
     if (ayah.Ayah == 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public static string GetNotificationTitle(QuranAyah minVerse, QuranAyah maxVerse)
        {
            int minSura = minVerse.Surah;
            int maxSura = maxVerse.Surah;
            int maxAyah = maxVerse.Ayah;

            if (maxAyah == 0)
            {
                maxSura--;
                maxAyah = QuranUtils.GetSurahNumberOfAyah(maxSura);
            }

            string notificationTitle =
                QuranUtils.GetSurahName(minSura, true);

            if (minSura == maxSura)
            {
                if (minVerse.Ayah == maxAyah)
                {
                    notificationTitle += " (" + maxAyah + ")";
                }
                else
                {
                    notificationTitle += " (" + minVerse.Ayah +
                                         "-" + maxAyah + ")";
                }
            }
            else
            {
                notificationTitle += " (" + minVerse.Ayah +
                                     ") - " + QuranUtils.GetSurahName(maxSura, true) +
                                     " (" + maxAyah + ")";
            }

            return(notificationTitle);
        }
Exemple #35
0
 public static int GetPageFromAyah(QuranAyah ayah)
 {
     return GetPageFromAyah(ayah.Surah, ayah.Ayah);
 }
 public bool AddAyahBookmark(QuranAyah ayah)
 {
     return AddBookmark(ayah);
 }
Exemple #37
0
        public async void Load(string query)
        {
            if (this.IsLoading)
            {
                return;
            }

            this.IsLoading = true;
            var translation = SettingsUtils.Get <string>(Constants.PREF_ACTIVE_TRANSLATION);

            if (!string.IsNullOrEmpty(translation))
            {
                var translationFile = translation.Split('|')[0];

                try
                {
                    var translationVerses = new List <QuranAyah>();
                    var arabicVerses      = new List <ArabicAyah>();
                    var taskFactory       = new TaskFactory();

                    if (await FileUtils.FileExists(FileUtils.DatabaseFolder, translationFile))
                    {
                        using (var db = new QuranDatabaseHandler <QuranAyah>(Path.Combine(FileUtils.GetQuranDatabaseDirectory(), translationFile)))
                        {
                            translationVerses = await taskFactory.StartNew(() => db.Search(query));
                        }
                    }
                    using (var dbArabic = new QuranDatabaseHandler <ArabicAyah>(FileUtils.ArabicDatabase))
                    {
                        arabicVerses = await taskFactory.StartNew(() => dbArabic.Search(query));
                    }
                    this.SearchResults.Clear();

                    // Merging 2 results
                    int a           = 0;
                    int t           = 0;
                    var arabicVerse = new QuranAyah {
                        Surah = int.MaxValue, Ayah = int.MaxValue
                    };
                    var translationVerse = new QuranAyah {
                        Surah = int.MaxValue, Ayah = int.MaxValue
                    };
                    var verseToDisplay = new QuranAyah();
                    var comparer       = new AyahComparer();

                    while (a < arabicVerses.Count || t < translationVerses.Count)
                    {
                        if (a < arabicVerses.Count)
                        {
                            arabicVerse = arabicVerses[a];
                        }
                        else
                        {
                            arabicVerse = new QuranAyah {
                                Surah = int.MaxValue, Ayah = int.MaxValue
                            }
                        };

                        if (t < translationVerses.Count)
                        {
                            translationVerse = translationVerses[t];
                        }
                        else
                        {
                            translationVerse = new QuranAyah {
                                Surah = int.MaxValue, Ayah = int.MaxValue
                            }
                        };

                        if (comparer.Compare(arabicVerse, translationVerse) > 0)
                        {
                            verseToDisplay = translationVerse;
                            t++;
                        }
                        else if (comparer.Compare(arabicVerse, translationVerse) < 0)
                        {
                            verseToDisplay = arabicVerse;
                            a++;
                        }
                        else if (comparer.Compare(arabicVerse, translationVerse) == 0)
                        {
                            verseToDisplay = arabicVerse;
                            a++;
                            t++;
                        }

                        var verse = verseToDisplay;
                        var text  = TrimText(verse.Text, MaxPreviewCharacter);
                        this.SearchResults.Add(new ItemViewModel
                        {
                            Id =
                                string.Format("{0} ({1}:{2})", QuranUtils.GetSurahName(verse.Surah, false), verse.Surah,
                                              verse.Ayah),
                            Details      = text,
                            PageNumber   = QuranUtils.GetPageFromAyah(verse.Surah, verse.Ayah),
                            SelectedAyah = new QuranAyah(verse.Surah, verse.Ayah)
                        });
                    }
                    return;
                }
                catch (Exception ex)
                {
                    telemetry.TrackException(ex, new Dictionary <string, string> {
                        { "Scenario", "LoadingTranslations" }
                    });
                    this.SearchResults.Add(new ItemViewModel
                    {
                        Id           = "Error",
                        Details      = "Error performing translation",
                        PageNumber   = 1,
                        SelectedAyah = new QuranAyah()
                    });
                }
                finally
                {
                    IsLoading = false;
                }
            }
            await QuranApp.NativeProvider.ShowInfoMessageBox(Resources.no_translation_to_search);
        }
Exemple #38
0
 private static QuranAyah GetLastAyahToPlayForSura(QuranAyah startAyah)
 {
     int surah = startAyah.Surah;
     int lastAyah = QuranUtils.GetSurahNumberOfAyah(surah);
     return new QuranAyah(surah, lastAyah);
 }
Exemple #39
0
        private static QuranAyah GetLastAyahToPlayForJuz(QuranAyah startAyah)
        {
            var juz = QuranUtils.GetJuzFromAyah(startAyah.Surah, startAyah.Ayah);
            // If last juz - return last verse
            if (juz == Constants.JUZ2_COUNT)
                return new QuranAyah(Constants.SURA_LAST, 6);

            int[] endJuz = QuranUtils.QUARTERS[juz * 8];

            return new QuranAyah(endJuz[0], endJuz[1] - 1);
        }
Exemple #40
0
        private async Task UpdateSelectedAyah(QuranAyah ayahInfo)
        {
            if (ayahInfo == null)
            {
                canvas.Children.Clear();
            }
            else
            {
                try
                {
                    if (PageNumber != QuranUtils.GetPageFromAyah(ayahInfo))
                    {
                        return;
                    }

                    var ayahDb = await QuranApp.GetAyahInfoDatabase();

                    if (ayahDb != null)
                    {
                        int offsetToScrollTo = 0;
                        var bounds           = ayahDb.GetVerseBoundsCombined(ayahInfo.Surah, ayahInfo.Ayah);
                        if (bounds == null)
                        {
                            return;
                        }

                        // Wait for image to load
                        await _imageLoaded.WaitAsync();

                        // Reset any overlays
                        canvas.Children.Clear();
                        canvas.Opacity = 1.0;

                        foreach (var bound in bounds)
                        {
                            drawAyahBound(bound);
                            if (offsetToScrollTo == 0)
                            {
                                offsetToScrollTo = bound.MinY;
                            }
                        }

                        var adjustedScrollPoint = adjustPointRevert(new Point(1, offsetToScrollTo), LayoutRoot.ActualWidth);
                        LayoutRoot.ScrollToVerticalOffset(adjustedScrollPoint.Y); //Adjusting for ViewBox offset
                        if (QuranApp.DetailsViewModel.AudioPlayerState == AudioState.Playing)
                        {
                            canvasStoryboard.Seek(new TimeSpan(1));
                            canvasStoryboard.Stop();
                        }
                        else
                        {
                            canvasStoryboard.Begin();
                        }
                    }
                }
                catch (Exception ex)
                {
                    telemetry.TrackException(ex, new Dictionary <string, string> {
                        { "Scenario", "UpdateSelectedAyahInImage" }
                    });
                }
            }
        }
Exemple #41
0
        public static async Task<bool> DownloadGaplessRange(string urlString, string destination, QuranAyah fromAyah, QuranAyah toAyah)
        {
            var result = true;
            for (int i = fromAyah.Surah; i <= toAyah.Surah; i++)
            {
                string serverUrl = string.Format(CultureInfo.InvariantCulture, urlString, i);
                var localUrl = destination + "/";
                QuranApp.NativeProvider.Log("gapless asking to download " + serverUrl + " to " + localUrl);

                result = await QuranApp.DetailsViewModel.ActiveDownload.Download(serverUrl, localUrl, AppResources.loading_audio);
                if (!result)
                    break;
            }
            return result;
        }
        public async Task<string> GetAyahString(QuranAyah ayah)
        {
            if (ayah == null)
            {
                return null;
            }

            else if (ayah.Text != null)
            {
                return ayah.Text;
            }
            else
            {
                await DownloadArabicSearchFile();
                if (await FileUtils.HaveArabicSearchFile())
                {
                    try
                    {
                        using (var dbArabic = new QuranDatabaseHandler<ArabicAyah>(FileUtils.QURAN_ARABIC_DATABASE))
                        {
                            var ayahSurah = dbArabic.GetVerse(ayah.Surah, ayah.Ayah);
                            string ayahText = ayahSurah.Text;
                            return ayahText;
                        }
                    }
                    catch (Exception e)
                    {
                        telemetry.TrackException(e, new Dictionary<string, string> { { "Scenario", "OpenArabicDatabase" } });
                    }
                }
            }
            return null;
        }
 private void DataShareRequested(DataTransferManager sender, DataRequestedEventArgs args)
 {
     if (_ayahToShare != null)
     {
         args.Request.Data.Properties.Title = Core.Properties.Resources.share_ayah;
         if (_ayahToShare.Translation != null)
         {
             args.Request.Data.SetText(_ayahToShare.Translation);
         }
         else
         {
             args.Request.Data.SetText(_ayahToShare.Text);
         }
         _ayahToShare = null;
     }
 }
        public void PlayFromAyah(int startSura, int startAyah)
        {
            int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get<string>(Constants.PREF_ACTIVE_QARI));
            if (currentQari == -1)
                return;

            var lookaheadAmount = SettingsUtils.Get<AudioDownloadAmount>(Constants.PREF_DOWNLOAD_AMOUNT);
            var ayah = new QuranAyah(startSura, startAyah);
            var request = new AudioRequest(currentQari, ayah, lookaheadAmount);

            if (SettingsUtils.Get<bool>(Constants.PREF_PREFER_STREAMING))
            {
                PlayStreaming(request);
            }
            else
            {
                DownloadAndPlayAudioRequest(request);
            }
        }
        private async void AudioProvider_StateChanged(object sender, EventArgs e)
        {
            if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Stopped ||
                    QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Unknown ||
                QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Error)
            {
                await Task.Delay(500);
                // Check if still stopped
                if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Stopped ||
                    QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Unknown ||
                QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Error)
                {
                    AudioPlayerState = AudioState.Stopped;
                }
            }
            else if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Paused)
            {
                AudioPlayerState = AudioState.Paused;
            }
            else if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Playing)
            {
                AudioPlayerState = AudioState.Playing;

                var track = QuranApp.NativeProvider.AudioProvider.GetTrack();
                if (track != null && track.Tag != null)
                {
                    try
                    {
                        var request = new AudioRequest(track.Tag);
                        var pageNumber = QuranUtils.GetPageFromSurahAyah(request.CurrentAyah);
                        var oldPageIndex = CurrentPageIndex;
                        var newPageIndex = getIndexFromPageNumber(pageNumber);

                        CurrentPageIndex = newPageIndex;
                        if (oldPageIndex != newPageIndex)
                        {
                            await Task.Delay(500);
                        }
                        // If bismillah set to first ayah
                        if (request.CurrentAyah.Ayah == 0)
                            request.CurrentAyah.Ayah = 1;
                        SelectedAyah = request.CurrentAyah;
                    }
                    catch
                    {
                        // Bad track
                    }
                }
            }
        }
        public async Task<string> GetAyahString(QuranAyah ayah)
        {
            if (ayah == null)
            {
                return null;
            }

            else if (ayah.Text != null)
            {
                return ayah.Text;
            }
            else
            {
                await DownloadArabicSearchFile();
                if (FileUtils.HaveArabicSearchFile())
                {
                    try
                    {
                        using (var dbArabic = new QuranDatabaseHandler<ArabicAyah>(FileUtils.QURAN_ARABIC_DATABASE))
                        {
                            var ayahSurah = await new TaskFactory().StartNew(() => dbArabic.GetVerse(ayah.Surah, ayah.Ayah));
                            string ayahText = ayahSurah.Text;
                            return ayahText;
                        }
                    }
                    catch (Exception)
                    {
                        Debug.WriteLine("Ayah Text isn't found");
                        
                    }
                }
            }
            return null;
        }
        public async void CopyAyahToClipboard(QuranAyah ayah)
        {
            if (ayah == null)
                return;

            if (ayah.Translation != null)
            {
                QuranApp.NativeProvider.CopyToClipboard(ayah.Translation);
            }
            else if (ayah.Text != null)
            {
                QuranApp.NativeProvider.CopyToClipboard(ayah.Text);
            }
            else
            {
                await DownloadArabicSearchFile();
                if (FileUtils.HaveArabicSearchFile())
                {
                    try
                    {
                        using (var dbArabic = new QuranDatabaseHandler<ArabicAyah>(FileUtils.QURAN_ARABIC_DATABASE))
                        {
                            var ayahSurah =
                                await new TaskFactory().StartNew(() => dbArabic.GetVerse(ayah.Surah, ayah.Ayah));
                            QuranApp.NativeProvider.CopyToClipboard(ayahSurah.Text);
                        }
                    }
                    catch
                    {
                        //Not able to get Arabic text - skipping
                    }
                }
            }
        }
 private bool AddBookmark(QuranAyah ayah)
 {
     try
     {
         using (var adapter = new BookmarksDatabaseHandler())
         {
             if (ayah == null)
                 adapter.AddBookmarkIfNotExists(null, null, CurrentPageNumber);
             else
                 adapter.AddBookmarkIfNotExists(ayah.Surah, ayah.Ayah, CurrentPageNumber);
         }
         return true;
     }
     catch (Exception)
     {
         QuranApp.NativeProvider.Log("error creating bookmark");
         return false;
     }
 }
        public async Task PlayFromAyah(QuranAyah ayah)
        {
            int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get<string>(Constants.PREF_ACTIVE_QARI));
            if (currentQari == -1)
                return;

            var request = new QuranAudioTrack(currentQari, ayah, 
                FileUtils.ScreenInfo);

            // if necessary download aya position file
            await DownloadAyahPositionFile();

            QuranApp.NativeProvider.AudioProvider.SetTrack(request);
        }
        public static QuranAyah GetPreviousAyah(QuranAyah currentAyah, bool includeBismillah)
        {
            var ayahArray = GetPreviousAyah(new[] { currentAyah.Surah, currentAyah.Ayah }, includeBismillah);

            return(new QuranAyah(ayahArray[0], ayahArray[1]));
        }
Exemple #51
0
        public void IsValidWorks(bool expectedResult, int sura, int aya)
        {
            var suraAyah = new QuranAyah(sura, aya);

            Assert.Equal(expectedResult, QuranUtils.IsValid(suraAyah));
        }
 public static int GetPageFromAyah(QuranAyah ayah)
 {
     return(GetPageFromAyah(ayah.Surah, ayah.Ayah));
 }
Exemple #53
0
        public static string GetServerPathForAyah(QuranAyah ayah, ReciterItem reciter)
        {
            string fileName;
            if (reciter.IsGapless)
                fileName = string.Format(reciter.GetFilePattern(), ayah.Surah);
            else
                fileName = string.Format(reciter.GetFilePattern(), ayah.Surah, ayah.Ayah);

            return PathHelper.Combine(reciter.ServerUrl, fileName);
        }
 public bool AddAyahBookmark(QuranAyah ayah)
 {
     try
     {
         using (var adapter = new BookmarksDatabaseHandler())
         {
             if (ayah == null)
                 adapter.AddBookmarkIfNotExists(null, null, CurrentPageNumber);
             else
                 adapter.AddBookmarkIfNotExists(ayah.Surah, ayah.Ayah, CurrentPageNumber);
         }
         CurrentPageBookmarked = BookmarksDatabaseHandler.IsPageBookmarked(CurrentPageNumber);
         return true;
     }
     catch (Exception e)
     {
         QuranApp.NativeProvider.Log("error creating bookmark");
         telemetry.TrackException(e, new Dictionary<string, string> { { "Scenario", "AddBookmark" } });
         return false;
     }
 }
        public async void CopyAyahToClipboard(QuranAyah ayah)
        {
            if (ayah == null)
                return;

            if (ayah.Translation != null)
            {
                QuranApp.NativeProvider.CopyToClipboard(ayah.Translation);
            }
            else if (ayah.Text != null)
            {
                QuranApp.NativeProvider.CopyToClipboard(ayah.Text);
            }
            else
            {
                await DownloadArabicSearchFile();
                if (await FileUtils.HaveArabicSearchFile())
                {
                    try
                    {
                        using (var dbArabic = new QuranDatabaseHandler<ArabicAyah>(FileUtils.QURAN_ARABIC_DATABASE))
                        {
                            var ayahSurah =
                                await new TaskFactory().StartNew(() => dbArabic.GetVerse(ayah.Surah, ayah.Ayah));
                            QuranApp.NativeProvider.CopyToClipboard(ayahSurah.Text);
                        }
                    }
                    catch (Exception e)
                    {
                        telemetry.TrackException(e, new Dictionary<string, string> { { "Scenario", "OpenArabicDatabase" } });
                    }
                }
            }
        }
 public static string GetSurahAyahString(QuranAyah ayah)
 {
     return(GetSurahAyahString(ayah.Surah, ayah.Ayah));
 }
Exemple #57
0
        private static QuranAyah GetLastAyahToPlayForJuz(QuranAyah startAyah)
        {
            var juz = QuranUtils.GetJuzFromAyah(startAyah.Surah, startAyah.Ayah);

            return(QuranUtils.GetJuzLastAyah(juz));
        }
Exemple #58
0
 public static bool IsValid(QuranAyah selectedAyah)
 {
     if (selectedAyah == null || selectedAyah.Surah < 1 || selectedAyah.Surah > 114)
         return false;
     if (selectedAyah.Ayah < 0 || selectedAyah.Ayah > GetSurahNumberOfAyah(selectedAyah.Surah))
         return false;
     return true;
 }
 private void ShowContextMenu(QuranAyah data, UIElement target, Point offset)
 {
     ViewModel.SelectedAyah = data;
     var ayahContextMenu = this.Resources["AyahContextMenu"] as MenuFlyout;
     foreach (MenuFlyoutItem item in ayahContextMenu.Items)
     {
         item.DataContext = data;
     }
     ayahContextMenu.ShowAt(target, offset);
 }
Exemple #60
0
 public void IsValidWorks(bool expectedResult, int sura, int aya)
 {
     var suraAyah = new QuranAyah(sura, aya);
     Assert.Equal(expectedResult, QuranUtils.IsValid(suraAyah));
 }