Search in sources :

Example 1 with REBUILD_CRAM

use of com.ichi2.async.CollectionTask.TASK_TYPE.REBUILD_CRAM in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method refreshOption.

private void refreshOption() {
    if (mLoadWithDeckOptions) {
        mLoadWithDeckOptions = false;
        Deck deck = getCol().getDecks().current();
        if (deck.getInt("dyn") != 0 && deck.has("empty")) {
            deck.remove("empty");
        }
        mProgressDialog = StyledProgressDialog.show(getActivity(), "", getResources().getString(R.string.rebuild_filtered_deck), true);
        CollectionTask.launchCollectionTask(REBUILD_CRAM, getCollectionTaskListener(true));
    } else {
        CollectionTask.waitToFinish();
        refreshInterface(true);
    }
}
Also used : Deck(com.ichi2.libanki.Deck)

Example 2 with REBUILD_CRAM

use of com.ichi2.async.CollectionTask.TASK_TYPE.REBUILD_CRAM in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method onMenuItemClick.

@SuppressWarnings("deprecation")
@Override
public boolean onMenuItemClick(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_browser:
            {
                Timber.i("DeckPicker:: Old browser button pressed");
                getAnkiActivity().openOldCardBrowser();
                return true;
            }
        case R.id.action_undo:
            Timber.i("StudyOptionsFragment:: Undo button pressed");
            CollectionTask.launchCollectionTask(UNDO, undoListener);
            return true;
        case R.id.action_deck_options:
            Timber.i("StudyOptionsFragment:: Deck options button pressed");
            if (getCol().getDecks().isDyn(getCol().getDecks().selected())) {
                openFilteredDeckOptions();
            } else {
                Intent i = new Intent(getActivity(), DeckOptions.class);
                getActivity().startActivityForResult(i, DECK_OPTIONS);
                ActivityTransitionAnimation.slide(getActivity(), ActivityTransitionAnimation.FADE);
            }
            return true;
        case R.id.action_setting:
            Timber.i("StudyOptionsFragment:: Deck setting button pressed");
            Intent i = new Intent(getActivity(), StudySettingActivity.class);
            getActivity().startActivityForResult(i, DECK_OPTIONS);
            ActivityTransitionAnimation.slide(getActivity(), ActivityTransitionAnimation.FADE);
            return true;
        case R.id.action_custom_study:
            Timber.i("StudyOptionsFragment:: custom study button pressed");
            showCustomStudyContextMenu();
            return true;
        case R.id.action_unbury:
            Timber.i("StudyOptionsFragment:: unbury button pressed");
            getCol().getSched().unburyCardsForDeck();
            refreshInterfaceAndDecklist(true);
            item.setVisible(false);
            return true;
        case R.id.action_rebuild:
            Timber.i("StudyOptionsFragment:: rebuild cram deck button pressed");
            mProgressDialog = StyledProgressDialog.show(getActivity(), "", getResources().getString(R.string.rebuild_filtered_deck), true);
            CollectionTask.launchCollectionTask(REBUILD_CRAM, getCollectionTaskListener(true));
            return true;
        case R.id.action_empty:
            Timber.i("StudyOptionsFragment:: empty cram deck button pressed");
            mProgressDialog = StyledProgressDialog.show(getActivity(), "", getResources().getString(R.string.empty_filtered_deck), false);
            CollectionTask.launchCollectionTask(EMPTY_CRAM, getCollectionTaskListener(true));
            return true;
        case R.id.action_rename:
            ((AnkiActivity) getActivity()).renameDeckDialog(getCol().getDecks().selected());
            return true;
        case R.id.action_delete:
            getAnkiActivity().mContextMenuDid = getCol().getDecks().selected();
            ((AnkiActivity) getActivity()).confirmDeckDeletion(getCol().getDecks().selected());
            return true;
        case R.id.action_export:
            ((AnkiActivity) getActivity()).exportDeck(getCol().getDecks().selected());
            return true;
        case R.id.action_add_card:
            addNote();
            return true;
        case R.id.create_deck:
            getAnkiActivity().mContextMenuDid = getCol().getDecks().selected();
            ((AnkiActivity) getActivity()).createSubdeckDialog();
            return true;
        case // 停止/恢复
        R.id.action_suspend:
            mDeckIsStopped = deckIsStopped();
            if (mDeckIsStopped) {
                customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("恢复学习").setMessage("恢复学习后将每天新卡数和复习数值调整成默认值,请确认是否开始学习").setPositiveButton("确定", (dialog, which) -> {
                    resumeDeckStudy();
                    dialog.dismiss();
                }).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
            } else {
                customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("停止学习").setMessage("暂停学习将会自动把每天新卡数和复习数调整为零,适用于有事暂停一两周不学习,若该记忆库学习的时长不超过2个月,又暂停了30天未学习,建议重设进度,重新开始学习").setPositiveButton("确定", (dialog, which) -> {
                    stopDeckStudy();
                    dialog.dismiss();
                }).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
            }
            customDialog.show();
            return true;
        case // 重设学习进度
        R.id.action_reset_card_progress:
            customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("重设学习进度").setMessage("重设学习进度后,该记忆库的所有卡片学习记录都会被清除,请谨慎操作").setPositiveButton("确定", (dialog, which) -> {
                CollectionTask.launchCollectionTask(RESET_DECK, new ResetCardHandler(StudyOptionsFragment.this), new TaskData(new Object[] { "deck:\"" + getCol().getDecks().current().getString("name") + "\" " }));
                dialog.dismiss();
            }).setNegativeButton("取消", (dialog, which) -> dialog.dismiss()).create();
            customDialog.show();
            return true;
        default:
            return false;
    }
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Bundle(android.os.Bundle) TypeToken(com.google.gson.reflect.TypeToken) Deck(com.ichi2.libanki.Deck) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) WindowManager(android.view.WindowManager) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Maps(java8.util.Maps) KEY_STOPPED(com.ichi2.anki.StudySettingActivity.KEY_STOPPED) DeckInfoListAdapter(com.ichi2.anki.widgets.DeckInfoListAdapter) Decks(com.ichi2.libanki.Decks) Gson(com.google.gson.Gson) Locale(java.util.Locale) Handler(android.os.Handler) DeckConfig(com.ichi2.libanki.DeckConfig) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) TaskData(com.ichi2.async.TaskData) RecyclerView(androidx.recyclerview.widget.RecyclerView) REQUEST_BROWSE_CARDS(com.ichi2.anki.DeckPicker.REQUEST_BROWSE_CARDS) TabLayout(com.google.android.material.tabs.TabLayout) TYPE_LIFE(com.ichi2.libanki.stats.Stats.AxisType.TYPE_LIFE) SHOW_STUDYOPTIONS(com.ichi2.anki.DeckPicker.SHOW_STUDYOPTIONS) Set(java.util.Set) FragmentTransaction(androidx.fragment.app.FragmentTransaction) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) DeckPickerContextMenu(com.ichi2.anki.dialogs.DeckPickerContextMenu) List(java.util.List) Nullable(androidx.annotation.Nullable) TextView(android.widget.TextView) NextCardHandler(com.ichi2.anki.AbstractFlashcardViewer.NextCardHandler) ALL_DECKS_ID(com.ichi2.libanki.stats.Stats.ALL_DECKS_ID) CompatHelper(com.ichi2.compat.CompatHelper) Toolbar(androidx.appcompat.widget.Toolbar) RelativeLayout(android.widget.RelativeLayout) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Window(android.view.Window) Snackbar(com.google.android.material.snackbar.Snackbar) DialogFragment(androidx.fragment.app.DialogFragment) KEY_SHOW_TTS_ICON(com.ichi2.libanki.Consts.KEY_SHOW_TTS_ICON) Context(android.content.Context) TaskListener(com.ichi2.async.TaskListener) Dialog(android.app.Dialog) Intent(android.content.Intent) StepsPreference.convertToJSON(com.ichi2.preferences.StepsPreference.convertToJSON) HashMap(java.util.HashMap) Collection(com.ichi2.libanki.Collection) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) PixelFormat(android.graphics.PixelFormat) Editable(android.text.Editable) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) TASK_TYPE(com.ichi2.async.CollectionTask.TASK_TYPE) ArrayList(java.util.ArrayList) JSONArray(com.ichi2.utils.JSONArray) Menu(android.view.Menu) Utils(com.ichi2.libanki.Utils) AbstractDeckTreeNode(com.ichi2.libanki.sched.AbstractDeckTreeNode) Stats(com.ichi2.libanki.stats.Stats) LayoutInflater(android.view.LayoutInflater) CollectionTask(com.ichi2.async.CollectionTask) Color(android.graphics.Color) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) TreeMap(java.util.TreeMap) KEY_MIND_MODE(com.ichi2.anki.StudySettingActivity.KEY_MIND_MODE) CustomStudyDialog(com.ichi2.anki.dialogs.CustomStudyDialog) DeckPicker.fadeOut(com.ichi2.anki.DeckPicker.fadeOut) Activity(android.app.Activity) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) DeckPicker.fadeIn(com.ichi2.anki.DeckPicker.fadeIn) STUDY_SETTING(com.ichi2.anki.StudySettingActivity.STUDY_SETTING) EditText(android.widget.EditText) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Resources(android.content.res.Resources) Intent(android.content.Intent) TaskData(com.ichi2.async.TaskData)

Example 3 with REBUILD_CRAM

use of com.ichi2.async.CollectionTask.TASK_TYPE.REBUILD_CRAM 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();
}
Also used : AnkiActivity(com.ichi2.anki.AnkiActivity) JSONArray(com.ichi2.utils.JSONArray) TaskListener(com.ichi2.async.TaskListener) Deck(com.ichi2.libanki.Deck) Collection(com.ichi2.libanki.Collection)

Aggregations

Deck (com.ichi2.libanki.Deck)3 TaskListener (com.ichi2.async.TaskListener)2 Collection (com.ichi2.libanki.Collection)2 JSONArray (com.ichi2.utils.JSONArray)2 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 Context (android.content.Context)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Resources (android.content.res.Resources)1 TypedArray (android.content.res.TypedArray)1 Color (android.graphics.Color)1 PixelFormat (android.graphics.PixelFormat)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Editable (android.text.Editable)1 DisplayMetrics (android.util.DisplayMetrics)1