Search in sources :

Example 1 with LocalTranslationDisplaySort

use of com.quran.labs.androidquran.common.LocalTranslationDisplaySort in project quran_android by quran.

the class PagerActivity method requestTranslationsList.

private void requestTranslationsList() {
    compositeDisposable.add(Single.fromCallable(() -> translationsDBAdapter.getTranslations()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSingleObserver<List<LocalTranslation>>() {

        @Override
        public void onSuccess(@NonNull List<LocalTranslation> translationList) {
            final List<LocalTranslation> sortedTranslations = new ArrayList<>(translationList);
            Collections.sort(sortedTranslations, new LocalTranslationDisplaySort());
            int items = sortedTranslations.size();
            String[] titles = new String[items];
            for (int i = 0; i < items; i++) {
                LocalTranslation item = sortedTranslations.get(i);
                if (!TextUtils.isEmpty(item.getTranslatorForeign())) {
                    titles[i] = item.getTranslatorForeign();
                } else if (!TextUtils.isEmpty(item.getTranslator())) {
                    titles[i] = item.getTranslator();
                } else {
                    titles[i] = item.getName();
                }
            }
            Set<String> currentActiveTranslationsFilesNames = quranSettings.getActiveTranslations();
            if (currentActiveTranslationsFilesNames.isEmpty() && items > 0) {
                currentActiveTranslationsFilesNames = new HashSet<>();
                for (int i = 0; i < items; i++) {
                    currentActiveTranslationsFilesNames.add(sortedTranslations.get(i).getFilename());
                }
            }
            activeTranslationsFilesNames = currentActiveTranslationsFilesNames;
            if (translationsSpinnerAdapter != null) {
                translationsSpinnerAdapter.updateItems(titles, sortedTranslations, activeTranslationsFilesNames);
            }
            translationNames = titles;
            translations = sortedTranslations;
            if (showingTranslation) {
                // Since translation items have changed, need to
                updateActionBarSpinner();
            }
        }

        @Override
        public void onError(@NonNull Throwable e) {
        }
    }));
}
Also used : DisposableSingleObserver(io.reactivex.rxjava3.observers.DisposableSingleObserver) LocalTranslation(com.quran.labs.androidquran.common.LocalTranslation) LocalTranslationDisplaySort(com.quran.labs.androidquran.common.LocalTranslationDisplaySort) ArrayList(java.util.ArrayList) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with LocalTranslationDisplaySort

use of com.quran.labs.androidquran.common.LocalTranslationDisplaySort in project quran_android by quran.

the class TranslationView method setVerses.

public void setVerses(@NonNull QuranDisplayData quranDisplayData, @NonNull LocalTranslation[] translations, @NonNull List<QuranAyahInfo> verses) {
    List<TranslationViewRow> rows = new ArrayList<>();
    int currentSura = -1;
    boolean wantTranslationHeaders = translations.length > 1;
    for (int i = 0, size = verses.size(); i < size; i++) {
        QuranAyahInfo verse = verses.get(i);
        int sura = verse.sura;
        if (sura != currentSura) {
            rows.add(new TranslationViewRow(TranslationViewRow.Type.SURA_HEADER, verse, quranDisplayData.getSuraName(getContext(), sura, true)));
            currentSura = sura;
        }
        if (verse.ayah == 1 && sura != 1 && sura != 9) {
            rows.add(new TranslationViewRow(TranslationViewRow.Type.BASMALLAH, verse));
        }
        rows.add(new TranslationViewRow(TranslationViewRow.Type.VERSE_NUMBER, verse));
        if (verse.arabicText != null) {
            rows.add(new TranslationViewRow(TranslationViewRow.Type.QURAN_TEXT, verse));
        }
        final LocalTranslation[] sortedTranslations = Arrays.copyOf(translations, translations.length);
        Arrays.sort(sortedTranslations, new LocalTranslationDisplaySort());
        for (int j = 0; j < sortedTranslations.length; j++) {
            final TranslationMetadata metadata = findText(verse.texts, sortedTranslations[j].getId());
            CharSequence text = metadata != null ? metadata.getText() : "";
            if (!TextUtils.isEmpty(text)) {
                if (wantTranslationHeaders) {
                    rows.add(new TranslationViewRow(TranslationViewRow.Type.TRANSLATOR, verse, sortedTranslations[j].getTranslatorName()));
                }
                rows.add(new TranslationViewRow(TranslationViewRow.Type.TRANSLATION_TEXT, verse, text, j, metadata == null ? null : metadata.getLink(), "ar".equals(sortedTranslations[j].getLanguageCode())));
            }
        }
        rows.add(new TranslationViewRow(TranslationViewRow.Type.SPACER, verse));
    }
    localTranslations = translations;
    translationAdapter.setData(rows);
    translationAdapter.notifyDataSetChanged();
}
Also used : QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) TranslationMetadata(com.quran.labs.androidquran.common.TranslationMetadata) LocalTranslation(com.quran.labs.androidquran.common.LocalTranslation) LocalTranslationDisplaySort(com.quran.labs.androidquran.common.LocalTranslationDisplaySort) ArrayList(java.util.ArrayList)

Aggregations

LocalTranslation (com.quran.labs.androidquran.common.LocalTranslation)2 LocalTranslationDisplaySort (com.quran.labs.androidquran.common.LocalTranslationDisplaySort)2 ArrayList (java.util.ArrayList)2 NonNull (androidx.annotation.NonNull)1 QuranAyahInfo (com.quran.labs.androidquran.common.QuranAyahInfo)1 TranslationMetadata (com.quran.labs.androidquran.common.TranslationMetadata)1 DisposableSingleObserver (io.reactivex.rxjava3.observers.DisposableSingleObserver)1 List (java.util.List)1