Search in sources :

Example 1 with LEFT

use of com.ichi2.anim.ActivityTransitionAnimation.LEFT in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method configureToolbarInternal.

// This will allow a maximum of one recur in order to workaround database closes
// caused by sync on startup where this might be running then have the collection close
private void configureToolbarInternal(boolean recur) {
    try {
        mToolbar.setOnMenuItemClickListener(this);
        Menu menu = mToolbar.getMenu();
        // Switch on or off rebuild/empty/custom study depending on whether or not filtered deck
        if (getCol().getDecks().isDyn(getCol().getDecks().selected())) {
            menu.findItem(R.id.action_add_card).setVisible(false);
            menu.findItem(R.id.action_rebuild).setVisible(true);
            menu.findItem(R.id.action_empty).setVisible(true);
            menu.findItem(R.id.action_custom_study).setVisible(false);
            menu.findItem(R.id.action_rename).setVisible(false);
            menu.findItem(R.id.create_deck).setVisible(false);
            menu.findItem(R.id.action_suspend).setVisible(false);
            menu.findItem(R.id.action_reset_card_progress).setVisible(false);
            menu.findItem(R.id.action_delete).setVisible(false);
            menu.findItem(R.id.action_export).setVisible(false);
            menu.findItem(R.id.action_setting).setVisible(false);
        } else {
            menu.findItem(R.id.action_rebuild).setVisible(false);
            menu.findItem(R.id.action_empty).setVisible(false);
            menu.findItem(R.id.action_custom_study).setVisible(true);
            menu.findItem(R.id.action_rename).setVisible(true);
            menu.findItem(R.id.create_deck).setVisible(true);
            menu.findItem(R.id.action_suspend).setVisible(true);
            menu.findItem(R.id.action_suspend).setTitle(deckIsStopped() ? "恢复学习" : "停止学习");
            menu.findItem(R.id.action_reset_card_progress).setVisible(true);
            menu.findItem(R.id.action_delete).setVisible(true);
            menu.findItem(R.id.action_export).setVisible(true);
            menu.findItem(R.id.action_setting).setVisible(true);
            menu.findItem(R.id.action_deck_options).setVisible(true);
        }
        // Don't show custom study icon if congrats shown
        // if (mCurrentContentView == CONTENT_CONGRATS) {
        // menu.findItem(R.id.action_custom_study).setVisible(false);
        // }
        // Switch on or off unbury depending on if there are cards to unbury
        menu.findItem(R.id.action_unbury).setVisible(getCol().getSched().haveBuried());
        // Switch on or off undo depending on whether undo is available
        menu.findItem(R.id.action_undo).setVisible(false);
    } catch (IllegalStateException e) {
        if (!CollectionHelper.getInstance().colIsOpen()) {
            if (recur) {
                Timber.i(e, "Database closed while working. Probably auto-sync. Will re-try after sleep.");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Timber.i(ex, "Thread interrupted while waiting to retry. Likely unimportant.");
                    Thread.currentThread().interrupt();
                }
                configureToolbarInternal(false);
            } else {
                Timber.w(e, "Database closed while working. No re-tries left.");
            }
        }
    }
}
Also used : DeckPickerContextMenu(com.ichi2.anki.dialogs.DeckPickerContextMenu) Menu(android.view.Menu)

Example 2 with LEFT

use of com.ichi2.anim.ActivityTransitionAnimation.LEFT in project AnkiChinaAndroid by ankichinateam.

the class SelfStudyActivity method initSearchView.

