use of com.ichi2.anki.R in project Anki-Android by ankidroid.
the class ModelBrowser method renameModelDialog.
/*
* Displays a confirmation box asking if you want to rename the note type and then renames it if confirmed
*/
private void renameModelDialog() {
initializeNoteTypeList();
mModelNameInput = new FixedEditText(this);
mModelNameInput.setSingleLine(true);
mModelNameInput.setText(mModels.get(mModelListPosition).getString("name"));
mModelNameInput.setSelection(mModelNameInput.getText().length());
new MaterialEditTextDialog.Builder(this, mModelNameInput).title(R.string.rename_model).positiveText(R.string.rename).negativeText(R.string.dialog_cancel).onPositive((dialog, which) -> {
Model model = mModels.get(mModelListPosition);
String deckName = mModelNameInput.getText().toString().replaceAll("[\"\\n\\r]", "");
if (mExistingModelNames.contains(deckName)) {
deckName = randomizeName(deckName);
}
if (deckName.length() > 0) {
model.put("name", deckName);
mCol.getModels().update(model);
mModels.get(mModelListPosition).put("name", deckName);
mModelDisplayList.set(mModelListPosition, new DisplayPair(mModels.get(mModelListPosition).getString("name"), mCardCounts.get(mModelListPosition)));
refreshList();
} else {
showToast(getResources().getString(R.string.toast_empty_name));
}
}).show();
}
use of com.ichi2.anki.R in project Anki-Android by ankidroid.
the class ModelFieldEditor method renameField.
/*
* Renames the current field
*/
private void renameField() throws ConfirmModSchemaException {
String fieldLabel = mFieldNameInput.getText().toString().replaceAll("[\\n\\r]", "");
JSONObject field = mNoteFields.getJSONObject(mCurrentPos);
mCol.getModels().renameField(mMod, field, fieldLabel);
mCol.getModels().save();
fullRefreshList();
}
use of com.ichi2.anki.R in project Anki-Android by ankidroid.
the class ZipFile method exportFiltered.
private JSONObject exportFiltered(ZipFile z, String path, Context context) throws IOException, JSONException, ImportExportException {
// export into the anki2 file
String colfile = path.replace(".apkg", ".anki2");
super.exportInto(colfile, context);
z.write(colfile, CollectionHelper.COLLECTION_FILENAME);
// and media
prepareMedia();
JSONObject media = _exportMedia(z, mMediaFiles, mCol.getMedia().dir());
// tidy up intermediate files
SQLiteDatabase.deleteDatabase(new File(colfile));
SQLiteDatabase.deleteDatabase(new File(path.replace(".apkg", ".media.ad.db2")));
String tempPath = path.replace(".apkg", ".media");
File file = new File(tempPath);
if (file.exists()) {
String deleteCmd = "rm -r " + tempPath;
Runtime runtime = Runtime.getRuntime();
try {
runtime.exec(deleteCmd);
} catch (IOException ignored) {
Timber.w(ignored);
}
}
return media;
}
use of com.ichi2.anki.R in project Anki-Android by ankidroid.
the class HttpTest method testLogin.
@Test
// #7108: AsyncTask
@SuppressWarnings("deprecation")
public void testLogin() {
String username = "AnkiDroidInstrumentedTestUser";
String password = "AnkiDroidInstrumentedTestInvalidPass";
Connection.Payload invalidPayload = new Connection.Payload(new Object[] { username, password, new HostNum(null) });
TestTaskListener testListener = new TestTaskListener(invalidPayload);
// We have to carefully run things on the main thread here or the threading protections in BaseAsyncTask throw
// The first one is just to run the static initializer, really
Runnable onlineRunnable = () -> {
try {
Class.forName("com.ichi2.async.Connection");
} catch (Exception e) {
Assert.fail("Unable to load Connection class: " + e.getMessage());
}
};
InstrumentationRegistry.getInstrumentation().runOnMainSync(onlineRunnable);
// TODO simulate offline programmatically - currently exercised by manually toggling an emulator offline pre-test
if (!Connection.isOnline()) {
Connection.login(testListener, invalidPayload);
Assert.assertFalse("Successful login despite being offline", testListener.getPayload().success);
Assert.assertTrue("onDisconnected not called despite being offline", testListener.mDisconnectedCalled);
return;
}
Runnable r = () -> {
Connection conn = Connection.login(testListener, invalidPayload);
try {
// This forces us to synchronously wait for the AsyncTask to do it's work
conn.get();
} catch (Exception e) {
Assert.fail("Caught exception while trying to login: " + e.getMessage());
}
};
InstrumentationRegistry.getInstrumentation().runOnMainSync(r);
Assert.assertFalse("Successful login despite invalid credentials", testListener.getPayload().success);
}
Aggregations