use of com.ichi2.anki.CardBrowser.Column.TAGS 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;
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project AnkiChinaAndroid by ankichinateam.
the class PosterActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
Themes.setThemeLegacy(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_poster);
String poster = getIntent().getStringExtra("poster");
root = new JSONObject(poster);
JSONArray members = root.getJSONArray("members");
setText(R.id.content_title, root.getString("title"));
setText(R.id.content_classify, root.getString("level") + "/" + root.getString("subject"));
setText(R.id.content_price_origin, "原价¥ " + root.getString("origin_price"));
// 中划线
((TextView) findViewById(R.id.content_price_origin)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
setText(R.id.content_price, "¥ " + root.getString("team_price"));
setText(R.id.content_num, root.getString("study_users") + "人正在学习");
setText(R.id.content_time_remain, "拼团特惠仅剩" + root.getInt("quota") + "名额\n" + convertSeconds(root.getInt("countDown")) + "后结束");
setText(R.id.content_num_remain, "还差" + (root.getInt("users") - members.length()) + "人,特享团购价");
ImageView qrcode = findViewById(R.id.qr_code);
Bitmap mBitmap = QRCodeUtil.createQRCodeBitmap(root.getString("link"), Utils.dp2px(this, 160), Utils.dp2px(this, 160));
qrcode.setImageBitmap(mBitmap);
LinearLayout memberLayout = findViewById(R.id.join_list);
for (int i = 0; i < members.length(); i++) {
if (root.getInt("users") > 3) {
// 需要人数大于3个,那就保留一个空位
if (i > 1) {
// 最多添加2个
break;
}
}
// if(root.getInt("users")==3) {
// //需要人数刚好是3个,那就三个都占满
// if (i > 2) {
// break;
// }
// }
View view = getLayoutInflater().inflate(R.layout.item_poster_avatar, null);
ImageView avatar = view.findViewById(R.id.avatar);
if (i == 0) {
view.findViewById(R.id.host_role).setVisibility(View.VISIBLE);
}
Glide.with(this).asBitmap().load(members.getJSONObject(i).getString("avatar")).into(avatar);
memberLayout.addView(view);
}
for (int i = memberLayout.getChildCount(); i < 3; i++) {
View view = getLayoutInflater().inflate(R.layout.item_poster_avatar_empty, null);
memberLayout.addView(view);
}
JSONArray tags = root.getJSONArray("tags");
for (int i = 0; i < tags.length(); i++) {
View view = getLayoutInflater().inflate(R.layout.item_warp_poster, null);
Button button = view.findViewById(R.id.text);
button.setText(tags.getString(i));
((WarpLinearLayout) findViewById(R.id.tags_layout)).addView(view);
}
showShareDialog(findViewById(R.id.rootView));
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project AnkiChinaAndroid by ankichinateam.
the class SelfStudyActivity method updateCardsInList.
/**
* @param cards Cards that were changed
* @param updatedCardTags Mapping note id -> updated tags
*/
private void updateCardsInList(List<Card> cards, Map<Long, String> updatedCardTags) {
List<CardCache> cardList = getCards();
Map<Long, Integer> idToPos = getPositionMap(cardList);
for (Card c : cards) {
// get position in the mCards search results HashMap
Integer pos = idToPos.get(c.getId());
if (pos == null || pos >= getCardCount()) {
continue;
}
// update Q & A etc
cardList.get(pos).load(true, 0, 1);
}
updateList();
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project AnkiChinaAndroid by ankichinateam.
the class Collection method load.
/**
* DB-related *************************************************************** ********************************
*/
public void load() {
Cursor cursor = null;
String deckConf = "";
try {
// Read in deck table columns
cursor = mDb.query("SELECT crt, mod, scm, dty, usn, ls, " + "conf, dconf, tags,ver FROM col");
if (!cursor.moveToFirst()) {
return;
}
mCrt = cursor.getLong(0);
mMod = cursor.getLong(1);
mScm = cursor.getLong(2);
// No longer used
mDty = cursor.getInt(3) == 1;
mUsn = cursor.getInt(4);
mLs = cursor.getLong(5);
mConf = new JSONObject(cursor.getString(6));
deckConf = cursor.getString(7);
mTagsJson = cursor.getString(8);
mTags.load(mTagsJson);
mVer = cursor.getInt(9);
} finally {
if (cursor != null) {
cursor.close();
}
}
// getModels().load(loadColumn("models")); This code has been
// moved to `CollectionHelper::loadLazyCollection` for
// efficiency Models are loaded lazily on demand. The
// application layer can asynchronously pre-fetch those parts;
// otherwise they get loaded when required.
Timber.i("load new collection");
mDecks.load(loadColumn("decks"), deckConf);
}
use of com.ichi2.anki.CardBrowser.Column.TAGS in project AnkiChinaAndroid by ankichinateam.
the class NoteImporter method importNotes.
/**
* Convert each card into a note, apply attributes and add to col.
*/
public void importNotes(List<ForeignNote> notes) {
Assert.that(mappingOk());
// note whether tags are mapped
mTagsMapped = false;
for (String f : mMapping) {
if ("_tags".equals(f)) {
mTagsMapped = true;
break;
}
}
// gather checks for duplicate comparison
HashMap<Long, List<Long>> csums = new HashMap<>();
try (Cursor c = mCol.getDb().query("select csum, id from notes where mid = ?", mModel.getLong("id"))) {
while (c.moveToNext()) {
long csum = c.getLong(0);
long id = c.getLong(1);
if (csums.containsKey(csum)) {
csums.get(csum).add(id);
} else {
csums.put(csum, new ArrayList<>(Collections.singletonList(id)));
}
}
}
HashMap<String, Boolean> firsts = new HashMap<>();
int fld0index = mMapping.indexOf(mModel.getJSONArray("flds").getJSONObject(0).getString("name"));
mFMap = mCol.getModels().fieldMap(mModel);
mNextId = mCol.getTime().timestampID(mCol.getDb(), "notes");
// loop through the notes
List<Object[]> updates = new ArrayList<>();
List<String> updateLog = new ArrayList<>();
// PORT: Translations moved closer to their sources
List<Object[]> _new = new ArrayList<>();
_ids = new ArrayList<>();
_cards = new ArrayList<>();
mEmptyNotes = false;
int dupeCount = 0;
List<String> dupes = new ArrayList<>();
for (ForeignNote n : notes) {
for (int c = 0; c < n.mFields.size(); c++) {
if (!this.mAllowHTML) {
n.mFields.set(c, HtmlUtils.escape(n.mFields.get(c)));
}
n.mFields.set(c, n.mFields.get(c).trim());
if (!this.mAllowHTML) {
n.mFields.set(c, n.mFields.get(c).replace("\n", "<br>"));
}
}
String fld0 = n.mFields.get(fld0index);
long csum = fieldChecksum(fld0);
// first field must exist
if (fld0 == null || fld0.length() == 0) {
getLog().add(getString(R.string.note_importer_error_empty_first_field, TextUtils.join(" ", n.mFields)));
continue;
}
// earlier in import?
if (firsts.containsKey(fld0) && mImportMode != ADD_MODE) {
// duplicates in source file; log and ignore
getLog().add(getString(R.string.note_importer_error_appeared_twice, fld0));
continue;
}
firsts.put(fld0, true);
// already exists?
boolean found = false;
if (csums.containsKey(csum)) {
// csum is not a guarantee; have to check
for (Long id : csums.get(csum)) {
String flds = mCol.getDb().queryString("select flds from notes where id = ?", id);
String[] sflds = splitFields(flds);
if (fld0.equals(sflds[0])) {
// duplicate
found = true;
if (mImportMode == UPDATE_MODE) {
Object[] data = updateData(n, id, sflds);
if (data != null && data.length > 0) {
updates.add(data);
updateLog.add(getString(R.string.note_importer_error_first_field_matched, fld0));
dupeCount += 1;
found = true;
}
} else if (mImportMode == IGNORE_MODE) {
dupeCount += 1;
} else if (mImportMode == ADD_MODE) {
// allow duplicates in this case
if (!dupes.contains(fld0)) {
// only show message once, no matter how many
// duplicates are in the collection already
updateLog.add(getString(R.string.note_importer_error_added_duplicate_first_field, fld0));
dupes.add(fld0);
}
found = false;
}
}
}
}
// newly add
if (!found) {
Object[] data = newData(n);
if (data != null && data.length > 0) {
_new.add(data);
// note that we've seen this note once already
firsts.put(fld0, true);
}
}
}
addNew(_new);
addUpdates(updates);
// make sure to update sflds, etc
mCol.updateFieldCache(collection2Array(_ids));
// generate cards
if (!mCol.genCards(_ids).isEmpty()) {
this.getLog().add(0, getString(R.string.note_importer_empty_cards_found));
}
// apply scheduling updates
updateCards();
// we randomize or order here, to ensure that siblings
// have the same due#
long did = mCol.getDecks().selected();
DeckConfig conf = mCol.getDecks().confForDid(did);
// in order due?
if (conf.getJSONObject("new").getInt("order") == NEW_CARDS_RANDOM) {
mCol.getSched().randomizeCards(did);
}
String part1 = getQuantityString(R.plurals.note_importer_notes_added, _new.size());
String part2 = getQuantityString(R.plurals.note_importer_notes_updated, mUpdateCount);
int unchanged;
if (mImportMode == UPDATE_MODE) {
unchanged = dupeCount - mUpdateCount;
} else if (mImportMode == IGNORE_MODE) {
unchanged = dupeCount;
} else {
unchanged = 0;
}
String part3 = getQuantityString(R.plurals.note_importer_notes_unchanged, unchanged);
mLog.add(String.format("%s, %s, %s.", part1, part2, part3));
mLog.addAll(updateLog);
if (mEmptyNotes) {
mLog.add(getString(R.string.note_importer_error_empty_notes));
}
mTotal = _ids.size();
}
Aggregations