use of com.quran.labs.androidquran.dao.translation.TranslationItem in project quran_android by quran.
the class TranslationManagerPresenter method mergeWithServerTranslations.
private List<TranslationItem> mergeWithServerTranslations(List<Translation> serverTranslations) {
List<TranslationItem> results = new ArrayList<>(serverTranslations.size());
SparseArray<LocalTranslation> localTranslations = translationsDBAdapter.getTranslationsHash();
String databaseDir = quranFileUtils.getQuranDatabaseDirectory(appContext);
List<TranslationItem> updates = new ArrayList<>();
for (int i = 0, count = serverTranslations.size(); i < count; i++) {
Translation translation = serverTranslations.get(i);
LocalTranslation local = localTranslations.get(translation.getId());
File dbFile = new File(databaseDir, translation.getFileName());
boolean exists = dbFile.exists();
TranslationItem item;
if (exists) {
int version = local == null ? getVersionFromDatabase(translation.getFileName()) : local.version;
item = new TranslationItem(translation, version);
} else {
item = new TranslationItem(translation);
}
if (exists && !item.exists()) {
// delete the file, it has been corrupted
if (dbFile.delete()) {
exists = false;
}
}
if ((local == null && exists) || (local != null && !exists)) {
updates.add(item);
} else if (local != null && local.languageCode == null) {
// older items don't have a language code
updates.add(item);
}
results.add(item);
}
if (!updates.isEmpty()) {
translationsDBAdapter.writeTranslationUpdates(updates);
}
return results;
}
use of com.quran.labs.androidquran.dao.translation.TranslationItem in project quran_android by quran.
the class TranslationsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(TranslationViewHolder holder, int position) {
TranslationRowData rowItem = translations.get(position);
switch(holder.getItemViewType()) {
case R.layout.translation_row:
TranslationItem item = (TranslationItem) rowItem;
holder.getTranslationTitle().setText(item.name());
if (TextUtils.isEmpty(item.translation.getTranslatorNameLocalized())) {
holder.getTranslationInfo().setText(item.translation.getTranslator());
} else {
holder.getTranslationInfo().setText(item.translation.getTranslatorNameLocalized());
}
ImageView leftImage = holder.getLeftImage();
ImageView rightImage = holder.getRightImage();
if (item.exists()) {
if (item.needsUpgrade()) {
leftImage.setImageResource(R.drawable.ic_download);
leftImage.setVisibility(View.VISIBLE);
holder.getTranslationInfo().setText(R.string.update_available);
} else {
leftImage.setVisibility(View.GONE);
}
rightImage.setImageResource(R.drawable.ic_cancel);
rightImage.setVisibility(View.VISIBLE);
rightImage.setContentDescription(context.getString(R.string.remove_button));
} else {
leftImage.setVisibility(View.GONE);
rightImage.setImageResource(R.drawable.ic_download);
rightImage.setVisibility(View.VISIBLE);
rightImage.setOnClickListener(null);
rightImage.setClickable(false);
rightImage.setContentDescription(null);
}
break;
case R.layout.translation_sep:
holder.getSeparatorText().setText(rowItem.name());
break;
}
}
use of com.quran.labs.androidquran.dao.translation.TranslationItem in project quran_android by quran.
the class TranslationManagerActivity method generateListItems.
private void generateListItems() {
if (allItems == null) {
return;
}
List<TranslationItem> downloaded = new ArrayList<>();
List<TranslationItem> notDownloaded = new ArrayList<>();
for (int i = 0, mAllItemsSize = allItems.size(); i < mAllItemsSize; i++) {
TranslationItem item = allItems.get(i);
if (item.exists()) {
downloaded.add(item);
} else {
notDownloaded.add(item);
}
}
List<TranslationRowData> result = new ArrayList<>();
if (downloaded.size() > 0) {
TranslationHeader hdr = new TranslationHeader(getString(R.string.downloaded_translations));
result.add(hdr);
boolean needsUpgrade = false;
for (TranslationItem item : downloaded) {
result.add(item);
needsUpgrade = needsUpgrade || item.needsUpgrade();
}
if (!needsUpgrade) {
quranSettings.setHaveUpdatedTranslations(false);
}
}
result.add(new TranslationHeader(getString(R.string.available_translations)));
result.addAll(notDownloaded);
adapter.setTranslations(result);
adapter.notifyDataSetChanged();
}
Aggregations