Search in sources :

Example 1 with SelectionIndicator

use of com.quran.data.model.selection.SelectionIndicator in project quran_android by quran.

the class PagerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    QuranApplication quranApp = (QuranApplication) getApplication();
    quranApp.refreshLocale(this, false);
    super.onCreate(savedInstanceState);
    // field injection
    getPagerActivityComponent().inject(this);
    bookmarksCache = new SparseBooleanArray();
    boolean shouldAdjustPageNumber = false;
    isDualPages = QuranUtils.isDualPages(this, quranScreenInfo);
    isSplitScreen = quranSettings.isQuranSplitWithTranslation();
    audioEventPresenterBridge = new AudioEventPresenterBridge(audioEventPresenter, suraAyah -> {
        onAudioPlaybackAyahChanged(suraAyah);
        return null;
    });
    readingEventPresenterBridge = new ReadingEventPresenterBridge(readingEventPresenter, () -> {
        onPageClicked();
        return null;
    }, ayahSelection -> {
        onAyahSelectionChanged(ayahSelection);
        return null;
    });
    // remove the window background to avoid overdraw. note that, per Romain's blog, this is
    // acceptable (as long as we don't set the background color to null in the theme, since
    // that is used to generate preview windows).
    getWindow().setBackgroundDrawable(null);
    numberOfPages = quranInfo.getNumberOfPages();
    numberOfPagesDual = quranInfo.getNumberOfPagesDual();
    int page = -1;
    isActionBarHidden = true;
    if (savedInstanceState != null) {
        Timber.d("non-null saved instance state!");
        page = savedInstanceState.getInt(LAST_READ_PAGE, -1);
        if (page != -1) {
            page = numberOfPages - page;
        }
        showingTranslation = savedInstanceState.getBoolean(LAST_READING_MODE_IS_TRANSLATION, false);
        if (savedInstanceState.containsKey(LAST_ACTIONBAR_STATE)) {
            isActionBarHidden = !savedInstanceState.getBoolean(LAST_ACTIONBAR_STATE);
        }
        boolean lastWasDualPages = savedInstanceState.getBoolean(LAST_WAS_DUAL_PAGES, isDualPages);
        shouldAdjustPageNumber = (lastWasDualPages != isDualPages);
        this.lastAudioRequest = savedInstanceState.getParcelable(LAST_AUDIO_REQUEST);
    } else {
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            page = numberOfPages - extras.getInt("page", Constants.PAGES_FIRST);
            showingTranslation = extras.getBoolean(EXTRA_JUMP_TO_TRANSLATION, showingTranslation);
            final int highlightedSura = extras.getInt(EXTRA_HIGHLIGHT_SURA, -1);
            final int highlightedAyah = extras.getInt(EXTRA_HIGHLIGHT_AYAH, -1);
            if (highlightedSura > -1 && highlightedAyah > -1) {
                readingEventPresenterBridge.setSelection(highlightedSura, highlightedAyah, true);
            }
        }
    }
    compositeDisposable = new CompositeDisposable();
    setContentView(R.layout.quran_page_activity_slider);
    audioStatusBar = findViewById(R.id.audio_area);
    audioStatusBar.setIsDualPageMode(quranScreenInfo.isDualPageMode());
    audioStatusBar.setQariList(audioUtils.getQariList(this));
    audioStatusBar.setAudioBarListener(this);
    audioBarParams = (ViewGroup.MarginLayoutParams) audioStatusBar.getLayoutParams();
    toolBarArea = findViewById(R.id.toolbar_area);
    translationsSpinner = findViewById(R.id.spinner);
    // this is the colored view behind the status bar on kitkat and above
    final View statusBarBackground = findViewById(R.id.status_bg);
    statusBarBackground.getLayoutParams().height = getStatusBarHeight();
    final Toolbar toolbar = findViewById(R.id.toolbar);
    if (quranSettings.isArabicNames() || QuranUtils.isRtl()) {
        // remove when we remove LTR from quran_page_activity's root
        ViewCompat.setLayoutDirection(toolbar, ViewCompat.LAYOUT_DIRECTION_RTL);
    }
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayShowHomeEnabled(true);
        ab.setDisplayHomeAsUpEnabled(true);
    }
    initAyahActionPanel();
    if (showingTranslation && translationNames != null) {
        updateActionBarSpinner();
    } else {
        updateActionBarTitle(numberOfPages - page);
    }
    lastPopupTime = System.currentTimeMillis();
    pagerAdapter = new QuranPageAdapter(getSupportFragmentManager(), isDualPages, showingTranslation, quranInfo, isSplitScreen, pageProviderFactoryProvider.providePageViewFactory(quranSettings.getPageType()));
    ayahToolBar = findViewById(R.id.ayah_toolbar);
    ayahToolBar.setFlavor(BuildConfig.FLAVOR);
    ayahToolBar.setLongPressLambda(charSequence -> {
        ToastCompat.makeText(PagerActivity.this, charSequence, Toast.LENGTH_SHORT).show();
        return null;
    });
    final NonRestoringViewPager nonRestoringViewPager = findViewById(R.id.quran_pager);
    nonRestoringViewPager.setIsDualPagesInLandscape(QuranUtils.isDualPagesInLandscape(this, quranScreenInfo));
    viewPager = nonRestoringViewPager;
    viewPager.setAdapter(pagerAdapter);
    ayahToolBar.setOnItemSelectedListener(new AyahMenuItemSelectionHandler());
    viewPager.addOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            final AyahSelection currentSelection = readingEventPresenter.currentAyahSelection();
            final SelectionIndicator selectionIndicator = AyahSelectionKt.selectionIndicator(currentSelection);
            final SuraAyah suraAyah = AyahSelectionKt.startSuraAyah(currentSelection);
            if (selectionIndicator != SelectionIndicator.None.INSTANCE && selectionIndicator != SelectionIndicator.ScrollOnly.INSTANCE && suraAyah != null) {
                final int startPage = quranInfo.getPageFromSuraAyah(suraAyah.sura, suraAyah.ayah);
                int barPos = quranInfo.getPositionFromPage(startPage, isDualPageVisible());
                if (position == barPos) {
                    // Swiping to next ViewPager page (i.e. prev quran page)
                    final SelectionIndicator updatedSelectionIndicator = SelectionIndicatorKt.withXScroll(selectionIndicator, -positionOffsetPixels);
                    readingEventPresenterBridge.withSelectionIndicator(updatedSelectionIndicator);
                } else if (position == barPos - 1 || position == barPos + 1) {
                    // Swiping to previous or next ViewPager page (i.e. next or previous quran page)
                    final SelectionIndicator updatedSelectionIndicator = SelectionIndicatorKt.withXScroll(selectionIndicator, viewPager.getWidth() - positionOffsetPixels);
                    readingEventPresenterBridge.withSelectionIndicator(updatedSelectionIndicator);
                } else {
                    readingEventPresenterBridge.clearSelectedAyah();
                }
            }
        }

        @Override
        public void onPageSelected(int position) {
            Timber.d("onPageSelected(): %d", position);
            final int page = quranInfo.getPageFromPosition(position, isDualPageVisible());
            if (quranSettings.shouldDisplayMarkerPopup()) {
                lastPopupTime = QuranDisplayHelper.displayMarkerPopup(PagerActivity.this, quranInfo, page, lastPopupTime);
                if (isDualPages) {
                    lastPopupTime = QuranDisplayHelper.displayMarkerPopup(PagerActivity.this, quranInfo, page - 1, lastPopupTime);
                }
            }
            if (!showingTranslation) {
                updateActionBarTitle(page);
            } else {
                refreshActionBarSpinner();
            }
            if (bookmarksCache.indexOfKey(page) < 0) {
                if (isDualPages && !isSplitScreen) {
                    if (bookmarksCache.indexOfKey(page - 1) < 0) {
                        checkIfPageIsBookmarked(page - 1, page);
                    }
                } else {
                    // we don't have the key
                    checkIfPageIsBookmarked(page);
                }
            } else {
                refreshBookmarksMenu();
            }
            // If we're more than 1 page away from ayah selection end ayah mode
            final SuraAyah suraAyah = getSelectionStart();
            if (suraAyah != null) {
                final int startPage = quranInfo.getPageFromSuraAyah(suraAyah.sura, suraAyah.ayah);
                int ayahPos = quranInfo.getPositionFromPage(startPage, isDualPageVisible());
                if (Math.abs(ayahPos - position) > 1) {
                    endAyahMode();
                }
            }
        }
    });
    setUiVisibilityListener();
    audioStatusBar.setVisibility(View.VISIBLE);
    toggleActionBarVisibility(true);
    if (shouldAdjustPageNumber) {
        // when going from two page per screen to one or vice versa, we adjust the page number,
        // such that the first page is always selected.
        int curPage = numberOfPages - page;
        if (isDualPageVisible()) {
            if (curPage % 2 != 0) {
                curPage++;
            }
            curPage = numberOfPagesDual - (curPage / 2);
        } else {
            if (curPage % 2 == 0) {
                curPage--;
            }
            curPage = numberOfPages - curPage;
        }
        page = curPage;
    } else if (isDualPageVisible()) {
        page = page / 2;
    }
    viewPager.setCurrentItem(page);
    // just got created, need to reconnect to service
    shouldReconnect = true;
    // enforce orientation lock
    if (quranSettings.isLockOrientation()) {
        int current = getResources().getConfiguration().orientation;
        if (quranSettings.isLandscapeOrientation()) {
            if (current == Configuration.ORIENTATION_PORTRAIT) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                return;
            }
        } else if (current == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            return;
        }
    }
    LocalBroadcastManager.getInstance(this).registerReceiver(audioReceiver, new IntentFilter(AudioService.AudioUpdateIntent.INTENT_NAME));
    downloadReceiver = new DefaultDownloadReceiver(this, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
    String action = QuranDownloadNotifier.ProgressIntent.INTENT_NAME;
    LocalBroadcastManager.getInstance(this).registerReceiver(downloadReceiver, new IntentFilter(action));
    downloadReceiver.setListener(this);
    defaultNavigationBarColor = getWindow().getNavigationBarColor();
    quranEventLogger.logAnalytics(isDualPages, showingTranslation, isSplitScreen);
}
Also used : AyahActionFragmentProvider(com.quran.mobile.di.AyahActionFragmentProvider) Bundle(android.os.Bundle) AUDIO_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.AUDIO_PAGE) NonNull(androidx.annotation.NonNull) OnPageChangeListener(androidx.viewpager.widget.ViewPager.OnPageChangeListener) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) AudioPresenter(com.quran.labs.androidquran.presenter.audio.AudioPresenter) QuranPageAdapter(com.quran.labs.androidquran.ui.helpers.QuranPageAdapter) ActionBar(androidx.appcompat.app.ActionBar) QuranReadingActivityComponent(com.quran.mobile.di.QuranReadingActivityComponent) PagerActivityModule(com.quran.labs.androidquran.di.module.activity.PagerActivityModule) QuranPageModule(com.quran.labs.androidquran.di.module.fragment.QuranPageModule) Handler(android.os.Handler) Fragment(androidx.fragment.app.Fragment) BuildConfig(com.quran.labs.androidquran.BuildConfig) TranslationsDBAdapter(com.quran.labs.androidquran.database.TranslationsDBAdapter) AyahSelectionKt(com.quran.data.model.selection.AyahSelectionKt) ContextCompat(androidx.core.content.ContextCompat) ViewCompat(androidx.core.view.ViewCompat) TabletFragment(com.quran.labs.androidquran.ui.fragment.TabletFragment) AyahSelection(com.quran.data.model.selection.AyahSelection) QuranPageExtrasComponent(com.quran.data.page.provider.di.QuranPageExtrasComponent) IntentFilter(android.content.IntentFilter) Set(java.util.Set) SearchView(androidx.appcompat.widget.SearchView) QuranScreenInfo(com.quran.labs.androidquran.util.QuranScreenInfo) HelpActivity(com.quran.labs.androidquran.HelpActivity) HapticFeedbackConstants(android.view.HapticFeedbackConstants) DisposableSingleObserver(io.reactivex.rxjava3.observers.DisposableSingleObserver) Nullable(androidx.annotation.Nullable) Message(android.os.Message) TranslationsSpinnerAdapter(com.quran.labs.androidquran.ui.util.TranslationsSpinnerAdapter) QuranSpinner(com.quran.labs.androidquran.view.QuranSpinner) SlidingUpPanelLayout(com.quran.labs.androidquran.view.SlidingUpPanelLayout) TAG_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.TAG_PAGE) Single(io.reactivex.rxjava3.core.Single) ViewPager(androidx.viewpager.widget.ViewPager) QuranDownloadService(com.quran.labs.androidquran.service.QuranDownloadService) QariItem(com.quran.labs.androidquran.common.audio.QariItem) AudioUtils(com.quran.labs.androidquran.util.AudioUtils) QuranDisplayData(com.quran.labs.androidquran.data.QuranDisplayData) BookmarkModel(com.quran.labs.androidquran.model.bookmark.BookmarkModel) ArrayList(java.util.ArrayList) QuranEventLogger(com.quran.labs.androidquran.presenter.data.QuranEventLogger) ReadingEventPresenterBridge(com.quran.labs.androidquran.bridge.ReadingEventPresenterBridge) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) QuranDataProvider(com.quran.labs.androidquran.data.QuranDataProvider) MenuInflater(android.view.MenuInflater) Observable(io.reactivex.rxjava3.core.Observable) Toast(android.widget.Toast) AudioEventPresenterBridge(com.quran.labs.androidquran.bridge.AudioEventPresenterBridge) Menu(android.view.Menu) QuranFileUtils(com.quran.labs.androidquran.util.QuranFileUtils) QuranPageExtrasComponentProvider(com.quran.data.page.provider.di.QuranPageExtrasComponentProvider) FragmentManager(androidx.fragment.app.FragmentManager) SearchActivity(com.quran.labs.androidquran.SearchActivity) ComponentName(android.content.ComponentName) TRANSLATION_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.TRANSLATION_PAGE) QuranDownloadNotifier(com.quran.labs.androidquran.service.util.QuranDownloadNotifier) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) QuranApplication(com.quran.labs.androidquran.QuranApplication) AudioRequest(com.quran.labs.androidquran.dao.audio.AudioRequest) DisposableObserver(io.reactivex.rxjava3.observers.DisposableObserver) PagerActivityComponent(com.quran.labs.androidquran.di.component.activity.PagerActivityComponent) ArrayAdapter(android.widget.ArrayAdapter) SparseBooleanArray(android.util.SparseBooleanArray) SharedPreferences(android.content.SharedPreferences) SuraAyah(com.quran.data.model.SuraAyah) Configuration(android.content.res.Configuration) AyahToolBar(com.quran.page.common.toolbar.AyahToolBar) QuranReadingActivityComponentProvider(com.quran.mobile.di.QuranReadingActivityComponentProvider) QuranPreferenceActivity(com.quran.labs.androidquran.QuranPreferenceActivity) IconPageIndicator(com.quran.labs.androidquran.view.IconPageIndicator) Constants(com.quran.labs.androidquran.data.Constants) ShareUtil(com.quran.labs.androidquran.util.ShareUtil) AddTagDialog(com.quran.labs.androidquran.ui.fragment.AddTagDialog) AyahSelectedListener(com.quran.labs.androidquran.ui.helpers.AyahSelectedListener) AyahToolBarInjector(com.quran.page.common.toolbar.di.AyahToolBarInjector) ActivityInfo(android.content.pm.ActivityInfo) R(com.quran.labs.androidquran.R) View(android.view.View) QuranAppUtils(com.quran.labs.androidquran.util.QuranAppUtils) PreferenceManager(android.preference.PreferenceManager) LocalTranslationDisplaySort(com.quran.labs.androidquran.common.LocalTranslationDisplaySort) QuranInfo(com.quran.data.core.QuranInfo) AudioService(com.quran.labs.androidquran.service.AudioService) LocalTranslation(com.quran.labs.androidquran.common.LocalTranslation) ReadingEventPresenter(com.quran.reading.common.ReadingEventPresenter) PageViewFactoryProvider(com.quran.page.common.factory.PageViewFactoryProvider) AudioStatusBar(com.quran.labs.androidquran.view.AudioStatusBar) QuranDisplayHelper(com.quran.labs.androidquran.ui.helpers.QuranDisplayHelper) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) ToastCompat(com.quran.labs.androidquran.ui.util.ToastCompat) Timber(timber.log.Timber) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) SelectionIndicatorKt(com.quran.data.model.selection.SelectionIndicatorKt) List(java.util.List) Pair(androidx.core.util.Pair) DefaultDownloadReceiver(com.quran.labs.androidquran.service.util.DefaultDownloadReceiver) Toolbar(androidx.appcompat.widget.Toolbar) TranslationFragment(com.quran.labs.androidquran.ui.fragment.TranslationFragment) SearchManager(android.app.SearchManager) RecentPagePresenter(com.quran.labs.androidquran.presenter.bookmark.RecentPagePresenter) Context(android.content.Context) ArabicDatabaseUtils(com.quran.labs.androidquran.model.translation.ArabicDatabaseUtils) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) JumpFragment(com.quran.labs.androidquran.ui.fragment.JumpFragment) ServiceIntentHelper(com.quran.labs.androidquran.service.util.ServiceIntentHelper) Intent(android.content.Intent) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) QuranUtils(com.quran.labs.androidquran.util.QuranUtils) MenuItem(android.view.MenuItem) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) TagBookmarkDialog(com.quran.labs.androidquran.ui.fragment.TagBookmarkDialog) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) SlidingPagerAdapter(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter) SelectionIndicator(com.quran.data.model.selection.SelectionIndicator) Completable(io.reactivex.rxjava3.core.Completable) QuranPage(com.quran.labs.androidquran.ui.helpers.QuranPage) TimeUnit(java.util.concurrent.TimeUnit) AyahTracker(com.quran.labs.androidquran.ui.helpers.AyahTracker) JumpDestination(com.quran.labs.androidquran.ui.helpers.JumpDestination) NonRestoringViewPager(androidx.viewpager.widget.NonRestoringViewPager) AudioEventPresenter(com.quran.reading.common.AudioEventPresenter) Collections(java.util.Collections) Resources(android.content.res.Resources) AudioEventPresenterBridge(com.quran.labs.androidquran.bridge.AudioEventPresenterBridge) OnPageChangeListener(androidx.viewpager.widget.ViewPager.OnPageChangeListener) SuraAyah(com.quran.data.model.SuraAyah) QuranApplication(com.quran.labs.androidquran.QuranApplication) NonRestoringViewPager(androidx.viewpager.widget.NonRestoringViewPager) SparseBooleanArray(android.util.SparseBooleanArray) QuranPageAdapter(com.quran.labs.androidquran.ui.helpers.QuranPageAdapter) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar) IntentFilter(android.content.IntentFilter) SelectionIndicator(com.quran.data.model.selection.SelectionIndicator) Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) AyahSelection(com.quran.data.model.selection.AyahSelection) Intent(android.content.Intent) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) ReadingEventPresenterBridge(com.quran.labs.androidquran.bridge.ReadingEventPresenterBridge) DefaultDownloadReceiver(com.quran.labs.androidquran.service.util.DefaultDownloadReceiver) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable)

