use of com.ichi2.anki.CardBrowser.Column.CHANGED in project AnkiChinaAndroid by ankichinateam.
the class Models method flush.
/**
* Flush the registry if any models were changed.
*/
public void flush() {
if (mChanged) {
ensureNotEmpty();
JSONObject array = new JSONObject();
for (Map.Entry<Long, Model> o : mModels.entrySet()) {
array.put(Long.toString(o.getKey()), o.getValue());
}
ContentValues val = new ContentValues();
val.put("models", Utils.jsonToString(array));
mCol.getDb().update("col", val);
mChanged = false;
}
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class CardBrowserTest method flagsAreShownInBigDecksTest.
@Test
public void flagsAreShownInBigDecksTest() {
int numberOfNotes = 75;
CardBrowser cardBrowser = getBrowserWithNotes(numberOfNotes);
// select a random card
Random random = new Random(1);
int cardPosition = random.nextInt(numberOfNotes);
assumeThat("card position to select is 60", cardPosition, is(60));
cardBrowser.checkCardsAtPositions(cardPosition);
assumeTrue("card at position 60 is selected", cardBrowser.hasCheckedCardAtPosition(cardPosition));
// flag the selected card with flag = 1
final int flag = 1;
cardBrowser.flagTask(flag);
advanceRobolectricLooperWithSleep();
// check if card flag turned to flag = 1
assertThat("Card should be flagged", getCheckedCard(cardBrowser).getCard().userFlag(), is(flag));
// unflag the selected card with flag = 0
final int unflagFlag = 0;
cardBrowser.flagTask(unflagFlag);
advanceRobolectricLooperWithSleep();
// check if card flag actually changed from flag = 1
assertThat("Card flag should be removed", getCheckedCard(cardBrowser).getCard().userFlag(), not(flag));
// deselect and select all cards
cardBrowser.onSelectNone();
cardBrowser.onSelectAll();
// flag all the cards with flag = 3
final int flagForAll = 3;
cardBrowser.flagTask(flagForAll);
advanceRobolectricLooperWithSleep();
// check if all card flags turned to flag = 3
assertThat("All cards should be flagged", stream(cardBrowser.getCardIds()).map(cardId -> getCardFlagAfterFlagChangeDone(cardBrowser, cardId)).noneMatch(flag1 -> flag1 != flagForAll));
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class DeckOptionsTest method changeHardFactor.
@Test
public void changeHardFactor() {
Collection col = getCol();
// Verify that for newly created deck hardFactor is default.
double hardFactor = col.get_config("hardFactor", 1.2);
Assert.assertEquals(1.2, hardFactor, 0.01);
// Modify hard factor.
col.set_config("hardFactor", 1.0);
// Verify that hardFactor value has changed.
hardFactor = col.get_config("hardFactor", 1.2);
Assert.assertEquals(1.0, hardFactor, 0.01);
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class Decks method update.
/**
* {@inheritDoc}
*/
@Override
public void update(@NonNull Deck g) {
long id = g.getLong("id");
JSONObject oldDeck = get(id, false);
if (oldDeck != null) {
// In case where another update got the name
// `oldName`, it would be a mistake to remove it from nameMap
mNameMap.remove(oldDeck.getString("name"), oldDeck);
}
mNameMap.add(g);
mDecks.put(g.getLong("id"), g);
maybeAddToActive();
// mark registry changed, but don't bump mod time
save();
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class NoteEditor method saveNote.
@VisibleForTesting
void saveNote() {
final Resources res = getResources();
if (mSelectedTags == null) {
mSelectedTags = new ArrayList<>(0);
}
saveToggleStickyMap();
// treat add new note and edit existing note independently
if (mAddNote) {
// DEFECT: This does not block addition if cloze transpositions are in non-cloze fields.
if (isClozeType() && !hasClozeDeletions()) {
displayErrorSavingNote();
return;
}
// load all of the fields into the note
for (FieldEditText f : mEditFields) {
updateField(f);
}
// Save deck to model
mEditorNote.model().put("did", mCurrentDid);
// Save tags to model
mEditorNote.setTagsFromStr(tagsAsString(mSelectedTags));
JSONArray tags = new JSONArray();
for (String t : mSelectedTags) {
tags.put(t);
}
getCol().getModels().current().put("tags", tags);
getCol().getModels().setChanged();
mReloadRequired = true;
TaskManager.launchCollectionTask(new CollectionTask.AddNote(mEditorNote), saveNoteHandler());
updateFieldsFromStickyText();
} else {
// Check whether note type has been changed
final Model newModel = getCurrentlySelectedModel();
final Model oldModel = (mCurrentEditedCard == null) ? null : mCurrentEditedCard.model();
if (!newModel.equals(oldModel)) {
mReloadRequired = true;
if (mModelChangeCardMap.size() < mEditorNote.numberOfCards() || mModelChangeCardMap.containsValue(null)) {
// If cards will be lost via the new mapping then show a confirmation dialog before proceeding with the change
ConfirmationDialog dialog = new ConfirmationDialog();
dialog.setArgs(res.getString(R.string.confirm_map_cards_to_nothing));
Runnable confirm = () -> {
// Bypass the check once the user confirms
changeNoteTypeWithErrorHandling(oldModel, newModel);
};
dialog.setConfirm(confirm);
showDialogFragment(dialog);
} else {
// Otherwise go straight to changing note type
changeNoteTypeWithErrorHandling(oldModel, newModel);
}
return;
}
// Regular changes in note content
boolean modified = false;
// changed did? this has to be done first as remFromDyn() involves a direct write to the database
if (mCurrentEditedCard != null && mCurrentEditedCard.getDid() != mCurrentDid) {
mReloadRequired = true;
// remove card from filtered deck first (if relevant)
getCol().getSched().remFromDyn(new long[] { mCurrentEditedCard.getId() });
// refresh the card object to reflect the database changes in remFromDyn()
mCurrentEditedCard.load();
// also reload the note object
mEditorNote = mCurrentEditedCard.note();
// then set the card ID to the new deck
mCurrentEditedCard.setDid(mCurrentDid);
modified = true;
}
// now load any changes to the fields from the form
for (FieldEditText f : mEditFields) {
modified = modified | updateField(f);
}
// added tag?
for (String t : mSelectedTags) {
modified = modified || !mEditorNote.hasTag(t);
}
// removed tag?
modified = modified || mEditorNote.getTags().size() > mSelectedTags.size();
if (modified) {
mEditorNote.setTagsFromStr(tagsAsString(mSelectedTags));
mChanged = true;
}
closeNoteEditor();
}
}
Aggregations