Search in sources :

Example 6 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project AnkiChinaAndroid by ankichinateam.

the class NoteEditor method setNote.

/**
 * Handles setting the current note (non-null afterwards) and rebuilding the UI based on this note
 */
private void setNote(Note note, @NonNull FieldChangeType changeType) {
    if (note == null || mAddNote) {
        Model model = getCol().getModels().current();
        mEditorNote = new Note(getCol(), model);
    } else {
        mEditorNote = note;
    }
    if (mSelectedTags == null) {
        mSelectedTags = mEditorNote.getTags();
    }
    // nb: setOnItemSelectedListener and populateEditFields need to occur after this
    setNoteTypePosition();
    updateDeckPosition();
    updateTags();
    updateCards(mEditorNote.model());
    updateToolbar();
    populateEditFields(changeType, false);
}
Also used : IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model)

Example 7 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project AnkiChinaAndroid by ankichinateam.

the class FieldState method loadFieldEditLines.

@NonNull
public List<FieldEditLine> loadFieldEditLines(FieldChangeType type) {
    List<FieldEditLine> fieldEditLines;
    if (type.mType == Type.INIT && mSavedFieldData != null) {
        fieldEditLines = recreateFieldsFromState();
        mSavedFieldData = null;
    } else {
        fieldEditLines = createFields(type);
    }
    for (FieldEditLine l : fieldEditLines) {
        l.setId(ViewCompat.generateViewId());
    }
    if (type.mType == Type.CLEAR_KEEP_STICKY) {
        // we use the UI values here as the model will post-processing steps (newline -> br).
        String[] currentFieldStrings = mEditor.getCurrentFieldStrings();
        JSONArray flds = mEditor.getCurrentFields();
        for (int fldIdx = 0; fldIdx < flds.length(); fldIdx++) {
            if (flds.getJSONObject(fldIdx).getBoolean("sticky")) {
                fieldEditLines.get(fldIdx).setContent(currentFieldStrings[fldIdx], type.replaceNewlines);
            }
        }
    }
    if (type.mType == Type.CHANGE_FIELD_COUNT) {
        String[] currentFieldStrings = mEditor.getCurrentFieldStrings();
        for (int i = 0; i < Math.min(currentFieldStrings.length, fieldEditLines.size()); i++) {
            fieldEditLines.get(i).setContent(currentFieldStrings[i], type.replaceNewlines);
        }
    }
    return fieldEditLines;
}
Also used : JSONArray(com.ichi2.utils.JSONArray) FieldEditLine(com.ichi2.anki.FieldEditLine) NonNull(androidx.annotation.NonNull)

Example 8 with FieldChangeType

use of com.ichi2.anki.noteeditor.FieldState.FieldChangeType in project Anki-Android by ankidroid.

the class NoteEditor method setNote.

/**
 * Handles setting the current note (non-null afterwards) and rebuilding the UI based on this note
 */
private void setNote(Note note, @NonNull FieldChangeType changeType) {
    if (note == null || mAddNote) {
        Model model = getCol().getModels().current();
        mEditorNote = new Note(getCol(), model);
    } else {
        mEditorNote = note;
    }
    if (mSelectedTags == null) {
        mSelectedTags = mEditorNote.getTags();
    }
    // nb: setOnItemSelectedListener and populateEditFields need to occur after this
    setNoteTypePosition();
    setDid(note);
    updateTags();
    updateCards(mEditorNote.model());
    updateToolbar();
    populateEditFields(changeType, false);
    updateFieldsFromStickyText();
}
Also used : IMultimediaEditableNote(com.ichi2.anki.multimediacard.IMultimediaEditableNote) MultimediaEditableNote(com.ichi2.anki.multimediacard.impl.MultimediaEditableNote) Note(com.ichi2.libanki.Note) Model(com.ichi2.libanki.Model)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 ClipboardManager (android.content.ClipboardManager)2 SharedPreferences (android.content.SharedPreferences)2 Typeface (android.graphics.Typeface)2 ImageButton (android.widget.ImageButton)2 NonNull (androidx.annotation.NonNull)2 FieldEditLine (com.ichi2.anki.FieldEditLine)2 IMultimediaEditableNote (com.ichi2.anki.multimediacard.IMultimediaEditableNote)2 AudioRecordingField (com.ichi2.anki.multimediacard.fields.AudioRecordingField)2 IField (com.ichi2.anki.multimediacard.fields.IField)2 ImageField (com.ichi2.anki.multimediacard.fields.ImageField)2 TextField (com.ichi2.anki.multimediacard.fields.TextField)2 MultimediaEditableNote (com.ichi2.anki.multimediacard.impl.MultimediaEditableNote)2 FieldChangeType (com.ichi2.anki.noteeditor.FieldState.FieldChangeType)2 Model (com.ichi2.libanki.Model)2 Note (com.ichi2.libanki.Note)2 AudioClipField (com.ichi2.anki.multimediacard.fields.AudioClipField)1 MediaClipField (com.ichi2.anki.multimediacard.fields.MediaClipField)1 JSONArray (com.ichi2.utils.JSONArray)1 ArrayList (java.util.ArrayList)1