Search in sources :

Example 6 with ALL_DECKS_ID

use of com.ichi2.libanki.stats.Stats.ALL_DECKS_ID in project AnkiChinaAndroid by ankichinateam.

the class SelfStudyActivity method deckDropDownItemChanged.

/**
 * Performs changes relating to the Deck DropDown Item changing
 * Exists as mActionBarSpinner.setSelection() caused a loop in roboelectirc (calling onItemSelected())
 */
private void deckDropDownItemChanged(int position) {
    if (position <= 0) {
        mRestrictOnDeck = "";
        saveLastDeckId(ALL_DECKS_ID);
    } else {
        Deck deck = mDropDownDecks.get(position - 1);
        mRestrictOnDeck = "deck:\"" + deck.getString("name") + "\" ";
        saveLastDeckId(deck.getLong("id"));
    }
// searchCards();
}
Also used : Deck(com.ichi2.libanki.Deck)

Example 7 with ALL_DECKS_ID

use of com.ichi2.libanki.stats.Stats.ALL_DECKS_ID in project AnkiChinaAndroid by ankichinateam.

the class StudyOptionsFragment method getDeckIds.

public static List<Long> getDeckIds(Long deckId, Collection col) {
    ArrayList<Long> ids = new ArrayList<>();
    if (deckId == ALL_DECKS_ID) {
        // All decks
        for (Deck d : col.getDecks().all()) {
            ids.add(d.getLong("id"));
        }
        return ids;
    } else {
        // The given deck id and its children
        ids.add(deckId);
        ids.addAll(col.getDecks().children(deckId).values());
        return ids;
    }
}
Also used : ArrayList(java.util.ArrayList) Deck(com.ichi2.libanki.Deck)

Example 8 with ALL_DECKS_ID

use of com.ichi2.libanki.stats.Stats.ALL_DECKS_ID in project AnkiChinaAndroid by ankichinateam.

the class CardBrowser method onCollectionLoaded.

// Finish initializing the activity after the collection has been correctly loaded
@Override
protected void onCollectionLoaded(Collection col) {
    super.onCollectionLoaded(col);
    Timber.d("onCollectionLoaded()");
    registerExternalStorageListener();
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    // Load reference to action bar title
    mActionBarTitle = (TextView) findViewById(R.id.toolbar_title);
    // Add drop-down menu to select deck to action bar.
    mDropDownDecks = getCol().getDecks().allSorted();
    mDropDownAdapter = new DeckDropDownAdapter(this, mDropDownDecks, R.layout.dropdown_deck_selected_item, this);
    Toolbar toolbar = findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        // enable ActionBar app icon to behave as action to toggle nav drawer
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        // Decide which action to take when the navigation button is tapped.
        toolbar.setNavigationOnClickListener(v -> finishActivityWithFade(this, ActivityTransitionAnimation.RIGHT));
    }
    ActionBar mActionBar = getSupportActionBar();
    if (mActionBar != null) {
        mActionBar.setDisplayShowTitleEnabled(false);
    }
    mActionBarSpinner = (Spinner) findViewById(R.id.toolbar_spinner);
    mActionBarSpinner.setAdapter(mDropDownAdapter);
    mActionBarSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            deckDropDownItemChanged(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // do nothing
        }
    });
    mActionBarSpinner.setVisibility(View.VISIBLE);
    mOrder = CARD_ORDER_NONE;
    String colOrder = getCol().getConf().getString("sortType");
    for (int c = 0; c < fSortTypes.length; ++c) {
        if (fSortTypes[c].equals(colOrder)) {
            mOrder = c;
            break;
        }
    }
    if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
        mOrder = 0;
    }
    // This upgrade should already have been done during
    // setConf. However older version of AnkiDroid didn't call
    // upgradeJSONIfNecessary during setConf, which means the
    // conf saved may still have this bug.
    mOrderAsc = Upgrade.upgradeJSONIfNecessary(getCol(), getCol().getConf(), "sortBackwards", false);
    mCards = new ArrayList<>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);
    // Create a spinner for column1
    Spinner cardsColumn1Spinner = (Spinner) findViewById(R.id.browser_column1_spinner);
    ArrayAdapter<CharSequence> column1Adapter = ArrayAdapter.createFromResource(this, R.array.browser_column1_headings, android.R.layout.simple_spinner_item);
    column1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    cardsColumn1Spinner.setAdapter(column1Adapter);
    mColumn1Index = AnkiDroidApp.getSharedPrefs(getBaseContext()).getInt("cardBrowserColumn1", 0);
    cardsColumn1Spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            // If a new column was selected then change the key used to map from mCards to the column TextView
            if (pos != mColumn1Index) {
                mColumn1Index = pos;
                AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putInt("cardBrowserColumn1", mColumn1Index).commit();
                Column[] fromMap = mCardsAdapter.getFromMapping();
                fromMap[0] = COLUMN1_KEYS[mColumn1Index];
                mCardsAdapter.setFromMapping(fromMap);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // Do Nothing
        }
    });
    // Load default value for column2 selection
    mColumn2Index = AnkiDroidApp.getSharedPrefs(getBaseContext()).getInt("cardBrowserColumn2", 0);
    // Setup the column 2 heading as a spinner so that users can easily change the column type
    Spinner cardsColumn2Spinner = (Spinner) findViewById(R.id.browser_column2_spinner);
    ArrayAdapter<CharSequence> column2Adapter = ArrayAdapter.createFromResource(this, R.array.browser_column2_headings, android.R.layout.simple_spinner_item);
    column2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    cardsColumn2Spinner.setAdapter(column2Adapter);
    // Create a new list adapter with updated column map any time the user changes the column
    cardsColumn2Spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            // If a new column was selected then change the key used to map from mCards to the column TextView
            if (pos != mColumn2Index) {
                mColumn2Index = pos;
                AnkiDroidApp.getSharedPrefs(AnkiDroidApp.getInstance().getBaseContext()).edit().putInt("cardBrowserColumn2", mColumn2Index).commit();
                Column[] fromMap = mCardsAdapter.getFromMapping();
                fromMap[1] = COLUMN2_KEYS[mColumn2Index];
                mCardsAdapter.setFromMapping(fromMap);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        // Do Nothing
        }
    });
    // get the font and font size from the preferences
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    Column[] columnsContent = { COLUMN1_KEYS[mColumn1Index], COLUMN2_KEYS[mColumn2Index] };
    // make a new list adapter mapping the data in mCards to column1 and column2 of R.layout.card_item_browser
    mCardsAdapter = new MultiColumnListAdapter(this, R.layout.card_item_browser, columnsContent, new int[] { R.id.card_sfld, R.id.card_column2 }, sflRelativeFontSize, sflCustomFont);
    // link the adapter to the main mCardsListView
    mCardsListView.setAdapter(mCardsAdapter);
    // make the items (e.g. question & answer) render dynamically when scrolling
    mCardsListView.setOnScrollListener(new RenderOnScroll());
    // set the spinner index
    cardsColumn1Spinner.setSelection(mColumn1Index);
    cardsColumn2Spinner.setSelection(mColumn2Index);
    mCardsListView.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mInMultiSelectMode) {
                // click on whole cell triggers select
                CheckBox cb = (CheckBox) view.findViewById(R.id.card_checkbox);
                cb.toggle();
                onCheck(position, view);
            } else {
                // load up the card selected on the list
                long clickedCardId = getCards().get(position).getId();
                openNoteEditorForCard(clickedCardId);
            }
        }
    });
    mCardsListView.setOnItemLongClickListener(new ListView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, final int position, long id) {
            mLastSelectedPosition = position;
            loadMultiSelectMode();
            // click on whole cell triggers select
            CheckBox cb = (CheckBox) view.findViewById(R.id.card_checkbox);
            cb.toggle();
            onCheck(position, view);
            recenterListView(view);
            mCardsAdapter.notifyDataSetChanged();
            return true;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    // If a valid value for last deck exists then use it, otherwise use libanki selected deck
    if (getLastDeckId() != null && getLastDeckId() == ALL_DECKS_ID) {
        selectAllDecks();
    } else if (getLastDeckId() != null && getCol().getDecks().get(getLastDeckId(), false) != null) {
        selectDeckById(getLastDeckId());
    } else {
        selectDeckById(getCol().getDecks().selected());
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Spinner(android.widget.Spinner) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) DeckDropDownAdapter(com.ichi2.anki.widgets.DeckDropDownAdapter) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) Column(com.ichi2.anki.CardBrowser.Column) CheckBox(android.widget.CheckBox) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 9 with ALL_DECKS_ID

