use of com.quran.labs.androidquran.dao.translation.TranslationItem in project quran_android by quran.
the class TranslationsDBAdapter method writeTranslationUpdates.
public boolean writeTranslationUpdates(List<TranslationItem> updates) {
boolean result = true;
db.beginTransaction();
try {
for (int i = 0, updatesSize = updates.size(); i < updatesSize; i++) {
TranslationItem item = updates.get(i);
if (item.exists()) {
ContentValues values = new ContentValues();
values.put(TranslationsTable.ID, item.translation.getId());
values.put(TranslationsTable.NAME, item.translation.getDisplayName());
values.put(TranslationsTable.TRANSLATOR, item.translation.getTranslator());
values.put(TranslationsTable.TRANSLATOR_FOREIGN, item.translation.getTranslatorNameLocalized());
values.put(TranslationsTable.FILENAME, item.translation.getFileName());
values.put(TranslationsTable.URL, item.translation.getFileUrl());
values.put(TranslationsTable.LANGUAGE_CODE, item.translation.getLanguageCode());
values.put(TranslationsTable.VERSION, item.localVersion);
db.replace(TranslationsTable.TABLE_NAME, null, values);
} else {
db.delete(TranslationsTable.TABLE_NAME, TranslationsTable.ID + " = " + item.translation.getId(), null);
}
}
db.setTransactionSuccessful();
// clear the cached translations
this.cachedTranslations = null;
} catch (Exception e) {
result = false;
Timber.d(e, "error writing translation updates");
} finally {
db.endTransaction();
}
return result;
}
use of com.quran.labs.androidquran.dao.translation.TranslationItem 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.TranslationItem in project quran_android by quran.
the class TranslationManagerActivity method downloadItem.
private void downloadItem(TranslationRowData translationRowData) {
TranslationItem selectedItem = (TranslationItem) translationRowData;
if (selectedItem.exists() && !selectedItem.needsUpgrade()) {
return;
}
downloadingItem = selectedItem;
if (mDownloadReceiver == null) {
mDownloadReceiver = new DefaultDownloadReceiver(this, QuranDownloadService.DOWNLOAD_TYPE_TRANSLATION);
LocalBroadcastManager.getInstance(this).registerReceiver(mDownloadReceiver, new IntentFilter(QuranDownloadNotifier.ProgressIntent.INTENT_NAME));
}
mDownloadReceiver.setListener(this);
// actually start the download
String url = selectedItem.translation.getFileUrl();
if (selectedItem.translation.getFileUrl() == null) {
return;
}
String destination = databaseDirectory;
Timber.d("downloading %s to %s", url, destination);
if (selectedItem.exists()) {
try {
File f = new File(destination, selectedItem.translation.getFileName());
if (f.exists()) {
File newPath = new File(destination, selectedItem.translation.getFileName() + UPGRADING_EXTENSION);
if (newPath.exists()) {
newPath.delete();
}
f.renameTo(newPath);
}
} catch (Exception e) {
Timber.d(e, "error backing database file up");
}
}
// start the download
String notificationTitle = selectedItem.name();
Intent intent = ServiceIntentHelper.getDownloadIntent(this, url, destination, notificationTitle, TRANSLATION_DOWNLOAD_KEY, QuranDownloadService.DOWNLOAD_TYPE_TRANSLATION);
String filename = selectedItem.translation.getFileName();
if (url.endsWith("zip")) {
filename += ".zip";
}
intent.putExtra(QuranDownloadService.EXTRA_OUTPUT_FILE_NAME, filename);
startService(intent);
}
use of com.quran.labs.androidquran.dao.translation.TranslationItem in project quran_android by quran.
the class TranslationManagerActivity method handleDownloadSuccess.
@Override
public void handleDownloadSuccess() {
if (downloadingItem != null) {
if (downloadingItem.exists()) {
try {
File f = new File(databaseDirectory, downloadingItem.translation.getFileName() + UPGRADING_EXTENSION);
if (f.exists()) {
f.delete();
}
} catch (Exception e) {
Timber.d(e, "error removing old database file");
}
}
TranslationItem updated = downloadingItem.withTranslationVersion(downloadingItem.translation.getCurrentVersion());
updateTranslationItem(updated);
// update active translations and add this item to it
QuranSettings settings = QuranSettings.getInstance(this);
Set<String> activeTranslations = settings.getActiveTranslations();
activeTranslations.add(downloadingItem.translation.getFileName());
settings.setActiveTranslations(activeTranslations);
}
downloadingItem = null;
generateListItems();
}
use of com.quran.labs.androidquran.dao.translation.TranslationItem in project quran_android by quran.
the class TranslationManagerActivity method onTranslationsUpdated.
public void onTranslationsUpdated(List<TranslationItem> items) {
translationSwipeRefresh.setRefreshing(false);
SparseIntArray itemsSparseArray = new SparseIntArray(items.size());
for (int i = 0, itemsSize = items.size(); i < itemsSize; i++) {
TranslationItem item = items.get(i);
itemsSparseArray.put(item.translation.getId(), i);
}
allItems = items;
translationPositions = itemsSparseArray;
generateListItems();
}
Aggregations