use of com.ichi2.async.CollectionTask.TASK_TYPE.IMPORT in project Anki-Android by ankidroid.
the class IntentHandler method handleFileImport.
private void handleFileImport(Intent intent, Intent reloadIntent, String action) {
Timber.i("Handling file import");
ImportResult importResult = ImportUtils.handleFileImport(this, intent);
// Start DeckPicker if we correctly processed ACTION_VIEW
if (importResult.isSuccess()) {
Timber.d("onCreate() import successful");
reloadIntent.setAction(action);
reloadIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(reloadIntent);
AnkiActivity.finishActivityWithFade(this);
} else {
Timber.i("File import failed");
// Don't import the file if it didn't load properly or doesn't have apkg extension
ImportUtils.showImportUnsuccessfulDialog(this, importResult.getHumanReadableMessage(), true);
}
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.IMPORT in project Anki-Android by ankidroid.
the class ImportTest method testAnki2DiffmodelTemplates.
@Test
public void testAnki2DiffmodelTemplates() throws IOException, JSONException, ImportExportException {
// different from the above as this one tests only the template text being
// changed, not the number of cards/fields
// import the first version of the model
String tmp = Shared.getTestFilePath(getTestContext(), "diffmodeltemplates-1.apkg");
AnkiPackageImporter imp = new AnkiPackageImporter(mTestCol, tmp);
imp.setDupeOnSchemaChange(true);
imp.run();
// then the version with updated template
tmp = Shared.getTestFilePath(getTestContext(), "diffmodeltemplates-2.apkg");
imp = new AnkiPackageImporter(mTestCol, tmp);
imp.setDupeOnSchemaChange(true);
imp.run();
// collection should contain the note we imported
assertEquals(1, mTestCol.noteCount());
// the front template should contain the text added in the 2nd package
Long tcid = mTestCol.findCards("").get(0);
Note tnote = mTestCol.getCard(tcid).note();
assertTrue(mTestCol.findTemplates(tnote).get(0).getString("qfmt").contains("Changed Front Template"));
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.IMPORT in project Anki-Android by ankidroid.
the class ImportTest method testCsv.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsv() throws IOException {
String file = Shared.getTestFilePath(getTestContext(), "text-2fields.txt");
TextImporter i = new TextImporter(mTestCol, file);
i.initMapping();
i.run();
if (TestEnvironment.isDisplayingDefaultEnglishStrings()) {
assertThat(i.getLog(), contains("‘多すぎる too many fields’ had 3 fields, expected 2", "‘not, enough, fields’ had 1 fields, expected 2", "Appeared twice in file: 飲む", "Empty first field: to play", "5 notes added, 0 notes updated, 0 notes unchanged."));
} else {
assertThat(i.getLog(), hasSize(5));
}
assertEquals(5, i.getTotal());
// if we run the import again, it should update instead
i.run();
if (TestEnvironment.isDisplayingDefaultEnglishStrings()) {
assertThat(i.getLog(), contains("‘多すぎる too many fields’ had 3 fields, expected 2", "‘not, enough, fields’ had 1 fields, expected 2", "Appeared twice in file: 飲む", "Empty first field: to play", "0 notes added, 0 notes updated, 5 notes unchanged.", "First field matched: 食べる", "First field matched: 飲む", "First field matched: テスト", "First field matched: to eat", "First field matched: 遊ぶ"));
} else {
assertThat(i.getLog(), hasSize(10));
}
assertEquals(5, i.getTotal());
// but importing should not clobber tags if they're unmapped
Note n = mTestCol.getNote(mTestCol.getDb().queryLongScalar("select id from notes"));
n.addTag("test");
n.flush();
i.run();
n.load();
assertThat(n.getTags(), contains("test"));
assertThat(n.getTags(), hasSize(1));
// if add-only mode, count will be 0
i.setImportMode(NoteImporter.ImportMode.IGNORE_MODE);
i.run();
assertEquals(0, i.getTotal());
// and if dupes mode, will reimport everything
assertEquals(5, mTestCol.cardCount());
i.setImportMode(NoteImporter.ImportMode.ADD_MODE);
i.run();
// includes repeated field
assertEquals(6, i.getTotal());
assertEquals(11, mTestCol.cardCount());
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.IMPORT in project Anki-Android by ankidroid.
the class NoteServiceTest method tempAudioIsDeletedAfterImport.
/**
* Sometimes media files cannot be imported directly to the media directory,
* so they are copied to cache then imported and deleted.
* This tests if cached media are properly deleted after import.
*/
@Test
public void tempAudioIsDeletedAfterImport() {
File file = createTransientFile("foo");
MediaClipField field = new MediaClipField();
field.setAudioPath(file.getAbsolutePath());
field.setHasTemporaryMedia(true);
NoteService.importMediaToDirectory(mTestCol, field);
assertFalse("Audio temporary file should have been deleted after importing", file.exists());
}
Aggregations