Search in sources :

Example 1 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class DeckOptions method buildLists.

// Tracked as #5019 on github
@SuppressWarnings("deprecation")
protected void buildLists() {
    android.preference.ListPreference deckConfPref = (android.preference.ListPreference) findPreference("deckConf");
    ArrayList<DeckConfig> confs = mCol.getDecks().allConf();
    Collections.sort(confs, NamedJSONComparator.instance);
    String[] confValues = new String[confs.size()];
    String[] confLabels = new String[confs.size()];
    for (int i = 0; i < confs.size(); i++) {
        DeckConfig o = confs.get(i);
        confValues[i] = o.getString("id");
        confLabels[i] = o.getString("name");
    }
    deckConfPref.setEntries(confLabels);
    deckConfPref.setEntryValues(confValues);
    deckConfPref.setValue(mPref.getString("deckConf", "0"));
    android.preference.ListPreference newOrderPref = (android.preference.ListPreference) findPreference("newOrder");
    newOrderPref.setEntries(R.array.new_order_labels);
    newOrderPref.setEntryValues(R.array.new_order_values);
    newOrderPref.setValue(mPref.getString("newOrder", "0"));
    android.preference.ListPreference leechActPref = (android.preference.ListPreference) findPreference("lapLeechAct");
    leechActPref.setEntries(R.array.leech_action_labels);
    leechActPref.setEntryValues(R.array.leech_action_values);
    leechActPref.setValue(mPref.getString("lapLeechAct", new Integer(Consts.LEECH_SUSPEND).toString()));
}
Also used : DeckConfig(com.ichi2.libanki.DeckConfig)

Example 2 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class CollectionTask method doInBackgroundConfRemove.

private TaskData doInBackgroundConfRemove(TaskData param) {
    Timber.d("doInBackgroundConfRemove");
    Collection col = getCol();
    Object[] data = param.getObjArray();
    DeckConfig conf = (DeckConfig) data[0];
    try {
        // Note: We do the actual removing of the options group in the main thread so that we
        // can ask the user to confirm if they're happy to do a full sync, and just do the resorting here
        // When a conf is deleted, all decks using it revert to the default conf.
        // Cards must be reordered according to the default conf.
        int order = conf.getJSONObject("new").getInt("order");
        int defaultOrder = col.getDecks().getConf(1).getJSONObject("new").getInt("order");
        if (order != defaultOrder) {
            conf.getJSONObject("new").put("order", defaultOrder);
            col.getSched().resortConf(conf);
        }
        col.save();
        return new TaskData(true);
    } catch (JSONException e) {
        return new TaskData(false);
    }
}
Also used : Collection(com.ichi2.libanki.Collection) JSONException(com.ichi2.utils.JSONException) JSONObject(com.ichi2.utils.JSONObject) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 3 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class CollectionTask method doInBackgroundConfChange.

private TaskData doInBackgroundConfChange(TaskData param) {
    Timber.d("doInBackgroundConfChange");
    Collection col = getCol();
    Object[] data = param.getObjArray();
    Deck deck = (Deck) data[0];
    DeckConfig conf = (DeckConfig) data[1];
    try {
        long newConfId = conf.getLong("id");
        // If new config has a different sorting order, reorder the cards
        int oldOrder = col.getDecks().getConf(deck.getLong("conf")).getJSONObject("new").getInt("order");
        int newOrder = col.getDecks().getConf(newConfId).getJSONObject("new").getInt("order");
        if (oldOrder != newOrder) {
            switch(newOrder) {
                case 0:
                    col.getSched().randomizeCards(deck.getLong("id"));
                    break;
                case 1:
                    col.getSched().orderCards(deck.getLong("id"));
                    break;
            }
        }
        col.getDecks().setConf(deck, newConfId);
        col.save();
        return new TaskData(true);
    } catch (JSONException e) {
        return new TaskData(false);
    }
}
Also used : Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) JSONException(com.ichi2.utils.JSONException) JSONObject(com.ichi2.utils.JSONObject) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 4 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class CollectionTask method doInBackgroundReorder.

private TaskData doInBackgroundReorder(TaskData param) {
    Timber.d("doInBackgroundReorder");
    Collection col = getCol();
    Object[] data = param.getObjArray();
    DeckConfig conf = (DeckConfig) data[0];
    col.getSched().resortConf(conf);
    return new TaskData(true);
}
Also used : Collection(com.ichi2.libanki.Collection) JSONObject(com.ichi2.utils.JSONObject) DeckConfig(com.ichi2.libanki.DeckConfig)

Example 5 with DeckConfig

use of com.ichi2.libanki.DeckConfig in project AnkiChinaAndroid by ankichinateam.

the class BootService method scheduleDeckReminder.

private void scheduleDeckReminder(Context context) {
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    for (DeckConfig deckConfiguration : CollectionHelper.getInstance().getCol(context).getDecks().allConf()) {
        Collection col = CollectionHelper.getInstance().getCol(context);
        if (deckConfiguration.has("reminder")) {
            final JSONObject reminder = deckConfiguration.getJSONObject("reminder");
            if (reminder.getBoolean("enabled")) {
                final PendingIntent reminderIntent = PendingIntent.getBroadcast(context, (int) deckConfiguration.getLong("id"), new Intent(context, ReminderService.class).putExtra(ReminderService.EXTRA_DECK_OPTION_ID, deckConfiguration.getLong("id")), 0);
                final Calendar calendar = reminderToCalendar(col.getTime(), reminder);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, reminderIntent);
            }
        }
    }
}
Also used : JSONObject(com.ichi2.utils.JSONObject) Calendar(java.util.Calendar) DeckOptions.reminderToCalendar(com.ichi2.anki.DeckOptions.reminderToCalendar) AlarmManager(android.app.AlarmManager) Collection(com.ichi2.libanki.Collection) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) DeckConfig(com.ichi2.libanki.DeckConfig)

Aggregations

DeckConfig (com.ichi2.libanki.DeckConfig)85 Collection (com.ichi2.libanki.Collection)57 Card (com.ichi2.libanki.Card)50 Test (org.junit.Test)49 RobolectricTest (com.ichi2.anki.RobolectricTest)48 Note (com.ichi2.libanki.Note)47 JSONArray (com.ichi2.utils.JSONArray)42 JSONObject (com.ichi2.utils.JSONObject)27 Deck (com.ichi2.libanki.Deck)14 NonNull (androidx.annotation.NonNull)12 Cursor (android.database.Cursor)5 JSONException (com.ichi2.utils.JSONException)5 ArrayList (java.util.ArrayList)5 Model (com.ichi2.libanki.Model)4 HashMap (java.util.HashMap)4 SuppressLint (android.annotation.SuppressLint)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ContentValues (android.content.ContentValues)2 Intent (android.content.Intent)2