use of com.ichi2.anki.AnkiActivity in project AnkiChinaAndroid by ankichinateam.
the class CustomStudyDialog method createCustomStudySession.
/**
* Create a custom study session
*
* @param delays delay options for scheduling algorithm
* @param terms search terms
* @param resched whether to reschedule the cards based on the answers given (or ignore them if false)
*/
private void createCustomStudySession(JSONArray delays, Object[] terms, Boolean resched) {
Deck dyn;
final AnkiActivity activity = getAnkiActivity();
Collection col = CollectionHelper.getInstance().getCol(activity);
long did = getArguments().getLong("did");
String deckToStudyName = col.getDecks().get(did).getString("name");
String customStudyDeck = getResources().getString(R.string.custom_study_deck_name);
Deck cur = col.getDecks().byName(customStudyDeck);
if (cur != null) {
Timber.i("Found deck: '%s'", customStudyDeck);
if (cur.getInt("dyn") != 1) {
Timber.w("Deck: '%s' was non-dynamic", customStudyDeck);
new MaterialDialog.Builder(getActivity()).content(R.string.custom_study_deck_exists).negativeText(R.string.dialog_cancel).build().show();
return;
} else {
Timber.i("Emptying dynamic deck '%s' for custom study", customStudyDeck);
// safe to empty
col.getSched().emptyDyn(cur.getLong("id"));
// reuse; don't delete as it may have children
dyn = cur;
col.getDecks().select(cur.getLong("id"));
}
} else {
Timber.i("Creating Dynamic Deck '%s' for custom study", customStudyDeck);
long customStudyDid = col.getDecks().newDyn(customStudyDeck);
dyn = col.getDecks().get(customStudyDid);
}
if (!dyn.has("terms")) {
// #5959 - temp code to diagnose why terms doesn't exist.
// normally we wouldn't want to log this much, but we need to know how deep the corruption is to fix the
// issue
Timber.w("Invalid Dynamic Deck: %s", dyn);
AnkiDroidApp.sendExceptionReport("Custom Study Deck had no terms", "CustomStudyDialog - createCustomStudySession");
UIUtils.showThemedToast(this.getContext(), getString(R.string.custom_study_rebuild_deck_corrupt), false);
return;
}
// and then set various options
if (delays.length() > 0) {
dyn.put("delays", delays);
} else {
dyn.put("delays", JSONObject.NULL);
}
JSONArray ar = dyn.getJSONArray("terms");
ar.getJSONArray(0).put(0, "deck:\"" + deckToStudyName + "\" " + terms[0]);
ar.getJSONArray(0).put(1, terms[1]);
@Consts.DYN_PRIORITY int priority = (Integer) terms[2];
ar.getJSONArray(0).put(2, priority);
dyn.put("resched", resched);
// Rebuild the filtered deck
Timber.i("Rebuilding Custom Study Deck");
TaskListener listener = createCustomStudySessionListener();
CollectionTask.launchCollectionTask(REBUILD_CRAM, listener);
// Hide the dialogs
activity.dismissAllDialogFragments();
}
use of com.ichi2.anki.AnkiActivity in project AnkiChinaAndroid by ankichinateam.
the class DeckPickerConfirmDeleteDeckDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources();
return new MaterialDialog.Builder(getActivity()).title(res.getString(R.string.delete_deck_title)).content(getArguments().getString("dialogMessage")).iconAttr(R.attr.dialogErrorIcon).positiveText(res.getString(R.string.dialog_positive_delete)).negativeText(res.getString(R.string.dialog_cancel)).cancelable(true).onPositive((dialog, which) -> {
((AnkiActivity) getActivity()).deleteContextMenuDeck();
((AnkiActivity) getActivity()).dismissAllDialogFragments();
}).onNegative((dialog, which) -> ((AnkiActivity) getActivity()).dismissAllDialogFragments()).build();
}
Aggregations