Search in sources :

Example 86 with TaskData

use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method updateDeckList.

public void updateDeckList(boolean quick) {
    processNames();
    TaskListener listener = updateDeckListListener();
    CollectionTask.TASK_TYPE taskType = quick ? LOAD_DECK_QUICK : LOAD_SPECIFIC_DECK_COUNTS;
    CollectionTask.launchCollectionTask(taskType, listener, new TaskData(mCacheID));
}
Also used : TASK_TYPE(com.ichi2.async.CollectionTask.TASK_TYPE) TaskListener(com.ichi2.async.TaskListener) CollectionTask(com.ichi2.async.CollectionTask) TaskData(com.ichi2.async.TaskData)

Example 87 with TaskData

use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.

the class Reviewer method onCollectionLoaded.

@Override
protected void onCollectionLoaded(Collection col) {
    super.onCollectionLoaded(col);
    // Load the first card and start reviewing. Uses the answer card
    // task to load a card, but since we send null
    // as the card to answer, no card will be answered.
    mPrefWhiteboard = MetaDB.getWhiteboardState(this, getParentDid());
    if (mPrefWhiteboard) {
        // DEFECT: Slight inefficiency here, as we set the database using these methods
        boolean whiteboardVisibility = MetaDB.getWhiteboardVisibility(this, getParentDid());
        setWhiteboardEnabledState(true);
        setWhiteboardVisibility(whiteboardVisibility);
    }
    // Reset schedule in case card was previously loaded
    col.getSched().deferReset();
    getCol().startTimebox();
    CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false), new TaskData(null, 0));
    disableDrawerSwipeOnConflicts();
    // Add a weak reference to current activity so that scheduler can talk to to Activity
    mSched.setContext(new WeakReference<Activity>(this));
    // Set full screen/immersive mode if needed
    if (mPrefFullscreenReview) {
        CompatHelper.getCompat().setFullScreen(this);
    }
}
Also used : Activity(android.app.Activity) TaskData(com.ichi2.async.TaskData)

Example 88 with TaskData

use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.

the class Reviewer method showRescheduleCardDialog.

private void showRescheduleCardDialog() {
    Consumer<Integer> runnable = days -> CollectionTask.launchCollectionTask(DISMISS_MULTI, mRescheduleCardHandler, new TaskData(new Object[] { new long[] { mCurrentCard.getId() }, Collection.DismissType.RESCHEDULE_CARDS, days }));
    RescheduleDialog dialog = RescheduleDialog.rescheduleSingleCard(getResources(), mCurrentCard, runnable);
    showDialogFragment(dialog);
}
Also used : JavascriptInterface(android.webkit.JavascriptInterface) LinearLayout(android.widget.LinearLayout) COMMAND_NOTHING(com.ichi2.anki.cardviewer.ViewerCommand.COMMAND_NOTHING) Bundle(android.os.Bundle) MenuItemCompat(androidx.core.view.MenuItemCompat) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) UnderlineSpan(android.text.style.UnderlineSpan) DrawableRes(androidx.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) Permissions(com.ichi2.utils.Permissions) ActionBar(androidx.appcompat.app.ActionBar) Decks(com.ichi2.libanki.Decks) Handler(android.os.Handler) View(android.view.View) TaskData(com.ichi2.async.TaskData) ActionButtons(com.ichi2.anki.reviewer.ActionButtons) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ContextCompat(androidx.core.content.ContextCompat) FLAG_NONE(com.ichi2.anki.reviewer.CardMarker.FLAG_NONE) DismissType(com.ichi2.libanki.Collection.DismissType) CardMarker(com.ichi2.anki.reviewer.CardMarker) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) TextView(android.widget.TextView) Message(android.os.Message) Consts(com.ichi2.libanki.Consts) CompatHelper(com.ichi2.compat.CompatHelper) AudioView(com.ichi2.anki.multimediacard.AudioView) Context(android.content.Context) TaskListener(com.ichi2.async.TaskListener) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Intent(android.content.Intent) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) Collection(com.ichi2.libanki.Collection) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) TASK_TYPE(com.ichi2.async.CollectionTask.TASK_TYPE) WidgetStatus(com.ichi2.widget.WidgetStatus) PeripheralKeymap(com.ichi2.anki.reviewer.PeripheralKeymap) Menu(android.view.Menu) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) Utils(com.ichi2.libanki.Utils) Consumer(com.ichi2.utils.FunctionalInterfaces.Consumer) SpannableString(android.text.SpannableString) ActivityCompat(androidx.core.app.ActivityCompat) ReviewerUi(com.ichi2.anki.reviewer.ReviewerUi) CollectionTask(com.ichi2.async.CollectionTask) Themes(com.ichi2.themes.Themes) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ActionProvider(androidx.core.view.ActionProvider) FirefoxSnackbarWorkaround(com.ichi2.anki.workarounds.FirefoxSnackbarWorkaround) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) TaskData(com.ichi2.async.TaskData)

Example 89 with TaskData

use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.

the class Reviewer method showResetCardDialog.

private void showResetCardDialog() {
    // Show confirmation dialog before resetting card progress
    Timber.i("showResetCardDialog() Reset progress button pressed");
    // Show confirmation dialog before resetting card progress
    ConfirmationDialog dialog = new ConfirmationDialog();
    String title = getResources().getString(R.string.reset_card_dialog_title);
    String message = getResources().getString(R.string.reset_card_dialog_message);
    dialog.setArgs(title, message);
    Runnable confirm = () -> {
        Timber.i("NoteEditor:: ResetProgress button pressed");
        CollectionTask.launchCollectionTask(DISMISS_MULTI, mResetProgressCardHandler, new TaskData(new Object[] { new long[] { mCurrentCard.getId() }, Collection.DismissType.RESET_CARDS }));
    };
    dialog.setConfirm(confirm);
    showDialogFragment(dialog);
}
Also used : SpannableString(android.text.SpannableString) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) TaskData(com.ichi2.async.TaskData)

