use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class StudyOptionsFragment method updateDeckList.
public void updateDeckList(boolean quick) {
processNames();
TaskListener listener = updateDeckListListener();
CollectionTask.TASK_TYPE taskType = quick ? LOAD_DECK_QUICK : LOAD_SPECIFIC_DECK_COUNTS;
CollectionTask.launchCollectionTask(taskType, listener, new TaskData(mCacheID));
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class Reviewer method onCollectionLoaded.
@Override
protected void onCollectionLoaded(Collection col) {
super.onCollectionLoaded(col);
// Load the first card and start reviewing. Uses the answer card
// task to load a card, but since we send null
// as the card to answer, no card will be answered.
mPrefWhiteboard = MetaDB.getWhiteboardState(this, getParentDid());
if (mPrefWhiteboard) {
// DEFECT: Slight inefficiency here, as we set the database using these methods
boolean whiteboardVisibility = MetaDB.getWhiteboardVisibility(this, getParentDid());
setWhiteboardEnabledState(true);
setWhiteboardVisibility(whiteboardVisibility);
}
// Reset schedule in case card was previously loaded
col.getSched().deferReset();
getCol().startTimebox();
CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false), new TaskData(null, 0));
disableDrawerSwipeOnConflicts();
// Add a weak reference to current activity so that scheduler can talk to to Activity
mSched.setContext(new WeakReference<Activity>(this));
// Set full screen/immersive mode if needed
if (mPrefFullscreenReview) {
CompatHelper.getCompat().setFullScreen(this);
}
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class Reviewer method showRescheduleCardDialog.
private void showRescheduleCardDialog() {
Consumer<Integer> runnable = days -> CollectionTask.launchCollectionTask(DISMISS_MULTI, mRescheduleCardHandler, new TaskData(new Object[] { new long[] { mCurrentCard.getId() }, Collection.DismissType.RESCHEDULE_CARDS, days }));
RescheduleDialog dialog = RescheduleDialog.rescheduleSingleCard(getResources(), mCurrentCard, runnable);
showDialogFragment(dialog);
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class Reviewer method showResetCardDialog.
private void showResetCardDialog() {
// Show confirmation dialog before resetting card progress
Timber.i("showResetCardDialog() Reset progress button pressed");
// Show confirmation dialog before resetting card progress
ConfirmationDialog dialog = new ConfirmationDialog();
String title = getResources().getString(R.string.reset_card_dialog_title);
String message = getResources().getString(R.string.reset_card_dialog_message);
dialog.setArgs(title, message);
Runnable confirm = () -> {
Timber.i("NoteEditor:: ResetProgress button pressed");
CollectionTask.launchCollectionTask(DISMISS_MULTI, mResetProgressCardHandler, new TaskData(new Object[] { new long[] { mCurrentCard.getId() }, Collection.DismissType.RESET_CARDS }));
};
dialog.setConfirm(confirm);
showDialogFragment(dialog);
}
use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.
the class StudyOptionsFragment method openReviewer.
private void openReviewer() {
if (mShouldConfigBeforeStudy && mOptions != null) {
SharedPreferences sharedPreferences = getAnkiActivity().getSharedPreferences(STUDY_SETTING, 0);
StringBuilder initIds = new StringBuilder(sharedPreferences.getString(KEY_CONFIG_INIT, ""));
if (initIds.length() > 0) {
String[] ids = initIds.toString().split(",");
if (ids.length > 0) {
for (String id : ids) {
if (getCol().getDecks().current().getLong("id") == Long.parseLong(id)) {
// 已经初始化过了,直接跳过
openReviewerInternal();
return;
}
}
}
// 没初始化过,那现在也初始化了。
// initIds.append(",");
}
for (long id : getDeckIds(getCol().getDecks().current().getLong("id"), getCol())) {
if (!initIds.toString().isEmpty()) {
initIds.append(",");
}
initIds.append(id);
}
// initIds += Stats.deckLimit(getCol().getDecks().current().getLong("id"), getCol()).replace("(","").replace(")","").trim();//要把子牌组也加入里面
sharedPreferences.edit().putString(KEY_CONFIG_INIT, initIds.toString()).apply();
String savedMindModeValue = sharedPreferences.getString(KEY_MIND_MODE, "");
Map<String, Integer> map = null;
try {
Gson gson = new Gson();
map = gson.fromJson(savedMindModeValue, new TypeToken<Map<String, Integer>>() {
}.getType());
} catch (Exception e) {
e.printStackTrace();
}
String mDeckIdStr = String.valueOf(getCol().getDecks().current().getLong("id"));
mCurrentMindModeValue = map != null && map.get(mDeckIdStr) != null ? map.get(mDeckIdStr) : 0;
if (mMindModeValues == null) {
mMindModeValues = getResources().getStringArray(R.array.mind_mode_values);
mMindModeLabels = getResources().getStringArray(R.array.mind_mode_labels);
mMindModeHints = getResources().getStringArray(R.array.mind_mode_hint);
for (int i = 0; i < mMindModeValues.length; i++) {
mMindModeMap.put(Integer.valueOf(mMindModeValues[i]), mMindModeLabels[i]);
}
}
CustomStyleDialog customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("记忆模式").setCustomLayout(R.layout.dialog_common_custom_next).setSelectListModeCallback(new CustomStyleDialog.Builder.SelectListModeCallback() {
@Override
public String[] getItemContent() {
return mMindModeLabels;
}
@Override
public String[] getItemHint() {
return mMindModeHints;
}
@Override
public int getDefaultSelectedPosition() {
return mCurrentMindModeValue;
}
@Override
public void onItemSelect(int position) {
mCurrentMindModeValue = position;
}
}).setPositiveButton("下一步", (dialog, which) -> {
String oldValue = sharedPreferences.getString(KEY_MIND_MODE, "");
Map<String, Integer> oldMap = null;
Gson gson = new Gson();
try {
oldMap = gson.fromJson(oldValue, new TypeToken<Map<String, Integer>>() {
}.getType());
} catch (Exception e) {
e.printStackTrace();
}
if (oldMap == null) {
oldMap = new HashMap<>();
}
for (long id : getDeckIds(getCol().getDecks().current().getLong("id"), getCol())) {
// Timber.i("看看都是什么id %s", id);
oldMap.put(String.valueOf(id), mCurrentMindModeValue);
}
String newValue = gson.toJson(oldMap);
sharedPreferences.edit().putString(KEY_MIND_MODE, newValue).apply();
CollectionTask.launchCollectionTask(CONF_RESET, new ConfChangeHandler(StudyOptionsFragment.this, mCurrentMindModeValue), // 先恢复默认,即长记模式
new TaskData(new Object[] { mOptions }));
dialog.dismiss();
}).setNegativeButton("跳过", (dialog, which) -> {
dialog.dismiss();
try {
getCol().getDecks().save(mOptions);
} catch (RuntimeException e) {
Timber.e(e, "DeckOptions - RuntimeException on saving conf");
AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf");
}
refreshOption();
openReviewerInternal();
}).create();
customDialog.show();
} else {
openReviewerInternal();
}
}
Aggregations