Search in sources :

Example 1 with VerseRange

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

the class BaseTranslationPresenterTest method testCombineAyahDataOneVerseNoArabic.

@Test
public void testCombineAyahDataOneVerseNoArabic() {
    VerseRange verseRange = new VerseRange(1, 1, 1, 1, 1);
    List<QuranText> arabic = Collections.emptyList();
    List<QuranAyahInfo> info = presenter.combineAyahData(verseRange, arabic, Collections.singletonList(Collections.singletonList(new QuranText(1, 1, "translation"))));
    assertThat(info).hasSize(1);
    QuranAyahInfo first = info.get(0);
    assertThat(first.sura).isEqualTo(1);
    assertThat(first.ayah).isEqualTo(1);
    assertThat(first.texts).hasSize(1);
    assertThat(first.arabicText).isNull();
    assertThat(first.texts.get(0)).isEqualTo("translation");
}
Also used : VerseRange(com.quran.labs.androidquran.data.VerseRange) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) QuranText(com.quran.labs.androidquran.common.QuranText) Test(org.junit.Test)

Example 2 with VerseRange

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

the class BaseTranslationPresenterTest method testCombineAyahDataOneVerse.

@Test
public void testCombineAyahDataOneVerse() {
    VerseRange verseRange = new VerseRange(1, 1, 1, 1, 1);
    List<QuranText> arabic = Collections.singletonList(new QuranText(1, 1, "first ayah"));
    List<QuranAyahInfo> info = presenter.combineAyahData(verseRange, arabic, Collections.singletonList(Collections.singletonList(new QuranText(1, 1, "translation"))));
    assertThat(info).hasSize(1);
    QuranAyahInfo first = info.get(0);
    assertThat(first.sura).isEqualTo(1);
    assertThat(first.ayah).isEqualTo(1);
    assertThat(first.texts).hasSize(1);
    assertThat(first.arabicText).isEqualTo("first ayah");
    assertThat(first.texts.get(0)).isEqualTo("translation");
}
Also used : VerseRange(com.quran.labs.androidquran.data.VerseRange) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) QuranText(com.quran.labs.androidquran.common.QuranText) Test(org.junit.Test)

Example 3 with VerseRange

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

the class BaseTranslationPresenterTest method testCombineAyahDataOneVerseEmpty.

@Test
public void testCombineAyahDataOneVerseEmpty() {
    VerseRange verseRange = new VerseRange(1, 1, 1, 1, 1);
    List<QuranText> arabic = Collections.emptyList();
    List<QuranAyahInfo> info = presenter.combineAyahData(verseRange, arabic, Collections.emptyList());
    assertThat(info).hasSize(0);
}
Also used : VerseRange(com.quran.labs.androidquran.data.VerseRange) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) QuranText(com.quran.labs.androidquran.common.QuranText) Test(org.junit.Test)

Example 4 with VerseRange

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

the class AyahTranslationFragment method refreshView.