Example 90 with TaskData

use of com.ichi2.async.TaskData in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method openReviewer.

private void openReviewer() {
    if (mShouldConfigBeforeStudy && mOptions != null) {
        SharedPreferences sharedPreferences = getAnkiActivity().getSharedPreferences(STUDY_SETTING, 0);
        StringBuilder initIds = new StringBuilder(sharedPreferences.getString(KEY_CONFIG_INIT, ""));
        if (initIds.length() > 0) {
            String[] ids = initIds.toString().split(",");
            if (ids.length > 0) {
                for (String id : ids) {
                    if (getCol().getDecks().current().getLong("id") == Long.parseLong(id)) {
                        // 已经初始化过了,直接跳过
                        openReviewerInternal();
                        return;
                    }
                }
            }
        // 没初始化过,那现在也初始化了。
        // initIds.append(",");
        }
        for (long id : getDeckIds(getCol().getDecks().current().getLong("id"), getCol())) {
            if (!initIds.toString().isEmpty()) {
                initIds.append(",");
            }
            initIds.append(id);
        }
        // initIds += Stats.deckLimit(getCol().getDecks().current().getLong("id"), getCol()).replace("(","").replace(")","").trim();//要把子牌组也加入里面
        sharedPreferences.edit().putString(KEY_CONFIG_INIT, initIds.toString()).apply();
        String savedMindModeValue = sharedPreferences.getString(KEY_MIND_MODE, "");
        Map<String, Integer> map = null;
        try {
            Gson gson = new Gson();
            map = gson.fromJson(savedMindModeValue, new TypeToken<Map<String, Integer>>() {
            }.getType());
        } catch (Exception e) {
            e.printStackTrace();
        }
        String mDeckIdStr = String.valueOf(getCol().getDecks().current().getLong("id"));
        mCurrentMindModeValue = map != null && map.get(mDeckIdStr) != null ? map.get(mDeckIdStr) : 0;
        if (mMindModeValues == null) {
            mMindModeValues = getResources().getStringArray(R.array.mind_mode_values);
            mMindModeLabels = getResources().getStringArray(R.array.mind_mode_labels);
            mMindModeHints = getResources().getStringArray(R.array.mind_mode_hint);
            for (int i = 0; i < mMindModeValues.length; i++) {
                mMindModeMap.put(Integer.valueOf(mMindModeValues[i]), mMindModeLabels[i]);
            }
        }
        CustomStyleDialog customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("记忆模式").setCustomLayout(R.layout.dialog_common_custom_next).setSelectListModeCallback(new CustomStyleDialog.Builder.SelectListModeCallback() {

            @Override
            public String[] getItemContent() {
                return mMindModeLabels;
            }

            @Override
            public String[] getItemHint() {
                return mMindModeHints;
            }

            @Override
            public int getDefaultSelectedPosition() {
                return mCurrentMindModeValue;
            }

            @Override
            public void onItemSelect(int position) {
                mCurrentMindModeValue = position;
            }
        }).setPositiveButton("下一步", (dialog, which) -> {
            String oldValue = sharedPreferences.getString(KEY_MIND_MODE, "");
            Map<String, Integer> oldMap = null;
            Gson gson = new Gson();
            try {
                oldMap = gson.fromJson(oldValue, new TypeToken<Map<String, Integer>>() {
                }.getType());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (oldMap == null) {
                oldMap = new HashMap<>();
            }
            for (long id : getDeckIds(getCol().getDecks().current().getLong("id"), getCol())) {
                // Timber.i("看看都是什么id %s", id);
                oldMap.put(String.valueOf(id), mCurrentMindModeValue);
            }
            String newValue = gson.toJson(oldMap);
            sharedPreferences.edit().putString(KEY_MIND_MODE, newValue).apply();
            CollectionTask.launchCollectionTask(CONF_RESET, new ConfChangeHandler(StudyOptionsFragment.this, mCurrentMindModeValue), // 先恢复默认,即长记模式
            new TaskData(new Object[] { mOptions }));
            dialog.dismiss();
        }).setNegativeButton("跳过", (dialog, which) -> {
            dialog.dismiss();
            try {
                getCol().getDecks().save(mOptions);
            } catch (RuntimeException e) {
                Timber.e(e, "DeckOptions - RuntimeException on saving conf");
                AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf");
            }
            refreshOption();
            openReviewerInternal();
        }).create();
        customDialog.show();
    } else {
        openReviewerInternal();
    }
}
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) SharedPreferences(android.content.SharedPreferences) Gson(com.google.gson.Gson) TaskData(com.ichi2.async.TaskData) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

Collection (com.ichi2.libanki.Collection)67 TaskData (com.ichi2.async.TaskData)46 JSONObject (com.ichi2.utils.JSONObject)35 Card (com.ichi2.libanki.Card)16 JSONException (com.ichi2.utils.JSONException)15 ArrayList (java.util.ArrayList)14 JSONObject (org.json.JSONObject)13 Resources (android.content.res.Resources)12 HashMap (java.util.HashMap)12 SharedPreferences (android.content.SharedPreferences)11 Deck (com.ichi2.libanki.Deck)11 Intent (android.content.Intent)10 View (android.view.View)9 TextView (android.widget.TextView)9 ConfirmationDialog (com.ichi2.anki.dialogs.ConfirmationDialog)9 TaskListener (com.ichi2.async.TaskListener)9 Map (java.util.Map)9 VisibleForTesting (androidx.annotation.VisibleForTesting)8 CollectionTask (com.ichi2.async.CollectionTask)8 IOException (java.io.IOException)8