use of com.ichi2.async.CancelListener in project AnkiChinaAndroid by ankichinateam.
the class DeckPickerAnalyticsOptInDialog method onCreateDialog.
@Override
public MaterialDialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources();
return new MaterialDialog.Builder(getActivity()).title(res.getString(R.string.analytics_dialog_title)).content(res.getString(R.string.analytics_summ)).checkBoxPrompt(res.getString(R.string.analytics_title), true, null).positiveText(res.getString(R.string.dialog_continue)).onPositive((dialog, which) -> {
AnkiDroidApp.getSharedPrefs(getContext()).edit().putBoolean(UsageAnalytics.ANALYTICS_OPTIN_KEY, dialog.isPromptCheckBoxChecked()).apply();
((DeckPicker) getActivity()).dismissAllDialogFragments();
}).cancelable(true).cancelListener(dialog -> ((DeckPicker) getActivity()).dismissAllDialogFragments()).show();
}
use of com.ichi2.async.CancelListener in project AnkiChinaAndroid by ankichinateam.
the class DeckPickerBackupNoSpaceLeftDialog method onCreateDialog.
@Override
public MaterialDialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources();
long space = BackupManager.getFreeDiscSpace(CollectionHelper.getCollectionPath(getActivity()));
return new MaterialDialog.Builder(getActivity()).title(res.getString(R.string.sd_card_almost_full_title)).content(res.getString(R.string.sd_space_warning, space / 1024 / 1024)).positiveText(res.getString(R.string.dialog_ok)).onPositive((dialog, which) -> ((DeckPicker) getActivity()).finishWithoutAnimation()).cancelable(true).cancelListener(dialog -> ((DeckPicker) getActivity()).finishWithoutAnimation()).show();
}
use of com.ichi2.async.CancelListener in project Anki-Android by ankidroid.
the class SchedV2 method _walkingCount.
/**
* @param limFn Method sending a deck to the maximal number of card it can have. Normally into account both limits and cards seen today
* @param cntFn Method sending a deck to the number of card it has got to see today.
* @param cancelListener Whether the task is not useful anymore
* @return -1 if it's cancelled. Sum of the results of cntFn, limited by limFn,
*/
protected int _walkingCount(@NonNull LimitMethod limFn, @NonNull CountMethod cntFn, @Nullable CancelListener cancelListener) {
int tot = 0;
HashMap<Long, Integer> pcounts = HashUtil.HashMapInit(mCol.getDecks().count());
// for each of the active decks
for (long did : mCol.getDecks().active()) {
if (isCancelled(cancelListener))
return -1;
// get the individual deck's limit
int lim = limFn.operation(mCol.getDecks().get(did));
if (lim == 0) {
continue;
}
// check the parents
List<Deck> parents = mCol.getDecks().parents(did);
for (Deck p : parents) {
// add if missing
long id = p.getLong("id");
if (!pcounts.containsKey(id)) {
pcounts.put(id, limFn.operation(p));
}
// take minimum of child and parent
lim = Math.min(pcounts.get(id), lim);
}
// see how many cards we actually have
int cnt = cntFn.operation(did, lim);
// if non-zero, decrement from parents counts
for (Deck p : parents) {
long id = p.getLong("id");
pcounts.put(id, pcounts.get(id) - cnt);
}
// we may also be a parent
pcounts.put(did, lim - cnt);
// and add to running total
tot += cnt;
}
return tot;
}
use of com.ichi2.async.CancelListener in project AnkiChinaAndroid by ankichinateam.
the class DeckPickerNoSpaceLeftDialog method onCreateDialog.
@Override
public MaterialDialog onCreateDialog(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources();
return new MaterialDialog.Builder(getActivity()).title(res.getString(R.string.sd_card_full_title)).content(res.getString(R.string.backup_deck_no_space_left)).cancelable(true).positiveText(res.getString(R.string.dialog_ok)).onPositive((dialog, which) -> ((DeckPicker) getActivity()).startLoadingCollection()).cancelListener(dialog -> ((DeckPicker) getActivity()).startLoadingCollection()).show();
}
use of com.ichi2.async.CancelListener in project Anki-Android by ankidroid.
the class Sched method deckDueList.
/*
Deck list **************************************************************** *******************************
*/
/**
* Returns [deckname, did, rev, lrn, new]
*/
@Override
@Nullable
public List<DeckDueTreeNode> deckDueList(@Nullable CancelListener cancelListener) {
_checkDay();
mCol.getDecks().checkIntegrity();
List<Deck> decks = mCol.getDecks().allSorted();
HashMap<String, Integer[]> lims = HashUtil.HashMapInit(decks.size());
ArrayList<DeckDueTreeNode> deckNodes = new ArrayList<>(decks.size());
for (Deck deck : decks) {
if (isCancelled(cancelListener)) {
return null;
}
String deckName = deck.getString("name");
String p = Decks.parent(deckName);
// new
int nlim = _deckNewLimitSingle(deck, false);
int rlim = _deckRevLimitSingle(deck, false);
if (!TextUtils.isEmpty(p)) {
Integer[] parentLims = lims.get(Decks.normalizeName(p));
// 'temporary for diagnosis of bug #6383'
Assert.that(parentLims != null, "Deck %s is supposed to have parent %s. It has not be found.", deckName, p);
nlim = Math.min(nlim, parentLims[0]);
// review
rlim = Math.min(rlim, parentLims[1]);
}
int _new = _newForDeck(deck.getLong("id"), nlim);
// learning
int lrn = _lrnForDeck(deck.getLong("id"));
// reviews
int rev = _revForDeck(deck.getLong("id"), rlim);
// save to list
deckNodes.add(new DeckDueTreeNode(mCol, deck.getString("name"), deck.getLong("id"), rev, lrn, _new));
// add deck as a parent
lims.put(Decks.normalizeName(deck.getString("name")), new Integer[] { nlim, rlim });
}
return deckNodes;
}
Aggregations