use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class CardsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder tempHolder, int position) {
// Timber.i("onBindViewHolder:%s", position);
if (tempHolder instanceof CardsViewHolder) {
position--;
CardsViewHolder holder = (CardsViewHolder) tempHolder;
CardBrowser.CardCache card = mCallback.getCards().get(position);
String question = card.getColumnHeaderText(CardBrowser.Column.SFLD);
if (card.getColumnHeaderText(CardBrowser.Column.SUSPENDED).equals("True")) {
holder.deckQuestion.setTextColor(ContextCompat.getColor(mContext, R.color.new_primary_text_third_color));
// holder.deckAnswer.setTextColor(ContextCompat.getColor(mContext, R.color.new_primary_text_third_color));
}
String firstColumnStr = question.isEmpty() ? card.getColumnHeaderText(CardBrowser.Column.MEDIA_NAME) : card.getColumnHeaderText(CardBrowser.Column.SFLD);
Pattern pattern = Pattern.compile("(?<=≯#).*?(?=#≮)");
Matcher matcher = pattern.matcher(firstColumnStr);
String val = "";
if (matcher.find()) {
val = matcher.group(0);
try {
String key = mModelKeys.getString(String.valueOf(card.getCard().model().getLong("id")));
Timber.i("match key:%s", key);
holder.deckQuestion.setText(HtmlUtils.delHTMLTag(firstColumnStr.substring(0, firstColumnStr.indexOf("≯#")) + AESUtil.decrypt(val, key) + firstColumnStr.substring(firstColumnStr.indexOf("#≮") + 2)));
// holder.deckQuestion.setText(firstColumnStr.substring(0, firstColumnStr.indexOf("≯#")) + aesUtil.getDecryptedMessage(val) + firstColumnStr.substring(firstColumnStr.indexOf("#≮") + 2));
} catch (Exception e) {
e.printStackTrace();
holder.deckQuestion.setText(firstColumnStr);
}
} else {
holder.deckQuestion.setText(firstColumnStr);
}
Timber.i("match content:%s", val);
// if(mModelKeys!=null&&( key=mModelKeys.getString(String.valueOf(card.getCard().model().getLong("id"))))!=JSONObject.NULL){
// holder.deckQuestion.setText(AESUtil.decrypt(firstColumnStr,key));
// }else {
// holder.deckQuestion.setText((mModelKeys!=null&&( key=mModelKeys.getString(String.valueOf(card.getCard().model().getLong("id"))))!=JSONObject.NULL)?AESUtil.decrypt(firstColumnStr,key):firstColumnStr);
// }
// holder.deckQuestion.setText((mModelKeys!=null&&( key=mModelKeys.getString(String.valueOf(card.getCard().model().getLong("id"))))!=JSONObject.NULL)?AESUtil.decrypt(firstColumnStr,key):firstColumnStr);
// if (question.isEmpty()) {
//
// holder.deckQuestion.setText(card.getColumnHeaderText(CardBrowser.Column.MEDIA_NAME));
// } else {
// holder.deckQuestion.setText(card.getColumnHeaderText(CardBrowser.Column.SFLD));
// }
// holder.deckAnswer.setText(card.getColumnHeaderText(CardBrowser.Column.ANSWER));
holder.reviewCount.setText(card.getColumnHeaderText(CardBrowser.Column.REVIEWS));
holder.forgetCount.setText(card.getColumnHeaderText(CardBrowser.Column.LAPSES));
holder.due.setText(card.getColumnHeaderText(CardBrowser.Column.DUE2));
holder.mark.setTag(card.getId());
holder.flag.setTag(card.getId());
holder.itemRoot.setTag(card.getId());
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) holder.itemRoot.getLayoutParams();
if (mMultiCheckableMode) {
layoutParams.rightMargin = -60;
holder.itemRoot.setLayoutParams(layoutParams);
holder.stick.setVisibility(View.VISIBLE);
} else {
layoutParams.rightMargin = 0;
holder.itemRoot.setLayoutParams(layoutParams);
holder.stick.setVisibility(View.GONE);
}
holder.stick.setChecked(mSelectedPosition.contains(card.getId()));
// Timber.i("mSelectedPosition size " + mSelectedPosition.size() + "," + card.getId());
holder.stick.setOnClickListener(v -> {
if (mSelectedPosition.contains(card.getId())) {
mSelectedPosition.remove(card.getId());
mCheckedCards.remove(card);
} else {
mSelectedPosition.add(card.getId());
mCheckedCards.add(card);
}
mCallback.onItemSelect(mSelectedPosition.size());
});
// });
if (card.getCard().note().hasTag("marked")) {
holder.mark.setImageResource(R.mipmap.mark_star_normal);
// holder.mark.setVisibility(View.VISIBLE);
} else {
holder.mark.setImageResource(R.mipmap.note_star_unselected);
// holder.flag.setVisibility(View.GONE);
}
if (getFlagRes(card.getCard()) != -1) {
holder.flag.setImageResource(getFlagRes(card.getCard()));
// holder.flag.setVisibility(View.VISIBLE);
} else {
// holder.flag.setImageDrawable(mEmptyFlag);
holder.flag.setImageResource(R.mipmap.note_flag_unselected);
// holder.flag.setVisibility(View.GONE);
}
holder.mark.setOnClickListener(mMarkClickListener);
holder.flag.setOnClickListener(mSetFlagClickListener);
holder.itemRoot.setOnClickListener(mDeckClickListener);
holder.itemRoot.setOnLongClickListener(mDeckLongClickListener);
} else {
HeaderViewHolder holder = (HeaderViewHolder) tempHolder;
holder.cardsCount.setText(String.format("筛选出%d张卡片", getItemCount() - 1));
holder.cardsCount.setVisibility(isMultiCheckableMode() ? View.GONE : View.VISIBLE);
if (holder.order != null) {
holder.order.setOnClickListener(mIvOrderClickListener);
holder.orderText.setOnClickListener(mTvOrderClickListener);
holder.orderText.setText(mOrderName);
holder.order.setSelected(mAsc);
}
}
}
use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class NoteService method updateJsonNoteFromMultimediaNote.
/**
* Updates the JsonNote field values from MultimediaEditableNote When both notes are using the same Model, it updaes
* the destination field values with source values. If models are different it throws an Exception
*
* @param noteSrc
* @param editorNoteDst
*/
public static void updateJsonNoteFromMultimediaNote(final IMultimediaEditableNote noteSrc, final Note editorNoteDst) {
if (noteSrc instanceof MultimediaEditableNote) {
MultimediaEditableNote mmNote = (MultimediaEditableNote) noteSrc;
if (mmNote.getModelId() != editorNoteDst.getMid()) {
throw new RuntimeException("Source and Destination Note ID do not match.");
}
int totalFields = mmNote.getNumberOfFields();
for (int i = 0; i < totalFields; i++) {
editorNoteDst.values()[i] = mmNote.getField(i).getFormattedValue();
}
}
}
use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class NoteService method createEmptyNote.
/**
* Creates an empty Note from given Model
*
* @param model the model in JSOBObject format
* @return a new note instance
*/
public static MultimediaEditableNote createEmptyNote(JSONObject model) {
try {
JSONArray fieldsArray = model.getJSONArray("flds");
int numOfFields = fieldsArray.length();
if (numOfFields > 0) {
MultimediaEditableNote note = new MultimediaEditableNote();
note.setNumFields(numOfFields);
for (int i = 0; i < numOfFields; i++) {
JSONObject fieldObject = fieldsArray.getJSONObject(i);
TextField uiTextField = new TextField();
uiTextField.setName(fieldObject.getString("name"));
uiTextField.setText(fieldObject.getString("name"));
note.setField(i, uiTextField);
}
note.setModelId(model.getLong("id"));
return note;
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class Card method _getQA.
public HashMap<String, String> _getQA(boolean reload, boolean browser) {
if (mQA == null || reload) {
Note f = note(reload);
Model m = model();
JSONObject t = template();
long did = mODid != 0L ? mODid : mDid;
if (browser) {
String bqfmt = t.getString("bqfmt");
String bafmt = t.getString("bafmt");
mQA = mCol._renderQA(mId, m, did, mOrd, f.stringTags(), f.getFields(), mFlags, browser, bqfmt, bafmt);
} else {
mQA = mCol._renderQA(mId, m, did, mOrd, f.stringTags(), f.getFields(), mFlags);
}
}
return mQA;
}
use of com.ichi2.libanki.Model in project AnkiChinaAndroid by ankichinateam.
the class Finder method _findTemplate.
private String _findTemplate(String val) {
// were we given an ordinal number?
Integer num = null;
try {
num = Integer.parseInt(val) - 1;
} catch (NumberFormatException e) {
num = null;
}
if (num != null) {
return "c.ord = " + num;
}
// search for template names
List<String> lims = new ArrayList<>();
for (JSONObject m : mCol.getModels().all()) {
JSONArray tmpls = m.getJSONArray("tmpls");
for (int ti = 0; ti < tmpls.length(); ++ti) {
JSONObject t = tmpls.getJSONObject(ti);
String templateName = t.getString("name");
Normalizer.normalize(templateName, Normalizer.Form.NFC);
if (templateName.equalsIgnoreCase(val)) {
if (m.getInt("type") == Consts.MODEL_CLOZE) {
// if the user has asked for a cloze card, we want
// to give all ordinals, so we just limit to the
// model instead
lims.add("(n.mid = " + m.getLong("id") + ")");
} else {
lims.add("(n.mid = " + m.getLong("id") + " and c.ord = " + t.getInt("ord") + ")");
}
}
}
}
return TextUtils.join(" or ", lims.toArray(new String[lims.size()]));
}
Aggregations