Search in sources :

Example 11 with SuraAyah

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

the class PagerActivity method showAyahModeRangeHighlights.

private void showAyahModeRangeHighlights() {
    // Determine the start and end of the selection
    final int startPage = quranInfo.getPageFromSuraAyah(start.sura, start.ayah);
    final int endingPage = quranInfo.getPageFromSuraAyah(end.sura, end.ayah);
    int minPage = Math.min(startPage, endingPage);
    int maxPage = Math.max(startPage, endingPage);
    SuraAyah start = SuraAyah.min(this.start, end);
    SuraAyah end = SuraAyah.max(this.start, this.end);
    // Iterate from beginning to end
    for (int i = minPage; i <= maxPage; i++) {
        QuranPage fragment = pagerAdapter.getFragmentIfExistsForPage(i);
        if (fragment != null) {
            Set<String> ayahKeys = quranInfo.getAyahKeysOnPage(i, start, end);
            fragment.getAyahTracker().highlightAyat(i, ayahKeys, HighlightType.SELECTION);
        }
    }
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah) QuranPage(com.quran.labs.androidquran.ui.helpers.QuranPage)

Example 12 with SuraAyah

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

the class PagerActivity method playAudioRequest.

private void playAudioRequest(@Nullable DownloadAudioRequest request) {
    if (request == null) {
        audioStatusBar.switchMode(AudioStatusBar.STOPPED_MODE);
        return;
    }
    boolean needsPermission = needsPermissionToDownloadOver3g;
    if (needsPermission) {
        if (QuranUtils.isOnWifiNetwork(this)) {
            Timber.d("on wifi, don't need permission for download...");
            needsPermission = false;
        }
    }
    Timber.d("seeing if we can play audio request...");
    if (!quranFileUtils.haveAyaPositionFile(this)) {
        if (needsPermission) {
            audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
            return;
        }
        if (isActionBarHidden) {
            toggleActionBar();
        }
        audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
        String url = quranFileUtils.getAyaPositionFileUrl();
        String destination = quranFileUtils.getQuranDatabaseDirectory(this);
        // start the download
        String notificationTitle = getString(R.string.highlighting_database);
        Intent intent = ServiceIntentHelper.getDownloadIntent(this, url, destination, notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
        startService(intent);
    } else if (audioUtils.shouldDownloadGaplessDatabase(request)) {
        Timber.d("need to download gapless database...");
        if (needsPermission) {
            audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
            return;
        }
        if (isActionBarHidden) {
            toggleActionBar();
        }
        audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
        String url = audioUtils.getGaplessDatabaseUrl(request);
        String destination = request.getLocalPath();
        // start the download
        String notificationTitle = getString(R.string.timing_database);
        Intent intent = ServiceIntentHelper.getDownloadIntent(this, url, destination, notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
        startService(intent);
    } else if (audioUtils.haveAllFiles(request)) {
        if (!audioUtils.shouldDownloadBasmallah(request)) {
            Timber.d("have all files, playing!");
            play(request);
            lastAudioDownloadRequest = null;
        } else {
            Timber.d("should download basmalla...");
            if (needsPermission) {
                audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
                return;
            }
            SuraAyah firstAyah = new SuraAyah(1, 1);
            String qariUrl = audioUtils.getQariUrl(request.getQariItem());
            audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
            if (isActionBarHidden) {
                toggleActionBar();
            }
            String notificationTitle = quranInfo.getNotificationTitle(this, firstAyah, firstAyah, request.isGapless());
            Intent intent = ServiceIntentHelper.getDownloadIntent(this, qariUrl, request.getLocalPath(), notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
            intent.putExtra(QuranDownloadService.EXTRA_START_VERSE, firstAyah);
            intent.putExtra(QuranDownloadService.EXTRA_END_VERSE, firstAyah);
            startService(intent);
        }
    } else {
        if (needsPermission) {
            audioStatusBar.switchMode(AudioStatusBar.PROMPT_DOWNLOAD_MODE);
            return;
        }
        if (isActionBarHidden) {
            toggleActionBar();
        }
        audioStatusBar.switchMode(AudioStatusBar.DOWNLOADING_MODE);
        String notificationTitle = quranInfo.getNotificationTitle(this, request.getMinAyah(), request.getMaxAyah(), request.isGapless());
        String qariUrl = audioUtils.getQariUrl(request.getQariItem());
        Timber.d("need to start download: %s", qariUrl);
        // start service
        Intent intent = ServiceIntentHelper.getDownloadIntent(this, qariUrl, request.getLocalPath(), notificationTitle, AUDIO_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
        intent.putExtra(QuranDownloadService.EXTRA_START_VERSE, request.getMinAyah());
        intent.putExtra(QuranDownloadService.EXTRA_END_VERSE, request.getMaxAyah());
        intent.putExtra(QuranDownloadService.EXTRA_IS_GAPLESS, request.isGapless());
        startService(intent);
    }
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah) Intent(android.content.Intent)

Example 13 with SuraAyah

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

the class PagerActivity method toggleBookmark.

private void toggleBookmark(final Integer sura, final Integer ayah, final int page) {
    compositeDisposable.add(bookmarkModel.toggleBookmarkObservable(sura, ayah, page).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSingleObserver<Boolean>() {

        @Override
        public void onSuccess(Boolean isBookmarked) {
            if (sura == null || ayah == null) {
                // page bookmark
                bookmarksCache.put(page, isBookmarked);
                supportInvalidateOptionsMenu();
            } else {
                // ayah bookmark
                SuraAyah suraAyah = new SuraAyah(sura, ayah);
                updateAyahBookmark(suraAyah, isBookmarked, true);
            }
        }

        @Override
        public void onError(Throwable e) {
        }
    }));
}
Also used : DisposableSingleObserver(io.reactivex.observers.DisposableSingleObserver) SuraAyah(com.quran.labs.androidquran.data.SuraAyah)

Example 14 with SuraAyah

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

the class PagerActivity method nextAyah.

public void nextAyah() {
    if (end != null) {
        final int ayat = quranInfo.getNumAyahs(end.sura);
        final SuraAyah s;
        if (end.ayah + 1 <= ayat) {
            s = new SuraAyah(end.sura, end.ayah + 1);
        } else if (end.sura < 114) {
            s = new SuraAyah(end.sura + 1, 1);
        } else {
            return;
        }
        selectAyah(s);
    }
}
Also used : SuraAyah(com.quran.labs.androidquran.data.SuraAyah)

Example 15 with SuraAyah

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

the class PagerActivity method playStreaming.

private void playStreaming(SuraAyah ayah, SuraAyah end, int page, QariItem item, int verseRepeat, int rangeRepeat, boolean enforceRange) {
    String qariUrl = audioUtils.getQariUrl(item);
    String dbFile = audioUtils.getQariDatabasePathIfGapless(this, item);
    if (!TextUtils.isEmpty(dbFile)) {
        // gapless audio is "download only"
        lastAudioDownloadRequest = getAudioDownloadRequest(ayah, end, page, item, verseRepeat, rangeRepeat, enforceRange);
        playAudioRequest(lastAudioDownloadRequest);
        return;
    }
    final SuraAyah ending;
    if (end != null) {
        ending = end;
    } else {
        // this won't be enforced unless the user sets a range
        // repeat, but we set it to a sane default anyway.
        ending = audioUtils.getLastAyahToPlay(ayah, page, quranSettings.getPreferredDownloadAmount(), isDualPages);
    }
    AudioRequest request = new StreamingAudioRequest(qariUrl, ayah, quranInfo.getNumAyahs(ayah.sura));
    request.setPlayBounds(ayah, ending);
    request.setEnforceBounds(enforceRange);
    request.setRangeRepeatCount(rangeRepeat);
    request.setVerseRepeatCount(verseRepeat);
    play(request);
    audioStatusBar.switchMode(AudioStatusBar.PLAYING_MODE);
    audioStatusBar.setRepeatCount(verseRepeat);
}
Also used : StreamingAudioRequest(com.quran.labs.androidquran.service.util.StreamingAudioRequest) DownloadAudioRequest(com.quran.labs.androidquran.service.util.DownloadAudioRequest) AudioRequest(com.quran.labs.androidquran.service.util.AudioRequest) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) StreamingAudioRequest(com.quran.labs.androidquran.service.util.StreamingAudioRequest)

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