Search in sources :

Example 1 with CancelListener

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();
}
Also used : DeckPicker(com.ichi2.anki.DeckPicker) Bundle(android.os.Bundle) AnkiDroidApp(com.ichi2.anki.AnkiDroidApp) AnalyticsDialogFragment(com.ichi2.anki.analytics.AnalyticsDialogFragment) R(com.ichi2.anki.R) UsageAnalytics(com.ichi2.anki.analytics.UsageAnalytics) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Resources(android.content.res.Resources) Resources(android.content.res.Resources) DeckPicker(com.ichi2.anki.DeckPicker)

Example 2 with CancelListener

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();
}
Also used : DeckPicker(com.ichi2.anki.DeckPicker) Bundle(android.os.Bundle) BackupManager(com.ichi2.anki.BackupManager) AnalyticsDialogFragment(com.ichi2.anki.analytics.AnalyticsDialogFragment) R(com.ichi2.anki.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CollectionHelper(com.ichi2.anki.CollectionHelper) Resources(android.content.res.Resources) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Resources(android.content.res.Resources) DeckPicker(com.ichi2.anki.DeckPicker)

Example 3 with CancelListener

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;
}
Also used : Deck(com.ichi2.libanki.Deck)

Example 4 with CancelListener

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();
}
Also used : DeckPicker(com.ichi2.anki.DeckPicker) Bundle(android.os.Bundle) AnalyticsDialogFragment(com.ichi2.anki.analytics.AnalyticsDialogFragment) R(com.ichi2.anki.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Resources(android.content.res.Resources) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Resources(android.content.res.Resources) DeckPicker(com.ichi2.anki.DeckPicker)

Example 5 with CancelListener

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;
}
Also used : ArrayList(java.util.ArrayList) Deck(com.ichi2.libanki.Deck) Nullable(androidx.annotation.Nullable)

Aggregations

Resources (android.content.res.Resources)3 Bundle (android.os.Bundle)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 DeckPicker (com.ichi2.anki.DeckPicker)3 R (com.ichi2.anki.R)3 AnalyticsDialogFragment (com.ichi2.anki.analytics.AnalyticsDialogFragment)3 Deck (com.ichi2.libanki.Deck)3 ArrayList (java.util.ArrayList)3 Nullable (androidx.annotation.Nullable)2 SuppressLint (android.annotation.SuppressLint)1 Cursor (android.database.Cursor)1 NonNull (androidx.annotation.NonNull)1 AnkiDroidApp (com.ichi2.anki.AnkiDroidApp)1 BackupManager (com.ichi2.anki.BackupManager)1 CollectionHelper (com.ichi2.anki.CollectionHelper)1 UsageAnalytics (com.ichi2.anki.analytics.UsageAnalytics)1 Decks (com.ichi2.libanki.Decks)1 ParsedNode (com.ichi2.libanki.template.ParsedNode)1 JSONException (com.ichi2.utils.JSONException)1 JSONObject (com.ichi2.utils.JSONObject)1