Search in sources :

Example 1 with SelectableDeck

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();
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Example 2 with SelectableDeck

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;
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Bundle(android.os.Bundle) Deck(com.ichi2.libanki.Deck) AnalyticsDialogFragment(com.ichi2.anki.analytics.AnalyticsDialogFragment) NonNull(androidx.annotation.NonNull) R(com.ichi2.anki.R) Filter(android.widget.Filter) Dialog(android.app.Dialog) Collection(com.ichi2.libanki.Collection) Parcel(android.os.Parcel) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) FunctionalInterfaces(com.ichi2.utils.FunctionalInterfaces) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Parcelable(android.os.Parcelable) LayoutInflater(android.view.LayoutInflater) SearchView(androidx.appcompat.widget.SearchView) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Toolbar(androidx.appcompat.widget.Toolbar) Filterable(android.widget.Filterable) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Collections(java.util.Collections) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Bundle(android.os.Bundle) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) NonNull(androidx.annotation.NonNull)

Example 3 with SelectableDeck

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();
}
Also used : JSONObject(com.ichi2.utils.JSONObject)

Aggregations

JSONObject (com.ichi2.utils.JSONObject)2 Dialog (android.app.Dialog)1 Bundle (android.os.Bundle)1 Parcel (android.os.Parcel)1 Parcelable (android.os.Parcelable)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Filter (android.widget.Filter)1 Filterable (android.widget.Filterable)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 SearchView (androidx.appcompat.widget.SearchView)1 Toolbar (androidx.appcompat.widget.Toolbar)1 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1