use of com.ichi2.utils.JSONObject in project AnkiChinaAndroid by ankichinateam.
the class ModelFieldEditor method setupLabels.
/*
* Sets up the ArrayList containing the text for the main ListView
*/
private void setupLabels() {
long noteTypeID = getIntent().getLongExtra("noteTypeID", 0);
mMod = mCol.getModels().get(noteTypeID);
mFieldLabels = new ArrayList<>();
mNoteFields = mMod.getJSONArray("flds");
for (int i = 0; i < mNoteFields.length(); i++) {
JSONObject o = mNoteFields.getJSONObject(i);
mFieldLabels.add(o.getString("name"));
}
}
use of com.ichi2.utils.JSONObject in project AnkiChinaAndroid by ankichinateam.
the class CardBrowser method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
Timber.d("onCreateOptionsMenu()");
mActionBarMenu = menu;
if (!mInMultiSelectMode) {
// restore drawer click listener and icon
// restoreDrawerIcon();
getMenuInflater().inflate(R.menu.card_browser, menu);
mSaveSearchItem = menu.findItem(R.id.action_save_search);
// the searchview's query always starts empty.
mSaveSearchItem.setVisible(false);
mMySearchesItem = menu.findItem(R.id.action_list_my_searches);
JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters");
mMySearchesItem.setVisible(savedFiltersObj != null && savedFiltersObj.length() > 0);
mSearchItem = menu.findItem(R.id.action_search);
mSearchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// SearchView doesn't support empty queries so we always reset the search when collapsing
mSearchTerms = "";
mSearchView.setQuery(mSearchTerms, false);
searchCards();
// invalidate options menu so that disappeared icons would appear again
supportInvalidateOptionsMenu();
return true;
}
});
mSearchView = (SearchView) mSearchItem.getActionView();
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String newText) {
mSaveSearchItem.setVisible(!TextUtils.isEmpty(newText));
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
onSearch();
mSearchView.clearFocus();
return true;
}
});
mSearchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Provide SearchView with the previous search terms
mSearchView.setQuery(mSearchTerms, false);
}
});
// Fixes #6500 - keep the search consistent
if (!TextUtils.isEmpty(mSearchTerms)) {
mSearchItem.expandActionView();
mSearchView.setQuery(mSearchTerms, false);
}
} else {
// multi-select mode
getMenuInflater().inflate(R.menu.card_browser_multiselect, menu);
// showBackIcon();
}
if (mActionBarMenu != null && mActionBarMenu.findItem(R.id.action_undo) != null) {
MenuItem undo = mActionBarMenu.findItem(R.id.action_undo);
undo.setVisible(getCol().undoAvailable());
undo.setTitle(getResources().getString(R.string.studyoptions_congrats_undo, getCol().undoName(getResources())));
}
// Maybe we were called from ACTION_PROCESS_TEXT.
// In that case we already fill in the search.
Intent intent = getIntent();
Compat compat = CompatHelper.getCompat();
if (intent.getAction() == compat.ACTION_PROCESS_TEXT) {
CharSequence search = intent.getCharSequenceExtra(compat.EXTRA_PROCESS_TEXT);
if (search != null && search.length() != 0) {
Timber.i("CardBrowser :: Called with search intent: %s", search.toString());
mSearchView.setQuery(search, true);
intent.setAction(Intent.ACTION_DEFAULT);
}
}
mPreviewItem = menu.findItem(R.id.action_preview);
onSelectionChanged();
updatePreviewMenuItem();
return super.onCreateOptionsMenu(menu);
}
use of com.ichi2.utils.JSONObject in project AnkiChinaAndroid by ankichinateam.
the class CardTemplateEditor method onDeckSelected.
/**
* When a deck is selected via Deck Override
*/
@Override
public void onDeckSelected(@Nullable SelectableDeck deck) {
if (Models.isCloze(getTempModel().getModel())) {
Timber.w("Attempted to set deck for cloze model");
UIUtils.showThemedToast(this, getString(R.string.model_manager_deck_override_cloze_error), true);
return;
}
int ordinal = mViewPager.getCurrentItem();
JSONObject template = getTempModel().getTemplate(ordinal);
String templateName = template.getString("name");
if (deck != null && Decks.isDynamic(getCol(), deck.getDeckId())) {
Timber.w("Attempted to set default deck of %s to dynamic deck %s", templateName, deck.getName());
UIUtils.showThemedToast(this, getString(R.string.model_manager_deck_override_dynamic_deck_error), true);
return;
}
String message;
if (deck == null) {
Timber.i("Removing default template from template '%s'", templateName);
template.put("did", null);
message = getString(R.string.model_manager_deck_override_removed_message, templateName);
} else {
Timber.i("Setting template '%s' to '%s'", templateName, deck.getName());
template.put("did", deck.getDeckId());
message = getString(R.string.model_manager_deck_override_added_message, templateName, deck.getName());
}
UIUtils.showThemedToast(this, message, true);
// Deck Override can change from "on" <-> "off"
supportInvalidateOptionsMenu();
}
use of com.ichi2.utils.JSONObject in project AnkiChinaAndroid by ankichinateam.
the class CardTemplatePreviewer method getDummyCard.
/**
* Get a dummy card
*/
@Nullable
protected Card getDummyCard(Model model, int ordinal) {
Timber.d("getDummyCard() Creating dummy note for ordinal %s", ordinal);
if (model == null) {
return null;
}
Note n = getCol().newNote(model);
ArrayList<String> fieldNames = Models.fieldNames(model);
for (int i = 0; i < fieldNames.size() && i < n.getFields().length; i++) {
n.setField(i, fieldNames.get(i));
}
try {
JSONObject template = model.getJSONArray("tmpls").getJSONObject(ordinal);
PreviewerCard card = (PreviewerCard) getCol().getNewLinkedCard(new PreviewerCard(getCol()), n, template, 1, 0, false);
card.setNote(n);
return card;
} catch (Exception e) {
Timber.e("getDummyCard() unable to create card");
}
return null;
}
use of com.ichi2.utils.JSONObject in project AnkiChinaAndroid by ankichinateam.
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;
}
Aggregations