use of com.quran.labs.androidquran.common.LocalTranslation in project quran_android by quran.
the class BaseTranslationPresenterTest method testGetTranslationNames.
@Test
public void testGetTranslationNames() {
final List<String> databases = Arrays.asList("one.db", "two.db");
Map<String, LocalTranslation> map = new HashMap<String, LocalTranslation>() {
{
put("one.db", new LocalTranslation(1, "one.db", "One", "First", null, null, null, 1));
put("two.db", new LocalTranslation(2, "two.db", "Two", "Second", null, null, null, 1));
put("three.db", new LocalTranslation(2, "three.db", "Three", "Third", null, null, null, 1));
}
};
String[] translations = presenter.getTranslationNames(databases, map);
assertThat(translations).hasLength(2);
assertThat(translations[0]).isEqualTo("First");
assertThat(translations[1]).isEqualTo("Second");
}
use of com.quran.labs.androidquran.common.LocalTranslation in project quran_android by quran.
the class QuranDataProvider method search.
private Cursor search(String query, List<LocalTranslation> translations) {
Timber.d("query: %s", query);
final Context context = getContext();
final boolean queryIsArabic = QuranUtils.doesStringContainArabic(query);
final boolean haveArabic = queryIsArabic && quranFileUtils.hasTranslation(context, QURAN_ARABIC_DATABASE);
if (translations.size() == 0 && (queryIsArabic && !haveArabic)) {
return null;
}
int start = haveArabic ? -1 : 0;
int total = translations.size();
for (int i = start; i < total; i++) {
String databaseName;
if (i < 0) {
databaseName = QURAN_ARABIC_DATABASE;
} else {
LocalTranslation translation = translations.get(i);
// skip non-arabic databases if the query is in arabic
if (queryIsArabic && translation.languageCode != null && !"ar".equals(translation.languageCode)) {
continue;
} else if (!queryIsArabic && "ar".equals(translation.languageCode)) {
// skip arabic databases when the query isn't arabic
continue;
}
databaseName = translation.filename;
}
Cursor cursor = search(query, databaseName, true);
if (cursor != null && cursor.getCount() > 0) {
return cursor;
}
}
return null;
}
use of com.quran.labs.androidquran.common.LocalTranslation in project quran_android by quran.
the class TranslationsDBAdapter method getTranslations.
@WorkerThread
@NonNull
public List<LocalTranslation> getTranslations() {
// intentional, since cachedTranslations can be replaced by another thread, causing the check
// to be true, but the cached object returned to be null (or to change).
List<LocalTranslation> cached = cachedTranslations;
if (cached != null && cached.size() > 0) {
return cached;
}
List<LocalTranslation> items = new ArrayList<>();
Cursor cursor = db.query(TranslationsTable.TABLE_NAME, null, null, null, null, null, TranslationsTable.ID + " ASC");
if (cursor != null) {
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String name = cursor.getString(1);
String translator = cursor.getString(2);
String translatorForeign = cursor.getString(3);
String filename = cursor.getString(4);
String url = cursor.getString(5);
String languageCode = cursor.getString(6);
int version = cursor.getInt(7);
if (quranFileUtils.hasTranslation(context, filename)) {
items.add(new LocalTranslation(id, filename, name, translator, translatorForeign, url, languageCode, version));
}
}
cursor.close();
}
items = Collections.unmodifiableList(items);
if (items.size() > 0) {
cachedTranslations = items;
}
return items;
}
Aggregations