use of com.ichi2.anki.dialogs.CustomStudyDialog in project AnkiChinaAndroid by ankichinateam.
the class StudyOptionsFragment method handleDeckSelection.
private void handleDeckSelection(long did, boolean dontSkipStudyOptions) {
// Clear the undo history when selecting a new deck
if (getCol().getDecks().selected() != did) {
getCol().clearUndo();
}
// Select the deck
getCol().getDecks().select(did);
// Also forget the last deck used by the Browser
CardBrowser.clearLastDeckId();
// Reset the schedule so that we get the counts for the currently selected deck
mFocusedDeck = did;
// Get some info about the deck to handle special cases
int pos = mDeckListAdapter.findDeckPosition(did);
AbstractDeckTreeNode deckDueTreeNode = mDeckListAdapter.getDeckList().get(pos);
// if (!deckDueTreeNode.shouldDisplayCounts() || deckDueTreeNode.knownToHaveRep()) {
// If we don't yet have numbers, we trust the user that they knows what they opens, tries to open it.
// If there is nothing to review, it'll come back to deck picker.
openReviewerOrStudyOptions(dontSkipStudyOptions);
// return;
// }
// There are numbers
// Figure out what action to take
// if (getCol().getSched().hasCardsTodayAfterStudyAheadLimit()) {
// // If there are cards due that can't be studied yet (due to the learn ahead limit) then go to study options
// openStudyOptions(false);
// } else if (getCol().getSched().newDue() || getCol().getSched().revDue()) {
// // If there are no cards to review because of the daily study limit then give "Study more" option
// UIUtils.showSnackbar(getAnkiActivity(), R.string.studyoptions_limit_reached, false, R.string.study_more, v -> {
// CustomStudyDialog d = CustomStudyDialog.newInstance(
// CustomStudyDialog.CONTEXT_MENU_LIMITS,
// getCol().getDecks().selected(), true, this);
// showDialogFragment(d);
// }, getView().findViewById(R.id.root_layout), mSnackbarShowHideCallback);
// // Check if we need to update the fragment or update the deck list. The same checks
// // are required for all snackbars below.
// if (mFragmented) {
// // Tablets must always show the study options that corresponds to the current deck,
// // regardless of whether the deck is currently reviewable or not.
// openStudyOptions(false);
// } else {
// // On phones, we update the deck list to ensure the currently selected deck is
// // highlighted correctly.
// updateDeckList();
// }
// } else if (getCol().getDecks().isDyn(did)) {
// // Go to the study options screen if filtered deck with no cards to study
// openStudyOptions(false);
// } else if (!deckDueTreeNode.hasChildren() && getCol().cardCount(new Long[] {did}) == 0) {
// // If the deck is empty and has no children then show a message saying it's empty
// final Uri helpUrl = Uri.parse(getResources().getString(R.string.link_manual_getting_started));
// getAnkiActivity().mayOpenUrl(helpUrl);
// UIUtils.showSnackbar(getAnkiActivity(), R.string.empty_deck, false, R.string.help,
// v -> openHelpUrl(helpUrl), getView().findViewById(R.id.root_layout), mSnackbarShowHideCallback);
// if (mFragmented) {
// openStudyOptions(false);
// } else {
// updateDeckList();
// }
// } else {
// // Otherwise say there are no cards scheduled to study, and give option to do custom study
// UIUtils.showSnackbar(getAnkiActivity(), R.string.studyoptions_empty_schedule, false, R.string.custom_study, v -> {
// CustomStudyDialog d = CustomStudyDialog.newInstance(
// CustomStudyDialog.CONTEXT_MENU_EMPTY_SCHEDULE,
// getCol().getDecks().selected(), true, this);
// showDialogFragment(d);
// }, getView().findViewById(R.id.root_layout), mSnackbarShowHideCallback);
// if (mFragmented) {
// openStudyOptions(false);
// } else {
// updateDeckList();
// }
// }
}
use of com.ichi2.anki.dialogs.CustomStudyDialog in project AnkiChinaAndroid by ankichinateam.
the class CustomStudyDialogTest method learnAheadCardsRegressionTest.
@Test
public void learnAheadCardsRegressionTest() {
// #6289 - Regression Test
CustomStudyDialog args = CustomStudyDialog.newInstance(CustomStudyDialog.CUSTOM_STUDY_AHEAD, 1);
FragmentScenario<CustomStudyDialogForTesting> scenario = getDialogScenario(args);
scenario.moveToState(Lifecycle.State.STARTED);
scenario.onFragment(f -> {
MaterialDialog dialog = (MaterialDialog) f.getDialog();
assertThat(dialog, notNullValue());
dialog.getActionButton(DialogAction.POSITIVE).callOnClick();
});
Deck customStudy = getCol().getDecks().current();
assertThat("Custom Study should be dynamic", customStudy.getInt("dyn") == 1);
assertThat("could not find deck: Custom study session", customStudy, notNullValue());
customStudy.remove("id");
customStudy.remove("mod");
customStudy.remove("name");
String expected = "{\"newToday\":[0,0],\"revToday\":[0,0],\"lrnToday\":[0,0],\"timeToday\":[0,0],\"collapsed\":false,\"dyn\":1,\"desc\":\"\",\"usn\":-1,\"delays\":null,\"separate\":true,\"terms\":[[\"deck:\\\"Default\\\" prop:due<=1\",99999,6]],\"resched\":true,\"return\":true}";
assertThat(customStudy.toString(), is(expected));
}
use of com.ichi2.anki.dialogs.CustomStudyDialog in project AnkiChinaAndroid by ankichinateam.
the class StudyOptionsFragment method showCustomStudyContextMenu.
/**
* Show the context menu for the custom study options
*/
private void showCustomStudyContextMenu() {
CustomStudyDialog d = CustomStudyDialog.newInstance(CustomStudyDialog.CONTEXT_MENU_STANDARD, getCol().getDecks().selected(), (CustomStudyDialog.CustomStudyListener) getActivity());
((AnkiActivity) getActivity()).showDialogFragment(d);
}
use of com.ichi2.anki.dialogs.CustomStudyDialog in project AnkiChinaAndroid by ankichinateam.
the class CustomStudyDialog method buildContextMenu.
/**
* Build a context menu for custom study
*
* @param id
* @return
*/
private MaterialDialog buildContextMenu(int id) {
int[] listIds = getListIds(id);
final boolean jumpToReviewer = getArguments().getBoolean("jumpToReviewer");
return new MaterialDialog.Builder(this.getActivity()).title(R.string.custom_study).cancelable(true).itemsIds(listIds).items(ContextMenuHelper.getValuesFromKeys(getKeyValueMap(), listIds)).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog materialDialog, View view, int which, CharSequence charSequence) {
AnkiActivity activity = getAnkiActivity();
switch(view.getId()) {
case DECK_OPTIONS:
{
// User asked to permanently change the deck options
Intent i = new Intent(activity, DeckOptions.class);
i.putExtra("did", getArguments().getLong("did"));
getActivity().startActivity(i);
break;
}
case MORE_OPTIONS:
{
// User asked to see all custom study options
CustomStudyDialog d = CustomStudyDialog.newInstance(CONTEXT_MENU_STANDARD, getArguments().getLong("did"), jumpToReviewer, listener);
activity.showDialogFragment(d);
break;
}
case CUSTOM_STUDY_TAGS:
{
/*
* This is a special Dialog for CUSTOM STUDY, where instead of only collecting a
* number, it is necessary to collect a list of tags. This case handles the creation
* of that Dialog.
*/
long currentDeck = getArguments().getLong("did");
TagsDialog dialogFragment = TagsDialog.newInstance(TagsDialog.TYPE_CUSTOM_STUDY_TAGS, new ArrayList<String>(), new ArrayList<>(activity.getCol().getTags().byDeck(currentDeck, true)));
dialogFragment.setTagsDialogListener(CustomStudyDialog.this::customStudyFromTags);
activity.showDialogFragment(dialogFragment);
break;
}
default:
{
// User asked for a standard custom study option
CustomStudyDialog d = CustomStudyDialog.newInstance(view.getId(), getArguments().getLong("did"), jumpToReviewer, listener);
getAnkiActivity().showDialogFragment(d);
}
}
}
}).build();
}
use of com.ichi2.anki.dialogs.CustomStudyDialog 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();
}
Aggregations