use of com.ichi2.anki.CardBrowser.Column.TAGS in project Anki-Android by ankidroid.
the class CardBrowser method showEditTagsDialog.
private void showEditTagsDialog() {
if (getSelectedCardIds().isEmpty()) {
Timber.d("showEditTagsDialog: called with empty selection");
}
final ArrayList<String> allTags = new ArrayList<>(getCol().getTags().all());
List<Note> selectedNotes = getSelectedCardIds().stream().map(cardId -> getCol().getCard(cardId).note()).distinct().collect(Collectors.toList());
final ArrayList<String> checkedTags = selectedNotes.stream().flatMap(note -> note.getTags().stream()).collect(Collectors.toCollection(ArrayList::new));
if (selectedNotes.size() == 1) {
Timber.d("showEditTagsDialog: edit tags for one note");
mTagsDialogListenerAction = TagsDialogListenerAction.EDIT_TAGS;
TagsDialog dialog = mTagsDialogFactory.newTagsDialog().withArguments(TagsDialog.DialogType.EDIT_TAGS, checkedTags, allTags);
showDialogFragment(dialog);
return;
}
final ArrayList<String> uncheckedTags = selectedNotes.stream().flatMap(note -> {
final List<String> noteTags = note.getTags();
return allTags.stream().filter(t -> !noteTags.contains(t));
}).collect(Collectors.toCollection(ArrayList::new));
Timber.d("showEditTagsDialog: edit tags for multiple note");
mTagsDialogListenerAction = TagsDialogListenerAction.EDIT_TAGS;
TagsDialog dialog = mTagsDialogFactory.newTagsDialog().withArguments(TagsDialog.DialogType.EDIT_TAGS, checkedTags, uncheckedTags, allTags);
showDialogFragment(dialog);
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project Anki-Android by ankidroid.
the class CardBrowser method editSelectedCardsTags.
private void editSelectedCardsTags(List<String> selectedTags, List<String> indeterminateTags) {
List<Note> selectedNotes = getSelectedCardIds().stream().map(cardId -> getCol().getCard(cardId).note()).distinct().collect(Collectors.toList());
for (Note note : selectedNotes) {
List<String> previousTags = note.getTags();
List<String> updatedTags = TagsUtil.getUpdatedTags(previousTags, selectedTags, indeterminateTags);
note.setTagsFromStr(getCol().getTags().join(updatedTags));
}
Timber.i("CardBrowser:: editSelectedCardsTags: Saving note/s tags...");
TaskManager.launchCollectionTask(new CollectionTask.UpdateMultipleNotes(selectedNotes), updateMultipleNotesHandler());
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project Anki-Android by ankidroid.
the class NoteEditor method onCreate.
// ----------------------------------------------------------------------------
// ANDROID METHODS
// ----------------------------------------------------------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
if (showedActivityFailedScreen(savedInstanceState)) {
return;
}
Timber.d("onCreate()");
mTagsDialogFactory = new TagsDialogFactory(this).attachToActivity(this);
mMediaRegistration = new MediaRegistration(this);
super.onCreate(savedInstanceState);
mFieldState.setInstanceState(savedInstanceState);
setContentView(R.layout.note_editor);
Intent intent = getIntent();
if (savedInstanceState != null) {
mCaller = savedInstanceState.getInt("caller");
mAddNote = savedInstanceState.getBoolean("addNote");
mCurrentDid = savedInstanceState.getLong("did");
mSelectedTags = savedInstanceState.getStringArrayList("tags");
mReloadRequired = savedInstanceState.getBoolean("reloadRequired");
mPastedImageCache = (HashMap<String, String>) savedInstanceState.getSerializable("imageCache");
mToggleStickyText = (HashMap<Integer, String>) savedInstanceState.getSerializable("toggleSticky");
mChanged = savedInstanceState.getBoolean("changed");
} else {
mCaller = intent.getIntExtra(EXTRA_CALLER, CALLER_NOCALLER);
if (mCaller == CALLER_NOCALLER) {
String action = intent.getAction();
if ((ACTION_CREATE_FLASHCARD.equals(action) || ACTION_CREATE_FLASHCARD_SEND.equals(action) || ACTION_PROCESS_TEXT.equals(action))) {
mCaller = CALLER_CARDEDITOR_INTENT_ADD;
}
}
}
startLoadingCollection();
mOnboarding.onCreate();
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project Anki-Android by ankidroid.
the class NoteEditor method hasUnsavedChanges.
private boolean hasUnsavedChanges() {
if (!collectionHasLoaded()) {
return false;
}
// changed note type?
if (!mAddNote && mCurrentEditedCard != null) {
final JSONObject newModel = getCurrentlySelectedModel();
final JSONObject oldModel = mCurrentEditedCard.model();
if (!newModel.equals(oldModel)) {
return true;
}
}
// changed deck?
if (!mAddNote && mCurrentEditedCard != null && mCurrentEditedCard.getDid() != mCurrentDid) {
return true;
}
// changed fields?
if (mFieldEdited) {
return true;
}
// changed tags?
return mTagsEdited;
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project Anki-Android by ankidroid.
the class Collection method _renderQA.
@RustCleanup("#8951 - Remove FrontSide added to the front")
@NonNull
public HashMap<String, String> _renderQA(long cid, Model model, long did, int ord, String tags, String[] flist, int flags, boolean browser, String qfmt, String afmt) {
// data is [cid, nid, mid, did, ord, tags, flds, cardFlags]
// unpack fields and create dict
Map<String, Pair<Integer, JSONObject>> fmap = Models.fieldMap(model);
Set<Map.Entry<String, Pair<Integer, JSONObject>>> maps = fmap.entrySet();
Map<String, String> fields = HashUtil.HashMapInit(maps.size() + 8);
for (Map.Entry<String, Pair<Integer, JSONObject>> entry : maps) {
fields.put(entry.getKey(), flist[entry.getValue().first]);
}
int cardNum = ord + 1;
fields.put("Tags", tags.trim());
fields.put("Type", model.getString("name"));
fields.put("Deck", mDecks.name(did));
String baseName = Decks.basename(fields.get("Deck"));
fields.put("Subdeck", baseName);
fields.put("CardFlag", _flagNameFromCardFlags(flags));
JSONObject template;
if (model.isStd()) {
template = model.getJSONArray("tmpls").getJSONObject(ord);
} else {
template = model.getJSONArray("tmpls").getJSONObject(0);
}
fields.put("Card", template.getString("name"));
fields.put(String.format(Locale.US, "c%d", cardNum), "1");
// render q & a
HashMap<String, String> d = HashUtil.HashMapInit(2);
d.put("id", Long.toString(cid));
qfmt = TextUtils.isEmpty(qfmt) ? template.getString("qfmt") : qfmt;
afmt = TextUtils.isEmpty(afmt) ? template.getString("afmt") : afmt;
for (Pair<String, String> p : new Pair[] { new Pair<>("q", qfmt), new Pair<>("a", afmt) }) {
String type = p.first;
String format = p.second;
if ("q".equals(type)) {
format = fClozePatternQ.matcher(format).replaceAll(String.format(Locale.US, "{{$1cq-%d:", cardNum));
format = fClozeTagStart.matcher(format).replaceAll(String.format(Locale.US, "<%%cq:%d:", cardNum));
fields.put("FrontSide", "");
} else {
format = fClozePatternA.matcher(format).replaceAll(String.format(Locale.US, "{{$1ca-%d:", cardNum));
format = fClozeTagStart.matcher(format).replaceAll(String.format(Locale.US, "<%%ca:%d:", cardNum));
// the following line differs from libanki // TODO: why?
// fields.put("FrontSide", mMedia.stripAudio(d.get("q")));
fields.put("FrontSide", d.get("q"));
}
String html;
try {
html = ParsedNode.parse_inner(format).render(fields, "q".equals(type), getContext());
} catch (TemplateError er) {
Timber.w(er);
html = er.message(getContext());
}
html = ChessFilter.fenToChessboard(html, getContext());
if (!browser) {
// browser don't show image. So compiling LaTeX actually remove information.
html = LaTeX.mungeQA(html, this, model);
}
d.put(type, html);
// empty cloze?
if ("q".equals(type) && model.isCloze()) {
if (Models._availClozeOrds(model, flist, false).isEmpty()) {
String link = String.format("<a href=\"%s\">%s</a>", mContext.getResources().getString(R.string.link_ankiweb_docs_cloze_deletion), "help");
System.out.println(link);
d.put("q", mContext.getString(R.string.empty_cloze_warning, link));
}
}
}
return d;
}
Aggregations