use of com.ichi2.libanki.stats.Stats.ALL_DECKS_ID in project AnkiChinaAndroid by ankichinateam.

the class CollectionTask method doInBackgroundLoadSpecificDeckCounts.

private TaskData doInBackgroundLoadSpecificDeckCounts(TaskData param) {
    Timber.d("doInBackgroundLoadDeckCounts");
    Collection col = getCol();
    long did = param == null ? ALL_DECKS_ID : param.getLong();
    try {
        // Get due tree
        Object[] o = new Object[] { col.getSched().deckDueTree(this, did) };
        return new TaskData(o);
    } catch (RuntimeException e) {
        Timber.e(e, "doInBackgroundLoadDeckCounts - error");
        return null;
    }
}
Also used : Collection(com.ichi2.libanki.Collection) JSONObject(com.ichi2.utils.JSONObject)

Example 10 with ALL_DECKS_ID

use of com.ichi2.libanki.stats.Stats.ALL_DECKS_ID in project AnkiChinaAndroid by ankichinateam.

the class Stats method deckLimit.

/**
 * Note: NOT in libanki
 * Return a string of deck ids for the provided deck and its children, suitable for an SQL query
 *
 * @param deckId the deck id to filter on, or ALL_DECKS_ID for all decks
 * @param col    collection
 * @return
 */
public static String deckLimit(Long deckId, Collection col) {
    ArrayList<Long> ids = new ArrayList<>();
    if (deckId == ALL_DECKS_ID) {
        // All decks
        for (Deck d : col.getDecks().all()) {
            ids.add(d.getLong("id"));
        }
        return Utils.ids2str(Utils.collection2Array(ids));
    } else {
        // The given deck id and its children
        ids.add(deckId);
        ids.addAll(col.getDecks().children(deckId).values());
        return Utils.ids2str(ids);
    }
}
Also used : ArrayList(java.util.ArrayList) Deck(com.ichi2.libanki.Deck)

Aggregations

Deck (com.ichi2.libanki.Deck)9 ArrayList (java.util.ArrayList)7 View (android.view.View)4 TextView (android.widget.TextView)4 SharedPreferences (android.content.SharedPreferences)3 AdapterView (android.widget.AdapterView)3 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)3 CheckBox (android.widget.CheckBox)3 Spinner (android.widget.Spinner)3 Nullable (androidx.annotation.Nullable)3 SearchView (androidx.appcompat.widget.SearchView)3 Column (com.ichi2.anki.CardBrowser.Column)3 AbsListView (android.widget.AbsListView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 ActionBar (androidx.appcompat.app.ActionBar)2 Toolbar (androidx.appcompat.widget.Toolbar)2 DeckDropDownAdapter (com.ichi2.anki.widgets.DeckDropDownAdapter)2 Collection (com.ichi2.libanki.Collection)2 JSONObject (com.ichi2.utils.JSONObject)2