use of com.ichi2.anki.DeckOptions in project AnkiChinaAndroid by ankichinateam.
the class StudyOptionsFragment method configMaxDayLearnAndRev.
private void configMaxDayLearnAndRev() {
CustomStyleDialog customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("设置每天学习量").setCustomLayout(R.layout.dialog_common_custom_next).setMultiEditorModeCallback(new CustomStyleDialog.Builder.MultiEditorModeCallback() {
@Override
public String[] getEditorText() {
// return new String[] {mOptions.getJSONObject("new").getString("perDay"), mOptions.getJSONObject("rev").getString("perDay"),};
return new String[] { "30", "200" };
}
@Override
public String[] getEditorHint() {
return new String[] { "每天新卡上限", "每天复习上限" };
}
@Override
public String[] getItemHint() {
return new String[] { "学习一段时间后,未来每天新卡+复习卡约180张,大约需30分钟", "建议设置为最大9999,有多少复习多少" };
}
}).addSingleTextChangedListener(new CustomStyleDialog.Builder.MyTextWatcher() {
@Override
public void beforeTextChanged(Dialog dialog, CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(Dialog dialog, CharSequence s, int start, int before, int count) {
if (s.toString().isEmpty()) {
((CustomStyleDialog) dialog).getSingleEditorModeHintView().setText("未来每天学习量=新卡数x6");
} else {
int num = 0;
try {
num = Integer.parseInt(s.toString()) * 6;
} catch (Exception ignored) {
}
int time = num * 10 / 60;
((CustomStyleDialog) dialog).getSingleEditorModeHintView().setText(String.format("学习一段时间后,未来每天新卡+复习卡约%s张,大约需%s分钟", num, time));
}
}
@Override
public void afterTextChanged(Dialog dialog, Editable s) {
}
}).setPositiveButton("进入学习", (dialog, which) -> {
String text1 = ((CustomStyleDialog) dialog).getMultiEditor().get(0).getText().toString();
String text2 = ((CustomStyleDialog) dialog).getMultiEditor().get(1).getText().toString();
int maxNewCard = 0;
int maxRevCard = 0;
try {
maxNewCard = Integer.parseInt(text1);
} catch (Exception ignored) {
}
try {
maxRevCard = Integer.parseInt(text2);
} catch (Exception ignored) {
}
if (maxNewCard >= 0 && maxNewCard <= 9999 && maxRevCard >= 0 && maxRevCard <= 9999) {
mOptions.getJSONObject("new").put("perDay", maxNewCard);
mOptions.getJSONObject("rev").put("perDay", maxRevCard);
Timber.i("edit new and rev max:" + maxNewCard + "," + maxRevCard);
try {
getCol().getDecks().save(mOptions);
} catch (RuntimeException e) {
Timber.e(e, "DeckOptions - RuntimeException on saving conf");
AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf");
}
refreshOption();
dialog.dismiss();
openReviewerInternal();
} else {
UIUtils.showThemedToast(getAnkiActivity(), "请填写0至9999之间的数值", false);
}
}).setNegativeButton("跳过", (dialog, which) -> {
dialog.dismiss();
try {
getCol().getDecks().save(mOptions);
} catch (RuntimeException e) {
Timber.e(e, "DeckOptions - RuntimeException on saving conf");
AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf");
}
refreshOption();
openReviewerInternal();
}).create();
customDialog.show();
}
use of com.ichi2.anki.DeckOptions in project AnkiChinaAndroid by ankichinateam.
the class StudyOptionsFragment method openReviewer.
private void openReviewer() {
if (mShouldConfigBeforeStudy && mOptions != null) {
SharedPreferences sharedPreferences = getAnkiActivity().getSharedPreferences(STUDY_SETTING, 0);
StringBuilder initIds = new StringBuilder(sharedPreferences.getString(KEY_CONFIG_INIT, ""));
if (initIds.length() > 0) {
String[] ids = initIds.toString().split(",");
if (ids.length > 0) {
for (String id : ids) {
if (getCol().getDecks().current().getLong("id") == Long.parseLong(id)) {
// 已经初始化过了,直接跳过
openReviewerInternal();
return;
}
}
}
// 没初始化过,那现在也初始化了。
// initIds.append(",");
}
for (long id : getDeckIds(getCol().getDecks().current().getLong("id"), getCol())) {
if (!initIds.toString().isEmpty()) {
initIds.append(",");
}
initIds.append(id);
}
// initIds += Stats.deckLimit(getCol().getDecks().current().getLong("id"), getCol()).replace("(","").replace(")","").trim();//要把子牌组也加入里面
sharedPreferences.edit().putString(KEY_CONFIG_INIT, initIds.toString()).apply();
String savedMindModeValue = sharedPreferences.getString(KEY_MIND_MODE, "");
Map<String, Integer> map = null;
try {
Gson gson = new Gson();
map = gson.fromJson(savedMindModeValue, new TypeToken<Map<String, Integer>>() {
}.getType());
} catch (Exception e) {
e.printStackTrace();
}
String mDeckIdStr = String.valueOf(getCol().getDecks().current().getLong("id"));
mCurrentMindModeValue = map != null && map.get(mDeckIdStr) != null ? map.get(mDeckIdStr) : 0;
if (mMindModeValues == null) {
mMindModeValues = getResources().getStringArray(R.array.mind_mode_values);
mMindModeLabels = getResources().getStringArray(R.array.mind_mode_labels);
mMindModeHints = getResources().getStringArray(R.array.mind_mode_hint);
for (int i = 0; i < mMindModeValues.length; i++) {
mMindModeMap.put(Integer.valueOf(mMindModeValues[i]), mMindModeLabels[i]);
}
}
CustomStyleDialog customDialog = new CustomStyleDialog.Builder(getAnkiActivity()).setTitle("记忆模式").setCustomLayout(R.layout.dialog_common_custom_next).setSelectListModeCallback(new CustomStyleDialog.Builder.SelectListModeCallback() {
@Override
public String[] getItemContent() {
return mMindModeLabels;
}
@Override
public String[] getItemHint() {
return mMindModeHints;
}
@Override
public int getDefaultSelectedPosition() {
return mCurrentMindModeValue;
}
@Override
public void onItemSelect(int position) {
mCurrentMindModeValue = position;
}
}).setPositiveButton("下一步", (dialog, which) -> {
String oldValue = sharedPreferences.getString(KEY_MIND_MODE, "");
Map<String, Integer> oldMap = null;
Gson gson = new Gson();
try {
oldMap = gson.fromJson(oldValue, new TypeToken<Map<String, Integer>>() {
}.getType());
} catch (Exception e) {
e.printStackTrace();
}
if (oldMap == null) {
oldMap = new HashMap<>();
}
for (long id : getDeckIds(getCol().getDecks().current().getLong("id"), getCol())) {
// Timber.i("看看都是什么id %s", id);
oldMap.put(String.valueOf(id), mCurrentMindModeValue);
}
String newValue = gson.toJson(oldMap);
sharedPreferences.edit().putString(KEY_MIND_MODE, newValue).apply();
CollectionTask.launchCollectionTask(CONF_RESET, new ConfChangeHandler(StudyOptionsFragment.this, mCurrentMindModeValue), // 先恢复默认,即长记模式
new TaskData(new Object[] { mOptions }));
dialog.dismiss();
}).setNegativeButton("跳过", (dialog, which) -> {
dialog.dismiss();
try {
getCol().getDecks().save(mOptions);
} catch (RuntimeException e) {
Timber.e(e, "DeckOptions - RuntimeException on saving conf");
AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf");
}
refreshOption();
openReviewerInternal();
}).create();
customDialog.show();
} else {
openReviewerInternal();
}
}
use of com.ichi2.anki.DeckOptions in project AnkiChinaAndroid by ankichinateam.
the class DeckOptions method onCreate.
@Override
// conversion to fragments tracked as #5019 in github
@SuppressWarnings("deprecation")
protected void onCreate(Bundle icicle) {
Themes.setThemeLegacy(this);
super.onCreate(icicle);
mCol = CollectionHelper.getInstance().getCol(this);
if (mCol == null) {
finish();
return;
}
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("did")) {
mDeck = mCol.getDecks().get(extras.getLong("did"));
} else {
mDeck = mCol.getDecks().current();
}
registerExternalStorageListener();
if (mCol == null) {
Timber.w("DeckOptions - No Collection loaded");
finish();
} else {
mPref = new DeckPreferenceHack();
// #6068 - constructor can call finish()
if (this.isFinishing()) {
return;
}
mPref.registerOnSharedPreferenceChangeListener(this);
this.addPreferencesFromResource(R.xml.deck_options);
this.buildLists();
this.updateSummaries();
// Set the activity title to include the name of the deck
String title = getResources().getString(R.string.deckpreferences_title);
if (title.contains("XXX")) {
try {
title = title.replace("XXX", mDeck.getString("name"));
} catch (JSONException e) {
title = title.replace("XXX", "???");
}
}
this.setTitle(title);
}
// Add a home button to the actionbar
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
use of com.ichi2.anki.DeckOptions in project Anki-Android by ankidroid.
the class DeckOptions method onCreate.
@Override
// conversion to fragments tracked as #5019 in github
@SuppressWarnings("deprecation")
protected void onCreate(Bundle icicle) {
Themes.setThemeLegacy(this);
super.onCreate(icicle);
mCol = CollectionHelper.getInstance().getCol(this);
if (mCol == null) {
finish();
return;
}
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("did")) {
mDeck = mCol.getDecks().get(extras.getLong("did"));
} else {
mDeck = mCol.getDecks().current();
}
registerExternalStorageListener();
if (mCol == null) {
Timber.w("DeckOptions - No Collection loaded");
finish();
} else {
mPref = new DeckPreferenceHack();
// #6068 - constructor can call finish()
if (this.isFinishing()) {
return;
}
mPref.registerOnSharedPreferenceChangeListener(this);
this.addPreferencesFromResource(R.xml.deck_options);
if (this.isSchedV2()) {
this.enableSchedV2Preferences();
}
this.buildLists();
this.updateSummaries();
// Set the activity title to include the name of the deck
String title = getResources().getString(R.string.deckpreferences_title);
if (title.contains("XXX")) {
try {
title = title.replace("XXX", mDeck.getString("name"));
} catch (JSONException e) {
Timber.w(e);
title = title.replace("XXX", "???");
}
}
this.setTitle(title);
}
// Add a home button to the actionbar
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Aggregations