Search in sources :

Example 1 with SuraAyah

use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.

the class ImageAyahUtils method getAyahFromKey.

private static SuraAyah getAyahFromKey(String key) {
    String[] parts = key.split(":", -1);
    SuraAyah result = null;
    if (parts.length == 2) {
        try {
            int sura = Integer.parseInt(parts[0]);
            int ayah = Integer.parseInt(parts[1]);
            result = new SuraAyah(sura, ayah);
        } catch (Exception e) {
        // no op
        }
    }
    return result;
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah)

Example 2 with SuraAyah

use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.

the class AudioUtilsTest method testGetLastAyahWithNewSurahOnNextPageForMadani.

@Test
public void testGetLastAyahWithNewSurahOnNextPageForMadani() throws Exception {
    PageProvider pageProviderMock = Mockito.mock(PageProvider.class);
    when(pageProviderMock.getDataSource()).thenReturn(new MadaniDataSource());
    QuranInfo quranInfoMock = new QuranInfo(pageProviderMock);
    AudioUtils audioUtils = new AudioUtils(quranInfoMock, null);
    SuraAyah lastAyah = audioUtils.getLastAyahToPlay(new SuraAyah(109, 1), 603, 1, false);
    assertTrue(lastAyah.ayah == 5);
    assertTrue(lastAyah.sura == 111);
}
Also used : PageProvider(com.quran.data.source.PageProvider) MadaniDataSource(com.quran.data.pageinfo.common.MadaniDataSource) QuranInfo(com.quran.labs.androidquran.data.QuranInfo) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) Test(org.junit.Test)

Example 3 with SuraAyah

use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.

the class PagerActivity method playFromAyah.

private void playFromAyah(int page, int startSura, int startAyah, boolean force) {
    final SuraAyah start = new SuraAyah(startSura, startAyah);
    playFromAyah(start, null, page, 0, 0, false, force);
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah)

Example 4 with SuraAyah

use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.

the class PagerActivity method getAudioDownloadRequest.

@Nullable
private DownloadAudioRequest getAudioDownloadRequest(SuraAyah ayah, SuraAyah ending, int page, @NonNull QariItem item, int verseRepeat, int rangeRepeat, boolean enforceBounds) {
    final SuraAyah endAyah;
    if (ending != null) {
        endAyah = ending;
    } else {
        endAyah = audioUtils.getLastAyahToPlay(ayah, page, quranSettings.getPreferredDownloadAmount(), isDualPages);
    }
    String baseUri = audioUtils.getLocalQariUrl(this, item);
    if (endAyah == null || baseUri == null) {
        return null;
    }
    String dbFile = audioUtils.getQariDatabasePathIfGapless(this, item);
    String fileUrl;
    if (TextUtils.isEmpty(dbFile)) {
        fileUrl = baseUri + File.separator + "%d" + File.separator + "%d" + audioUtils.AUDIO_EXTENSION;
    } else {
        fileUrl = baseUri + File.separator + "%03d" + audioUtils.AUDIO_EXTENSION;
    }
    DownloadAudioRequest request = new DownloadAudioRequest(fileUrl, ayah, item, baseUri, quranInfo.getNumAyahs(ayah.sura));
    request.setGaplessDatabaseFilePath(dbFile);
    request.setPlayBounds(ayah, endAyah);
    request.setEnforceBounds(enforceBounds);
    request.setRangeRepeatCount(rangeRepeat);
    request.setVerseRepeatCount(verseRepeat);
    return request;
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah) DownloadAudioRequest(com.quran.labs.androidquran.service.util.DownloadAudioRequest) Nullable(android.support.annotation.Nullable)

Example 5 with SuraAyah

use of com.quran.labs.androidquran.data.SuraAyah in project quran_android by quran.

the class AyahPlaybackFragment method apply.

private void apply() {
    final Context context = getActivity();
    if (context instanceof PagerActivity) {
        final SuraAyah start = new SuraAyah(startSuraSpinner.getSelectedItemPosition() + 1, startAyahSpinner.getSelectedItemPosition() + 1);
        final SuraAyah ending = new SuraAyah(endingSuraSpinner.getSelectedItemPosition() + 1, endingAyahSpinner.getSelectedItemPosition() + 1);
        // force the correct order
        final SuraAyah currentStart;
        final SuraAyah currentEnding;
        if (ending.after(start)) {
            currentStart = start;
            currentEnding = ending;
        } else {
            currentStart = ending;
            currentEnding = start;
        }
        final int page = quranInfo.getPageFromSuraAyah(currentStart.sura, currentStart.ayah);
        final int verseRepeat = positionToRepeat(repeatVerseSpinner.getSelectedItemPosition());
        final int rangeRepeat = positionToRepeat(repeatRangeSpinner.getSelectedItemPosition());
        final boolean enforceRange = restrictToRange.isChecked();
        boolean updatedRange = false;
        final PagerActivity pagerActivity = (PagerActivity) context;
        if (!currentStart.equals(decidedStart) || !currentEnding.equals(decidedEnd)) {
            // different range or not playing, so make a new request
            updatedRange = true;
            if (this.start != null) {
                final SuraAyah starting = decidedStart == null ? this.start : decidedStart;
                final int origPage = quranInfo.getPageFromSuraAyah(starting.sura, starting.ayah);
                if (page != origPage) {
                    pagerActivity.highlightAyah(currentStart.sura, currentStart.ayah, HighlightType.AUDIO);
                }
            }
            pagerActivity.playFromAyah(currentStart, currentEnding, page, verseRepeat, rangeRepeat, enforceRange, true);
        } else if (shouldEnforce != enforceRange || rangeRepeatCount != rangeRepeat || verseRepeatCount != verseRepeat) {
            // can just update repeat settings
            if (!pagerActivity.updatePlayOptions(rangeRepeat, verseRepeat, enforceRange)) {
                // audio stopped in the process, let's start it
                pagerActivity.playFromAyah(currentStart, currentEnding, page, verseRepeat, rangeRepeat, enforceRange, true);
            }
        }
        pagerActivity.endAyahMode();
        if (updatedRange) {
            pagerActivity.toggleActionBarVisibility(true);
        }
    }
}
Also used : Context(android.content.Context) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) PagerActivity(com.quran.labs.androidquran.ui.PagerActivity)

Aggregations

SuraAyah (com.quran.labs.androidquran.data.SuraAyah)20 Intent (android.content.Intent)3 Context (android.content.Context)2 AudioRequest (com.quran.labs.androidquran.service.util.AudioRequest)2 DownloadAudioRequest (com.quran.labs.androidquran.service.util.DownloadAudioRequest)2 PagerActivity (com.quran.labs.androidquran.ui.PagerActivity)2 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 MadaniDataSource (com.quran.data.pageinfo.common.MadaniDataSource)1 PageProvider (com.quran.data.source.PageProvider)1 QuranText (com.quran.labs.androidquran.common.QuranText)1 QuranInfo (com.quran.labs.androidquran.data.QuranInfo)1 SuraAyahIterator (com.quran.labs.androidquran.data.SuraAyahIterator)1 NotificationDetails (com.quran.labs.androidquran.service.util.QuranDownloadNotifier.NotificationDetails)1 ProgressIntent (com.quran.labs.androidquran.service.util.QuranDownloadNotifier.ProgressIntent)1 StreamingAudioRequest (com.quran.labs.androidquran.service.util.StreamingAudioRequest)1 QuranPage (com.quran.labs.androidquran.ui.helpers.QuranPage)1 DisposableSingleObserver (io.reactivex.observers.DisposableSingleObserver)1 File (java.io.File)1 Test (org.junit.Test)1