use of com.quran.labs.androidquran.dao.translation.TranslationRowData in project quran_android by quran.
the class TranslationManagerActivity method removeItem.
private void removeItem(final TranslationRowData translationRowData) {
if (adapter == null) {
return;
}
final TranslationItem selectedItem = (TranslationItem) translationRowData;
String msg = String.format(getString(R.string.remove_dlg_msg), selectedItem.name());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.remove_dlg_title).setMessage(msg).setPositiveButton(R.string.remove_button, (dialog, id) -> {
quranFileUtils.removeTranslation(TranslationManagerActivity.this, selectedItem.translation.getFileName());
TranslationItem updatedItem = selectedItem.withTranslationRemoved();
updateTranslationItem(updatedItem);
// remove from active translations
QuranSettings settings = QuranSettings.getInstance(this);
Set<String> activeTranslations = settings.getActiveTranslations();
activeTranslations.remove(selectedItem.translation.getFileName());
settings.setActiveTranslations(activeTranslations);
generateListItems();
}).setNegativeButton(R.string.cancel, (dialog, i) -> dialog.dismiss());
builder.show();
}
use of com.quran.labs.androidquran.dao.translation.TranslationRowData 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.TranslationRowData 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