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()));
}
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);
}
}
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);
}
}
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);
}
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);
}
}
}
}
Aggregations