private void initSearchView() {
    mSearchView = findViewById(R.id.search_view);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mSearchView.getLayoutParams();
    layoutParams.gravity = Gravity.CENTER;
    mSearchView.setLayoutParams(layoutParams);
    mSearchView.setOnCloseListener(() -> {
        mSearchTerms = "";
        Timber.i("close search view");
        mSearchView.setQuery(mSearchTerms, false);
        searchCards();
        return false;
    });
    mSearchView.setQueryHint("输入关键词或语法");
    mSearchView.setIconifiedByDefault(false);
    // Get ImageView of icon
    // ImageView searchViewIcon = (ImageView)mSearchView.findViewById(androidx.appcompat.R.id.search_mag_icon);
    // //         Get parent of gathered icon
    // ViewGroup linearLayoutSearchView = (ViewGroup) searchViewIcon.getParent(); //Remove it from the left...
    // linearLayoutSearchView.removeView(searchViewIcon); //then put it back (to the right by default)
    // linearLayoutSearchView.addView(searchViewIcon);
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String newText) {
            if (newText.equals("")) {
                mSearchTerms = "";
            }
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            onSearch();
            mSearchView.clearFocus();
            return true;
        }
    });
    mSearchView.setOnSearchClickListener(v -> {
        // Provide SearchView with the previous search terms
        mSearchView.setQuery(mSearchTerms, false);
    // System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
    // //为数组最后一位赋值
    // mHits[mHits.length - 1] = SystemClock.uptimeMillis();
    // if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
    // mHits = new long[COUNTS];//重新初始化数组
    // mShowGrammarInSearchView=true;
    // Toast.makeText(SelfStudyActivity.this, "显示语法在搜索栏", Toast.LENGTH_LONG).show();
    // }
    });
    mSearchView.setOnFocusChangeListener((v, hasFocus) -> {
        mStartStudyButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
        if (hasFocus) {
            return;
        }
        InputMethodManager manager = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
        if (manager != null && getCurrentFocus() != null) {
            manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    });
    mSearchView.setOnClickListener(v -> {
        // 每次点击时,数组向前移动一位
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        // 为数组最后一位赋值
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
            // 重新初始化数组
            mHits = new long[COUNTS];
            mShowGrammarInSearchView = true;
            Toast.makeText(SelfStudyActivity.this, "显示语法在搜索栏", Toast.LENGTH_LONG).show();
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) InputMethodManager(android.view.inputmethod.InputMethodManager) WarpLinearLayout(com.ichi2.ui.WarpLinearLayout) LinearLayout(android.widget.LinearLayout)

Example 3 with LEFT

use of com.ichi2.anim.ActivityTransitionAnimation.LEFT in project AnkiChinaAndroid by ankichinateam.

the class Sched method _fillRev.

@Override
protected boolean _fillRev(boolean allowSibling) {
    if (!mRevQueue.isEmpty()) {
        return true;
    }
    if (mRevCount == 0) {
        return false;
    }
    SupportSQLiteDatabase db = mCol.getDb().getDatabase();
    while (!mRevDids.isEmpty()) {
        long did = mRevDids.getFirst();
        int lim = Math.min(mQueueLimit, _deckRevLimit(did));
        Cursor cur = null;
        if (lim != 0) {
            mRevQueue.clear();
            // fill the queue with the current did
            try {
                /* Difference with upstream: we take current card into account.
                     *
                     * When current card is answered, the card is not due anymore, so does not belong to the queue.
                     * Furthermore, _burySiblings ensure that the siblings of the current cards are removed from the
                     * queue to ensure same day spacing. We simulate this action by ensuring that those siblings are not
                     * filled, except if we know there are cards and we didn't find any non-sibling card. This way, the
                     * queue is not empty if it should not be empty (important for the conditional belows), but the
                     * front of the queue contains distinct card.
                     */
                String idName = (allowSibling) ? "id" : "nid";
                long id = (allowSibling) ? currentCardId() : currentCardNid();
                cur = db.query("SELECT id FROM cards WHERE did = ? AND queue = " + Consts.QUEUE_TYPE_REV + " AND due <= ?" + " AND " + idName + " != ? LIMIT ?", new Object[] { did, mToday, id, lim });
                while (cur.moveToNext()) {
                    mRevQueue.add(cur.getLong(0));
                }
            } finally {
                if (cur != null && !cur.isClosed()) {
                    cur.close();
                }
            }
            if (!mRevQueue.isEmpty()) {
                // ordering
                if (mCol.getDecks().get(did).getInt("dyn") != 0) {
                // dynamic decks need due order preserved
                // Note: libanki reverses mRevQueue and returns the last element in _getRevCard().
                // AnkiDroid differs by leaving the queue intact and returning the *first* element
                // in _getRevCard().
                } else {
                    Random r = new Random();
                    r.setSeed(mToday);
                    mRevQueue.shuffle(r);
                }
                // is the current did empty?
                if (mRevQueue.size() < lim) {
                    mRevDids.remove();
                }
                return true;
            }
        }
        // nothing left in the deck; move to next
        mRevDids.remove();
    }
    // Since we didn't get a card and the count is non-zero, we
    // need to check again for any cards that were removed from
    // the queue but not buried
    _resetRev();
    return _fillRev(true);
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) Random(java.util.Random) JSONObject(com.ichi2.utils.JSONObject) Cursor(android.database.Cursor)

Example 4 with LEFT

use of com.ichi2.anim.ActivityTransitionAnimation.LEFT in project AnkiChinaAndroid by ankichinateam.

the class NoteImporter method initMapping.

public void initMapping() {
    List<String> flds = new ArrayList<>();
    JSONArray array = mModel.getJSONArray("flds");
    for (int i = 0; i < array.length(); i++) {
        flds.add(array.getJSONObject(i).getString("name"));
    }
    // truncate to provided count
    flds = flds.subList(0, Math.min(flds.size(), fields()));
    // if there's room left, add tags
    if (fields() > flds.size()) {
        flds.add("_tags");
    }
    // and if there's still room left, pad
    int iterations = fields() - flds.size();
    for (int i = 0; i < iterations; i++) {
        flds.add(null);
    }
    mMapping = flds;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(com.ichi2.utils.JSONArray)

Example 5 with LEFT

use of com.ichi2.anim.ActivityTransitionAnimation.LEFT in project AnkiChinaAndroid by ankichinateam.

the class SchedV2 method _delayForGrade.

protected int _delayForGrade(JSONObject conf, int left) {
    left = left % 1000;
    try {
        double delay;
        JSONArray delays = conf.getJSONArray("delays");
        int len = delays.length();
        try {
            delay = delays.getDouble(len - left);
        } catch (JSONException e) {
            if (conf.getJSONArray("delays").length() > 0) {
                delay = conf.getJSONArray("delays").getDouble(0);
            } else {
                // user deleted final step; use dummy value
                delay = 1.0;
            }
        }
        return (int) (delay * 60.0);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}
Also used : JSONArray(com.ichi2.utils.JSONArray) JSONException(com.ichi2.utils.JSONException)

Aggregations

JSONArray (com.ichi2.utils.JSONArray)16 Card (com.ichi2.libanki.Card)14 Collection (com.ichi2.libanki.Collection)12 JSONObject (com.ichi2.utils.JSONObject)12 DeckConfig (com.ichi2.libanki.DeckConfig)11 Note (com.ichi2.libanki.Note)11 Test (org.junit.Test)11 RobolectricTest (com.ichi2.anki.RobolectricTest)10 Cursor (android.database.Cursor)8 ArrayList (java.util.ArrayList)8 Nullable (androidx.annotation.Nullable)7 JSONException (com.ichi2.utils.JSONException)7 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)5 Model (com.ichi2.libanki.Model)4 IOException (java.io.IOException)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 Menu (android.view.Menu)3 View (android.view.View)3