use of com.ichi2.anki.dialogs.DeckSelectionDialog.SelectableDeck in project AnkiChinaAndroid by ankichinateam.
the class CardTemplateEditor method onDeckSelected.
/**
* When a deck is selected via Deck Override
*/
@Override
public void onDeckSelected(@Nullable SelectableDeck deck) {
if (Models.isCloze(getTempModel().getModel())) {
Timber.w("Attempted to set deck for cloze model");
UIUtils.showThemedToast(this, getString(R.string.model_manager_deck_override_cloze_error), true);
return;
}
int ordinal = mViewPager.getCurrentItem();
JSONObject template = getTempModel().getTemplate(ordinal);
String templateName = template.getString("name");
if (deck != null && Decks.isDynamic(getCol(), deck.getDeckId())) {
Timber.w("Attempted to set default deck of %s to dynamic deck %s", templateName, deck.getName());
UIUtils.showThemedToast(this, getString(R.string.model_manager_deck_override_dynamic_deck_error), true);
return;
}
String message;
if (deck == null) {
Timber.i("Removing default template from template '%s'", templateName);
template.put("did", null);
message = getString(R.string.model_manager_deck_override_removed_message, templateName);
} else {
Timber.i("Setting template '%s' to '%s'", templateName, deck.getName());
template.put("did", deck.getDeckId());
message = getString(R.string.model_manager_deck_override_added_message, templateName, deck.getName());
}
UIUtils.showThemedToast(this, message, true);
// Deck Override can change from "on" <-> "off"
supportInvalidateOptionsMenu();
}
use of com.ichi2.anki.dialogs.DeckSelectionDialog.SelectableDeck in project AnkiChinaAndroid by ankichinateam.
the class DeckSelectionDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.deck_picker_dialog, null, false);
TextView summary = dialogView.findViewById(R.id.deck_picker_dialog_summary);
Bundle arguments = requireArguments();
summary.setText(getSummaryMessage(arguments));
RecyclerView recyclerView = dialogView.findViewById(R.id.deck_picker_dialog_list);
recyclerView.requestFocus();
// recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager deckLayoutManager = new LinearLayoutManager(requireActivity());
recyclerView.setLayoutManager(deckLayoutManager);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
recyclerView.addItemDecoration(dividerItemDecoration);
List<SelectableDeck> decks = getDeckNames(arguments);
DecksArrayAdapter adapter = new DecksArrayAdapter(decks);
recyclerView.setAdapter(adapter);
adjustToolbar(dialogView, adapter);
MaterialDialog.Builder builder = new MaterialDialog.Builder(requireActivity()).neutralText(R.string.dialog_cancel).negativeText(R.string.restore_default).customView(dialogView, false).onNegative((dialog, which) -> onDeckSelected(null)).onNeutral((dialog, which) -> {
});
mDialog = builder.build();
return mDialog;
}
use of com.ichi2.anki.dialogs.DeckSelectionDialog.SelectableDeck in project Anki-Android by ankidroid.
the class CardTemplateEditor method onDeckSelected.
/**
* When a deck is selected via Deck Override
*/
@Override
public void onDeckSelected(@Nullable SelectableDeck deck) {
if (getTempModel().getModel().isCloze()) {
Timber.w("Attempted to set deck for cloze model");
UIUtils.showThemedToast(this, getString(R.string.multimedia_editor_something_wrong), true);
return;
}
int ordinal = mViewPager.getCurrentItem();
JSONObject template = getTempModel().getTemplate(ordinal);
String templateName = template.getString("name");
if (deck != null && Decks.isDynamic(getCol(), deck.getDeckId())) {
Timber.w("Attempted to set default deck of %s to dynamic deck %s", templateName, deck.getName());
UIUtils.showThemedToast(this, getString(R.string.multimedia_editor_something_wrong), true);
return;
}
String message;
if (deck == null) {
Timber.i("Removing default template from template '%s'", templateName);
template.put("did", JSONObject.NULL);
message = getString(R.string.model_manager_deck_override_removed_message, templateName);
} else {
Timber.i("Setting template '%s' to '%s'", templateName, deck.getName());
template.put("did", deck.getDeckId());
message = getString(R.string.model_manager_deck_override_added_message, templateName, deck.getName());
}
UIUtils.showThemedToast(this, message, true);
// Deck Override can change from "on" <-> "off"
supportInvalidateOptionsMenu();
}
Aggregations