@Override
public void refreshView() {
    if (start == null || end == null) {
        return;
    }
    final Activity activity = getActivity();
    if (activity instanceof PagerActivity) {
        PagerActivity pagerActivity = (PagerActivity) activity;
        if (translations == null || translations.size() == 0) {
            translations = pagerActivity.getTranslations();
        }
        if (translations == null || translations.size() == 0) {
            progressBar.setVisibility(View.GONE);
            emptyState.setVisibility(View.VISIBLE);
            translationControls.setVisibility(View.GONE);
            return;
        }
        if (translationAdapter == null) {
            Set<String> activeTranslations = pagerActivity.getActiveTranslations();
            if (activeTranslations == null) {
                activeTranslations = quranSettings.getActiveTranslations();
            }
            translationAdapter = new TranslationsSpinnerAdapter(activity, R.layout.translation_ab_spinner_item, pagerActivity.getTranslationNames(), translations, activeTranslations, selectedItems -> {
                quranSettings.setActiveTranslations(selectedItems);
                refreshView();
            });
            translator.setAdapter(translationAdapter);
        }
        if (start.equals(end)) {
            translationControls.setVisibility(View.VISIBLE);
        } else {
            translationControls.setVisibility(View.GONE);
        }
        final int verses = 1 + Math.abs(quranInfo.getAyahId(start.sura, start.ayah) - quranInfo.getAyahId(end.sura, end.ayah));
        VerseRange verseRange = new VerseRange(start.sura, start.ayah, end.sura, end.ayah, verses);
        translationPresenter.refresh(verseRange);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) LayoutInflater(android.view.LayoutInflater) LocalTranslation(com.quran.labs.androidquran.common.LocalTranslation) QuranSpinner(com.quran.labs.androidquran.widgets.QuranSpinner) Set(java.util.Set) InlineTranslationPresenter(com.quran.labs.androidquran.presenter.translation.InlineTranslationPresenter) NonNull(android.support.annotation.NonNull) ViewGroup(android.view.ViewGroup) InlineTranslationView(com.quran.labs.androidquran.widgets.InlineTranslationView) Inject(javax.inject.Inject) VerseRange(com.quran.labs.androidquran.data.VerseRange) List(java.util.List) QuranAyahInfo(com.quran.labs.androidquran.common.QuranAyahInfo) TranslationsSpinnerAdapter(com.quran.labs.androidquran.ui.util.TranslationsSpinnerAdapter) QuranInfo(com.quran.labs.androidquran.data.QuranInfo) R(com.quran.labs.androidquran.R) View(android.view.View) Button(android.widget.Button) PagerActivity(com.quran.labs.androidquran.ui.PagerActivity) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) Activity(android.app.Activity) VerseRange(com.quran.labs.androidquran.data.VerseRange) TranslationsSpinnerAdapter(com.quran.labs.androidquran.ui.util.TranslationsSpinnerAdapter) PagerActivity(com.quran.labs.androidquran.ui.PagerActivity) Activity(android.app.Activity) PagerActivity(com.quran.labs.androidquran.ui.PagerActivity)

Example 5 with VerseRange

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

the class BaseTranslationPresenterTest method testEnsureProperTranslations.

@Test
public void testEnsureProperTranslations() {
    VerseRange verseRange = new VerseRange(1, 1, 1, 2, 2);
    List<QuranText> text = new ArrayList<>();
    text.add(new QuranText(1, 1, "bismillah"));
    text = presenter.ensureProperTranslations(verseRange, text);
    assertThat(text).hasSize(2);
    QuranText first = text.get(0);
    assertThat(first.sura).isEqualTo(1);
    assertThat(first.ayah).isEqualTo(1);
    assertThat(first.text).isEqualTo("bismillah");
    QuranText second = text.get(1);
    assertThat(second.sura).isEqualTo(1);
    assertThat(second.ayah).isEqualTo(2);
    assertThat(second.text).isEmpty();
}
Also used : VerseRange(com.quran.labs.androidquran.data.VerseRange) ArrayList(java.util.ArrayList) QuranText(com.quran.labs.androidquran.common.QuranText) Test(org.junit.Test)

Aggregations

VerseRange (com.quran.labs.androidquran.data.VerseRange)6 QuranAyahInfo (com.quran.labs.androidquran.common.QuranAyahInfo)5 QuranText (com.quran.labs.androidquran.common.QuranText)5 Test (org.junit.Test)5 Activity (android.app.Activity)1 Context (android.content.Context)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 ProgressBar (android.widget.ProgressBar)1 R (com.quran.labs.androidquran.R)1 LocalTranslation (com.quran.labs.androidquran.common.LocalTranslation)1 QuranInfo (com.quran.labs.androidquran.data.QuranInfo)1 InlineTranslationPresenter (com.quran.labs.androidquran.presenter.translation.InlineTranslationPresenter)1 PagerActivity (com.quran.labs.androidquran.ui.PagerActivity)1 TranslationsSpinnerAdapter (com.quran.labs.androidquran.ui.util.TranslationsSpinnerAdapter)1 QuranSettings (com.quran.labs.androidquran.util.QuranSettings)1