Search in sources :

Example 16 with ConfirmModSchemaException

use of com.ichi2.anki.exception.ConfirmModSchemaException in project Anki-Android by ankidroid.

the class SchedTest method getColV1.

/**
 ***************
 ** autogenerated from https://github.com/ankitects/anki/blob/2c73dcb2e547c44d9e02c20a00f3c52419dc277b/pylib/tests/test_cards.py*
 ****************
 */
private Collection getColV1() throws ConfirmModSchemaException {
    Collection col = getCol();
    col.changeSchedulerVer(1);
    return col;
}
Also used : Collection(com.ichi2.libanki.Collection)

Example 17 with ConfirmModSchemaException

use of com.ichi2.anki.exception.ConfirmModSchemaException in project Anki-Android by ankidroid.

the class DeckPicker method onFinishedStartup.

/**
 * Perform the following tasks:
 * Automatic backup
 * loadStudyOptionsFragment() if tablet
 * Automatic sync
 */
private void onFinishedStartup() {
    // create backup in background if needed
    BackupManager.performBackupInBackground(getCol().getPath(), getCol().getTime());
    // Force a full sync if flag was set in upgrade path, asking the user to confirm if necessary
    if (mRecommendFullSync) {
        mRecommendFullSync = false;
        try {
            getCol().modSchema();
        } catch (ConfirmModSchemaException e) {
            Timber.w("Forcing full sync");
            e.log();
            // If libanki determines it's necessary to confirm the full sync then show a confirmation dialog
            // We have to show the dialog via the DialogHandler since this method is called via an async task
            Resources res = getResources();
            Message handlerMessage = Message.obtain();
            handlerMessage.what = DialogHandler.MSG_SHOW_FORCE_FULL_SYNC_DIALOG;
            Bundle handlerMessageData = new Bundle();
            handlerMessageData.putString("message", res.getString(R.string.full_sync_confirmation_upgrade) + "\n\n" + res.getString(R.string.full_sync_confirmation));
            handlerMessage.setData(handlerMessageData);
            getDialogHandler().sendMessage(handlerMessage);
        }
    }
    automaticSync();
}
Also used : Message(android.os.Message) Bundle(android.os.Bundle) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) Resources(android.content.res.Resources)

Example 18 with ConfirmModSchemaException

use of com.ichi2.anki.exception.ConfirmModSchemaException in project Anki-Android by ankidroid.

the class ModelFieldEditor method addFieldDialog.

/*
    * Creates a dialog to create a field
    */
private void addFieldDialog() {
    mFieldNameInput = new FixedEditText(this);
    mFieldNameInput.setSingleLine(true);
    new MaterialEditTextDialog.Builder(this, mFieldNameInput).title(R.string.model_field_editor_add).positiveText(R.string.dialog_ok).onPositive((dialog, which) -> {
        // Name is valid, now field is added
        changeHandler listener = changeFieldHandler();
        String fieldName = _uniqueName(mFieldNameInput);
        try {
            addField(fieldName, listener, true);
        } catch (ConfirmModSchemaException e) {
            e.log();
            // Create dialogue to for schema change
            ConfirmationDialog c = new ConfirmationDialog();
            c.setArgs(getResources().getString(R.string.full_sync_confirmation));
            Runnable confirm = () -> {
                try {
                    addField(fieldName, listener, false);
                } catch (ConfirmModSchemaException e1) {
                    e1.log();
                // This should never be thrown
                }
                dismissContextMenu();
            };
            c.setConfirm(confirm);
            c.setCancel(mConfirmDialogCancel);
            ModelFieldEditor.this.showDialogFragment(c);
        }
        mCol.getModels().update(mMod);
        fullRefreshList();
    }).negativeText(R.string.dialog_cancel).show();
}
Also used : ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) FixedEditText(com.ichi2.ui.FixedEditText) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog)

Example 19 with ConfirmModSchemaException

use of com.ichi2.anki.exception.ConfirmModSchemaException in project Anki-Android by ankidroid.

the class ModelFieldEditor method renameFieldDialog.

/*
     * Creates a dialog to rename the currently selected field
     * Processing time is constant
     */
private void renameFieldDialog() {
    mFieldNameInput = new FixedEditText(this);
    mFieldNameInput.setSingleLine(true);
    mFieldNameInput.setText(mFieldLabels.get(mCurrentPos));
    mFieldNameInput.setSelection(mFieldNameInput.getText().length());
    new MaterialEditTextDialog.Builder(this, mFieldNameInput).title(R.string.model_field_editor_rename).positiveText(R.string.rename).onPositive((dialog, which) -> {
        String fieldName = _uniqueName(mFieldNameInput);
        if (fieldName == null) {
            return;
        }
        // Field is valid, now rename
        try {
            renameField();
        } catch (ConfirmModSchemaException e) {
            e.log();
            // Handler mod schema confirmation
            ConfirmationDialog c = new ConfirmationDialog();
            c.setArgs(getResources().getString(R.string.full_sync_confirmation));
            Runnable confirm = () -> {
                mCol.modSchemaNoCheck();
                try {
                    renameField();
                } catch (ConfirmModSchemaException e1) {
                    e1.log();
                // This should never be thrown
                }
                dismissContextMenu();
            };
            c.setConfirm(confirm);
            c.setCancel(mConfirmDialogCancel);
            ModelFieldEditor.this.showDialogFragment(c);
        }
    }).negativeText(R.string.dialog_cancel).show();
}
Also used : ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) FixedEditText(com.ichi2.ui.FixedEditText) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog)

Example 20 with ConfirmModSchemaException

use of com.ichi2.anki.exception.ConfirmModSchemaException in project Anki-Android by ankidroid.

the class ModelFieldEditor method deleteFieldDialog.

/*
     * Creates a dialog to delete the currently selected field
     */
private void deleteFieldDialog() {
    Runnable confirm = () -> {
        mCol.modSchemaNoCheck();
        deleteField();
        dismissContextMenu();
    };
    if (mFieldLabels.size() < 2) {
        UIUtils.showThemedToast(this, getResources().getString(R.string.toast_last_field), true);
    } else {
        try {
            mCol.modSchema();
            ConfirmationDialog d = new ConfirmationDialog();
            d.setArgs(getResources().getString(R.string.field_delete_warning));
            d.setConfirm(confirm);
            d.setCancel(mConfirmDialogCancel);
            showDialogFragment(d);
        } catch (ConfirmModSchemaException e) {
            e.log();
            ConfirmationDialog c = new ConfirmationDialog();
            c.setConfirm(confirm);
            c.setCancel(mConfirmDialogCancel);
            c.setArgs(getResources().getString(R.string.full_sync_confirmation));
            showDialogFragment(c);
        }
    }
}
Also used : ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog)

Aggregations

JSONObject (com.ichi2.utils.JSONObject)39 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)26 JSONArray (com.ichi2.utils.JSONArray)23 Test (org.junit.Test)22 RobolectricTest (com.ichi2.anki.RobolectricTest)14 ConfirmationDialog (com.ichi2.anki.dialogs.ConfirmationDialog)12 Collection (com.ichi2.libanki.Collection)12 Model (com.ichi2.libanki.Model)12 Note (com.ichi2.libanki.Note)8 ArrayList (java.util.ArrayList)8 JSONException (com.ichi2.utils.JSONException)6 HashMap (java.util.HashMap)5 SdkSuppress (androidx.test.filters.SdkSuppress)4 TaskData (com.ichi2.async.TaskData)4 ModelManager (com.ichi2.libanki.ModelManager)4 TextImporter (com.ichi2.libanki.importer.TextImporter)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Cursor (android.database.Cursor)3 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3