Search in sources :

Example 11 with TaskData

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

the class SelfStudyActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // FIXME:
    Timber.d("onActivityResult(requestCode=%d, resultCode=%d)", requestCode, resultCode);
    if (data != null) {
        Timber.d("onActivityResult data (reloadRequired=%s, noteChanged=%s)", data.getBooleanExtra("reloadRequired", false), data.getBooleanExtra("noteChanged", false));
    }
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == DeckPicker.RESULT_DB_ERROR) {
        closeCardBrowser(DeckPicker.RESULT_DB_ERROR);
    }
    if (requestCode == EDIT_CARD && resultCode != RESULT_CANCELED) {
        Timber.i("CardBrowser:: CardBrowser: Saving card...");
        CollectionTask.launchCollectionTask(UPDATE_NOTE, updateCardHandler(), new TaskData(sCardBrowserCard, false));
    } else if (requestCode == ADD_NOTE && resultCode == RESULT_OK) {
        if (mSearchView != null) {
            mSearchTerms = mSearchView.getQuery().toString();
            searchCards();
        } else {
            Timber.w("Note was added from browser and on return mSearchView == null");
        }
    }
    // }
    if (requestCode == PREVIEW_CARDS && data != null && (data.getBooleanExtra("reloadRequired", false) || data.getBooleanExtra("noteChanged", false))) {
        searchCards();
        if (getReviewerCardId() == mCurrentCardId) {
            mReloadRequired = true;
        }
    }
    if (requestCode == EDIT_CARD && data != null && (data.getBooleanExtra("reloadRequired", false) || data.getBooleanExtra("noteChanged", false))) {
        // if reloadRequired or noteChanged flag was sent from note editor then reload card list
        searchCards();
        // in use by reviewer?
        if (getReviewerCardId() == mCurrentCardId) {
            mReloadRequired = true;
        }
    }
    // maybe the availability of undo changed
    invalidateOptionsMenu();
}
Also used : TaskData(com.ichi2.async.TaskData)

Example 12 with TaskData

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

the class UIUtils method saveCollectionInBackground.

public static void saveCollectionInBackground(boolean syncIgnoresDatabaseModification) {
    if (CollectionHelper.getInstance().colIsOpen()) {
        TaskListener listener = new TaskListener() {

            @Override
            public void onPreExecute() {
                Timber.d("saveCollectionInBackground: start");
            }

            @Override
            public void onPostExecute(TaskData result) {
                Timber.d("saveCollectionInBackground: finished");
            }
        };
        CollectionTask.launchCollectionTask(SAVE_COLLECTION, listener, new TaskData(syncIgnoresDatabaseModification));
    }
}
Also used : TaskListener(com.ichi2.async.TaskListener) TaskData(com.ichi2.async.TaskData)

Example 13 with TaskData

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

the class Previewer2 method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.action_edit:
            editCard();
            return true;
        case R.id.action_suspend:
            if (mCurrentCard != null && mCurrentCard.getQueue() == Consts.QUEUE_TYPE_SUSPENDED) {
                Toast.makeText(Previewer2.this, "已恢复该卡牌", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(Previewer2.this, "已暂停该卡牌", Toast.LENGTH_SHORT).show();
            }
            blockControls(false);
            CollectionTask.launchCollectionTask(DISMISS, mDismissCardHandler, new TaskData(new Object[] { mCurrentCard, Collection.DismissType.SUSPEND_CARD }));
            return true;
        case R.id.action_delete:
            showDeleteNoteDialog();
            return true;
        case R.id.action_flag_zero:
            flagTask(0);
            return true;
        case R.id.action_flag_one:
            flagTask(1);
            return true;
        case R.id.action_flag_two:
            flagTask(2);
            return true;
        case R.id.action_flag_three:
            flagTask(3);
            return true;
        case R.id.action_flag_four:
            flagTask(4);
            return true;
        case R.id.action_mark_card:
            onMark(mCurrentCard);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : TaskData(com.ichi2.async.TaskData)

Example 14 with TaskData

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

the class Previewer2 method showDeleteNoteDialog.

@Override
protected void showDeleteNoteDialog() {
    Resources res = getResources();
    new MaterialDialog.Builder(this).title(res.getString(R.string.delete_card_title)).iconAttr(R.attr.dialogErrorIcon).content(res.getString(R.string.delete_note_message, Utils.stripHTML(mCurrentCard.q(true)))).positiveText(res.getString(R.string.dialog_positive_delete)).negativeText(res.getString(R.string.dialog_cancel)).onPositive((dialog, which) -> {
        Timber.i("AbstractFlashcardViewer:: OK button pressed to delete note %d", mCurrentCard.getNid());
        mSoundPlayer.stopSounds();
        blockControls(false);
        CollectionTask.launchCollectionTask(DISMISS, mDismissCardHandler, new TaskData(new Object[] { mCurrentCard, Collection.DismissType.DELETE_NOTE }));
        mCardList[mIndex] = mCardList[mCardList.length - 1];
        // 数组缩容
        mCardList = Arrays.copyOf(mCardList, mCardList.length - 1);
        mIndex--;
        mNextCardLayout.performClick();
        // updateScreenCounts();
        Toast.makeText(Previewer2.this, "成功删除卡牌", Toast.LENGTH_SHORT).show();
    }).build().show();
}
Also used : Resources(android.content.res.Resources) TaskData(com.ichi2.async.TaskData)

Example 15 with TaskData

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

the class Reviewer method performReload.

@Override
protected void performReload() {
    getCol().getSched().deferReset();
    CollectionTask.launchCollectionTask(ANSWER_CARD, mAnswerCardHandler(false), new TaskData(null, 0));
}
Also used : TaskData(com.ichi2.async.TaskData)

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