Example 2 with SelectionIndicator

use of com.quran.data.model.selection.SelectionIndicator in project quran_android by quran.

the class PagerActivity method onAyahSelectionChanged.

private void onAyahSelectionChanged(AyahSelection ayahSelection) {
    final boolean haveSelection = ayahSelection != AyahSelection.None.INSTANCE;
    final SelectionIndicator currentSelection = AyahSelectionKt.selectionIndicator(ayahSelection);
    if (currentSelection instanceof SelectionIndicator.None && haveSelection) {
        viewPager.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    }
    if (haveSelection) {
        final SuraAyah startPosition = startPosition(ayahSelection);
        updateLocalTranslations(startPosition);
    } else {
        endAyahMode();
    }
}
Also used : SelectionIndicator(com.quran.data.model.selection.SelectionIndicator) SuraAyah(com.quran.data.model.SuraAyah)

Example 3 with SelectionIndicator

use of com.quran.data.model.selection.SelectionIndicator in project quran_android by quran.

the class QuranPageFragment method onScrollChanged.

@Override
public void onScrollChanged(float y) {
    final AyahSelection selection = readingEventPresenter.currentAyahSelection();
    if (!(selection instanceof AyahSelection.None)) {
        final SelectionIndicator selectionIndicator = AyahSelectionKt.selectionIndicator(selection);
        final SelectionIndicator updatedIndicator = SelectionIndicatorKt.withYScroll(selectionIndicator, -y);
        final AyahSelection updatedSelection = AyahSelectionKt.withSelectionIndicator(selection, updatedIndicator);
        readingEventPresenter.onAyahSelection(updatedSelection);
    }
}
Also used : SelectionIndicator(com.quran.data.model.selection.SelectionIndicator) AyahSelection(com.quran.data.model.selection.AyahSelection)

Aggregations

SelectionIndicator (com.quran.data.model.selection.SelectionIndicator)2 ProgressDialog (android.app.ProgressDialog)1 SearchManager (android.app.SearchManager)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 ActivityInfo (android.content.pm.ActivityInfo)1 Configuration (android.content.res.Configuration)1 Resources (android.content.res.Resources)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Message (android.os.Message)1 PreferenceManager (android.preference.PreferenceManager)1 TextUtils (android.text.TextUtils)1 SparseBooleanArray (android.util.SparseBooleanArray)1 HapticFeedbackConstants (android.view.HapticFeedbackConstants)1