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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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;
         }
     }
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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]);
        }
Exemplo n.º 6
0
        public RepeatManager(RepeatInfo info, QuranAyah firstAyah, int currentIteration)
        {
            if (firstAyah == null)
                throw new ArgumentNullException("firstAyah");

            RepeatInfo = info ?? new RepeatInfo();

            Counter = currentIteration;

            FirstAyah = firstAyah;
            GenerateLastAyah();
        }
Exemplo n.º 7
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);
     }
 }
Exemplo n.º 8
0
 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);
     }
 }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
        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;
        }
Exemplo n.º 11
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);
     }
 }
Exemplo n.º 12
0
 public static int GetPageFromAyah(QuranAyah ayah)
 {
     return GetPageFromAyah(ayah.Surah, ayah.Ayah);
 }
Exemplo n.º 13
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;
     }
 }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        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
                    }
                }
            }
        }
Exemplo n.º 16
0
        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
                    }
                }
            }
        }
Exemplo n.º 17
0
        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;
        }
Exemplo n.º 18
0
 public bool AddAyahBookmark(QuranAyah ayah)
 {
     return AddBookmark(ayah);
 }
Exemplo n.º 19
0
 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;
     }
 }
Exemplo n.º 20
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;
 }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
 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;
     }
 }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
 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);
 }
Exemplo n.º 25
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;
        }
Exemplo n.º 26
0
        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" } });
                    }
                }
            }
        }
Exemplo n.º 27
0
 private static QuranAyah GetLastAyahToPlayForSura(QuranAyah startAyah)
 {
     int surah = startAyah.Surah;
     int lastAyah = QuranUtils.GetSurahNumberOfAyah(surah);
     return new QuranAyah(surah, lastAyah);
 }
Exemplo n.º 28
0
        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;
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
 public void IsValidWorks(bool expectedResult, int sura, int aya)
 {
     var suraAyah = new QuranAyah(sura, aya);
     Assert.Equal(expectedResult, QuranUtils.IsValid(suraAyah));
 }