Search in sources :

Example 1 with RescheduleDialog

use of com.ichi2.anki.dialogs.RescheduleDialog in project Anki-Android by ankidroid.

the class CardBrowser method rescheduleSelectedCards.

private void rescheduleSelectedCards() {
    if (!hasSelectedCards()) {
        Timber.i("Attempted reschedule - no cards selected");
        return;
    }
    List<Long> selectedCardIds = getSelectedCardIds();
    Consumer<Integer> consumer = newDays -> rescheduleWithoutValidation(selectedCardIds, newDays);
    RescheduleDialog rescheduleDialog;
    if (selectedCardIds.size() == 1) {
        long cardId = selectedCardIds.get(0);
        Card selected = getCol().getCard(cardId);
        rescheduleDialog = RescheduleDialog.rescheduleSingleCard(getResources(), selected, consumer);
    } else {
        rescheduleDialog = RescheduleDialog.rescheduleMultipleCards(getResources(), consumer, selectedCardIds.size());
    }
    showDialogFragment(rescheduleDialog);
}
Also used : TemplateRenderOutput(com.ichi2.libanki.TemplateManager.TemplateRenderContext.TemplateRenderOutput) Arrays(java.util.Arrays) Bundle(android.os.Bundle) SortOrder(com.ichi2.libanki.SortOrder) Deck(com.ichi2.libanki.Deck) NonNull(androidx.annotation.NonNull) Decks(com.ichi2.libanki.Decks) Map(java.util.Map) JSONException(com.ichi2.utils.JSONException) Upgrade(com.ichi2.upgrade.Upgrade) IntentFilter(android.content.IntentFilter) Set(java.util.Set) SearchView(androidx.appcompat.widget.SearchView) JSONObject(com.ichi2.utils.JSONObject) LanguageUtil.getLocaleCompat(com.ichi2.utils.LanguageUtil.getLocaleCompat) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) TagsDialogListener(com.ichi2.anki.dialogs.tags.TagsDialogListener) Consts(com.ichi2.libanki.Consts) ActivityResultContracts(androidx.activity.result.contract.ActivityResultContracts) CompatHelper(com.ichi2.compat.CompatHelper) TagsDialogFactory(com.ichi2.anki.dialogs.tags.TagsDialogFactory) RustCleanup(net.ankiweb.rsdroid.RustCleanup) HandlerUtils(com.ichi2.utils.HandlerUtils) TagsDialog(com.ichi2.anki.dialogs.tags.TagsDialog) Direction(com.ichi2.anim.ActivityTransitionAnimation.Direction) SystemClock(android.os.SystemClock) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) SdCardReceiver(com.ichi2.anki.receiver.SdCardReceiver) Column(com.ichi2.anki.CardBrowser.Column) ArrayList(java.util.ArrayList) Menu(android.view.Menu) SimpleMessageDialog(com.ichi2.anki.dialogs.SimpleMessageDialog) LinkedHashSet(java.util.LinkedHashSet) IntegerDialog(com.ichi2.anki.dialogs.IntegerDialog) CheckResult(androidx.annotation.CheckResult) TextUtils(android.text.TextUtils) CardBrowserSearchView(com.ichi2.ui.CardBrowserSearchView) ArrayAdapter(android.widget.ArrayAdapter) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) SECONDS_PER_DAY(com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY) LanguageUtil(com.ichi2.utils.LanguageUtil) SchedulerService(com.ichi2.anki.servicelayer.SchedulerService) CardBrowserOrderDialog(com.ichi2.anki.dialogs.CardBrowserOrderDialog) TaskManager(com.ichi2.async.TaskManager) WindowManager(android.view.WindowManager) Compat(com.ichi2.compat.Compat) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) Permissions(com.ichi2.utils.Permissions) FunctionalInterfaces(com.ichi2.utils.FunctionalInterfaces) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) View(android.view.View) AdapterView(android.widget.AdapterView) CardBrowserMySearchesDialog(com.ichi2.anki.dialogs.CardBrowserMySearchesDialog) HashUtil(com.ichi2.utils.HashUtil) BroadcastReceiver(android.content.BroadcastReceiver) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) AlertDialog(android.app.AlertDialog) UndoService(com.ichi2.anki.servicelayer.UndoService) List(java.util.List) TextView(android.widget.TextView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) BaseAdapter(android.widget.BaseAdapter) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) ListView(android.widget.ListView) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) SearchCardsResult(com.ichi2.anki.servicelayer.SearchService.SearchCardsResult) Typeface(android.graphics.Typeface) Note(com.ichi2.libanki.Note) Context(android.content.Context) NextCard(com.ichi2.anki.servicelayer.SchedulerService.NextCard) KeyEvent(android.view.KeyEvent) Pair(android.util.Pair) Intent(android.content.Intent) HashMap(java.util.HashMap) Collection(com.ichi2.libanki.Collection) MenuItem(android.view.MenuItem) HashSet(java.util.HashSet) DeckDropDownAdapter(com.ichi2.anki.widgets.DeckDropDownAdapter) WidgetStatus(com.ichi2.widget.WidgetStatus) Utils(com.ichi2.libanki.Utils) NoteService(com.ichi2.anki.servicelayer.NoteService) Computation(com.ichi2.utils.Computation) Iterator(java.util.Iterator) ActivityResultLauncher(androidx.activity.result.ActivityResultLauncher) LayoutInflater(android.view.LayoutInflater) AbsListView(android.widget.AbsListView) CollectionTask(com.ichi2.async.CollectionTask) Themes(com.ichi2.themes.Themes) Spinner(android.widget.Spinner) Consumer(java.util.function.Consumer) TagsUtil(com.ichi2.utils.TagsUtil) Card(com.ichi2.libanki.Card) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) DeckSelectionDialog(com.ichi2.anki.dialogs.DeckSelectionDialog) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) NextCard(com.ichi2.anki.servicelayer.SchedulerService.NextCard) Card(com.ichi2.libanki.Card)

Example 2 with RescheduleDialog

use of com.ichi2.anki.dialogs.RescheduleDialog in project AnkiChinaAndroid by ankichinateam.

the class SelfStudyActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // (when another operation will be performed on the model, it will undo the latest operation)
    if (mUndoSnackbar != null && mUndoSnackbar.isShown()) {
        mUndoSnackbar.dismiss();
    }
    switch(item.getItemId()) {
        case android.R.id.home:
            endMultiSelectMode();
            return true;
        case R.id.screen:
            showScreenDialog();
            return true;
        case R.id.action_edit:
            mCardsAdapter.setMultiCheckable(!mCardsAdapter.isMultiCheckableMode());
            return true;
        case R.id.action_add_note_from_card_browser:
            {
                Intent intent = new Intent(SelfStudyActivity.this, NoteEditor.class);
                intent.putExtra(NoteEditor.EXTRA_CALLER, NoteEditor.CALLER_CARDBROWSER_ADD);
                startActivityForResultWithAnimation(intent, ADD_NOTE, ActivityTransitionAnimation.LEFT);
                return true;
            }
        case R.id.action_save_search:
            {
                String searchTerms = mSearchView.getQuery().toString();
                showDialogFragment(CardBrowserMySearchesDialog.newInstance(null, mMySearchesDialogListener, searchTerms, CardBrowserMySearchesDialog.CARD_BROWSER_MY_SEARCHES_TYPE_SAVE));
                return true;
            }
        case R.id.action_list_my_searches:
            {
                JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters");
                HashMap<String, String> savedFilters = new HashMap<>();
                if (savedFiltersObj != null) {
                    Iterator<String> it = savedFiltersObj.keys();
                    while (it.hasNext()) {
                        String searchName = it.next();
                        savedFilters.put(searchName, savedFiltersObj.optString(searchName));
                    }
                }
                showDialogFragment(CardBrowserMySearchesDialog.newInstance(savedFilters, mMySearchesDialogListener, "", CardBrowserMySearchesDialog.CARD_BROWSER_MY_SEARCHES_TYPE_LIST));
                return true;
            }
        case R.id.action_sort_by_size:
            showDialogFragment(CardBrowserOrderDialog.newInstance(mOrder, mOrderAsc, mOrderDialogListener));
            return true;
        case R.id.action_show_marked:
            mSearchTerms = "tag:marked";
            mSearchView.setQuery("", false);
            mSearchView.setQueryHint(getResources().getString(R.string.card_browser_show_marked));
            searchCards();
            return true;
        case R.id.action_show_suspended:
            mSearchTerms = "is:suspended";
            mSearchView.setQuery("", false);
            mSearchView.setQueryHint(getResources().getString(R.string.card_browser_show_suspended));
            searchCards();
            return true;
        case R.id.action_flag_zero:
            flagTask(0);
            return true;
        case R.id.action_flag_one:
            flagTask(1);
            return true;
        case R.id.action_flag_two:
            flagTask(2);
            return true;
        case R.id.action_flag_three:
            flagTask(3);
            return true;
        case R.id.action_flag_four:
            flagTask(4);
            return true;
        case R.id.action_delete_card:
            if (inMultiSelectMode()) {
                CollectionTask.launchCollectionTask(DISMISS_MULTI, mDeleteNoteHandler, new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.DELETE_NOTE_MULTI }));
                mCardsAdapter.getSelectedItemIds().clear();
            }
            return true;
        case R.id.action_mark_card:
            CollectionTask.launchCollectionTask(DISMISS_MULTI, markCardHandler(), new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.MARK_NOTE_MULTI }));
            return true;
        case R.id.action_suspend_card:
            CollectionTask.launchCollectionTask(DISMISS_MULTI, suspendCardHandler(), new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.SUSPEND_CARD_MULTI }));
            toggleMultiSelectMode(false);
            return true;
        case R.id.action_change_deck:
            {
                AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
                builderSingle.setTitle(getString(R.string.move_all_to_deck));
                // WARNING: changeDeck depends on this index, so any changes should be reflected there.
                final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.dropdown_deck_item);
                for (Deck deck : getValidDecksForChangeDeck()) {
                    try {
                        arrayAdapter.add(deck.getString("name"));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                builderSingle.setNegativeButton(getString(R.string.cancel), (dialog, which) -> dialog.dismiss());
                builderSingle.setAdapter(arrayAdapter, (dialog, which) -> changeDeck(which));
                builderSingle.show();
                return true;
            }
        case R.id.action_undo:
            if (getCol().undoAvailable()) {
                CollectionTask.launchCollectionTask(UNDO, mUndoHandler);
            }
            return true;
        case R.id.action_preview:
            {
                mStartStudyButton.performClick();
                return true;
            }
        case R.id.action_reset_cards_progress:
            {
                Timber.i("NoteEditor:: Reset progress button pressed");
                // Show confirmation dialog before resetting card progress
                ConfirmationDialog dialog = new ConfirmationDialog();
                String title = getString(R.string.reset_card_dialog_title);
                String message = getString(R.string.reset_card_dialog_message);
                dialog.setArgs(title, message);
                Runnable confirm = () -> {
                    Timber.i("CardBrowser:: ResetProgress button pressed");
                    CollectionTask.launchCollectionTask(DISMISS_MULTI, resetProgressCardHandler(), new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.RESET_CARDS }));
                };
                dialog.setConfirm(confirm);
                showDialogFragment(dialog);
                return true;
            }
        case R.id.action_reschedule_cards:
            {
                Timber.i("CardBrowser:: Reschedule button pressed");
                long[] selectedCardIds = getSelectedCardIds();
                FunctionalInterfaces.Consumer<Integer> consumer = newDays -> CollectionTask.launchCollectionTask(DISMISS_MULTI, rescheduleCardHandler(), new TaskData(new Object[] { selectedCardIds, Collection.DismissType.RESCHEDULE_CARDS, newDays }));
                RescheduleDialog rescheduleDialog;
                if (selectedCardIds.length == 1) {
                    long cardId = selectedCardIds[0];
                    Card selected = getCol().getCard(cardId);
                    rescheduleDialog = RescheduleDialog.rescheduleSingleCard(getResources(), selected, consumer);
                } else {
                    rescheduleDialog = RescheduleDialog.rescheduleMultipleCards(getResources(), consumer, selectedCardIds.length);
                }
                showDialogFragment(rescheduleDialog);
                return true;
            }
        case R.id.action_reposition_cards:
            {
                Timber.i("CardBrowser:: Reposition button pressed");
                // Only new cards may be repositioned
                long[] cardIds = getSelectedCardIds();
                for (int i = 0; i < cardIds.length; i++) {
                    if (getCol().getCard(cardIds[i]).getQueue() != Consts.CARD_TYPE_NEW) {
                        SimpleMessageDialog dialog = SimpleMessageDialog.newInstance(getString(R.string.vague_error), getString(R.string.reposition_card_not_new_error), false);
                        showDialogFragment(dialog);
                        return false;
                    }
                }
                IntegerDialog repositionDialog = new IntegerDialog();
                repositionDialog.setArgs(getString(R.string.reposition_card_dialog_title), getString(R.string.reposition_card_dialog_message), 5);
                repositionDialog.setCallbackRunnable(days -> CollectionTask.launchCollectionTask(DISMISS_MULTI, repositionCardHandler(), new TaskData(new Object[] { cardIds, Collection.DismissType.REPOSITION_CARDS, days })));
                showDialogFragment(repositionDialog);
                return true;
            }
        case R.id.action_edit_note:
            {
                openNoteEditorForCurrentlySelectedNote();
            }
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : AlertDialog(android.app.AlertDialog) Arrays(java.util.Arrays) Bundle(android.os.Bundle) TagsDialog(com.ichi2.anki.dialogs.TagsDialog) Deck(com.ichi2.libanki.Deck) NonNull(androidx.annotation.NonNull) ImageView(android.widget.ImageView) RangeSeekBar(com.jaygoo.widget.RangeSeekBar) ActionBar(androidx.appcompat.app.ActionBar) Decks(com.ichi2.libanki.Decks) Handler(android.os.Handler) Map(java.util.Map) JSONException(com.ichi2.utils.JSONException) OnRangeChangedListener(com.jaygoo.widget.OnRangeChangedListener) ContextCompat(androidx.core.content.ContextCompat) DUE(com.ichi2.anki.CardBrowser.Column.DUE) Upgrade(com.ichi2.upgrade.Upgrade) CREATED(com.ichi2.anki.CardBrowser.Column.CREATED) IntentFilter(android.content.IntentFilter) Set(java.util.Set) JSONObject(com.ichi2.utils.JSONObject) SearchView(androidx.appcompat.widget.SearchView) INTERVAL(com.ichi2.anki.CardBrowser.Column.INTERVAL) Nullable(androidx.annotation.Nullable) CHANGED(com.ichi2.anki.CardBrowser.Column.CHANGED) Consts(com.ichi2.libanki.Consts) CardCache(com.ichi2.anki.CardBrowser.CardCache) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DECK(com.ichi2.anki.CardBrowser.Column.DECK) CARD(com.ichi2.anki.CardBrowser.Column.CARD) WarpLinearLayout(com.ichi2.ui.WarpLinearLayout) UPDATE_NOTE(com.ichi2.async.CollectionTask.TASK_TYPE.UPDATE_NOTE) NOTE_TYPE(com.ichi2.anki.CardBrowser.Column.NOTE_TYPE) TAGS(com.ichi2.anki.CardBrowser.Column.TAGS) SystemClock(android.os.SystemClock) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) SdCardReceiver(com.ichi2.anki.receiver.SdCardReceiver) DISMISS_MULTI(com.ichi2.async.CollectionTask.TASK_TYPE.DISMISS_MULTI) Column(com.ichi2.anki.CardBrowser.Column) ArrayList(java.util.ArrayList) LAPSES(com.ichi2.anki.CardBrowser.Column.LAPSES) RENDER_BROWSER_QA(com.ichi2.async.CollectionTask.TASK_TYPE.RENDER_BROWSER_QA) SFLD(com.ichi2.anki.CardBrowser.Column.SFLD) Toast(android.widget.Toast) Menu(android.view.Menu) SimpleMessageDialog(com.ichi2.anki.dialogs.SimpleMessageDialog) REVIEWS(com.ichi2.anki.CardBrowser.Column.REVIEWS) IntegerDialog(com.ichi2.anki.dialogs.IntegerDialog) EASE(com.ichi2.anki.CardBrowser.Column.EASE) CheckResult(androidx.annotation.CheckResult) TextUtils(android.text.TextUtils) Gravity(android.view.Gravity) ArrayAdapter(android.widget.ArrayAdapter) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) CardBrowserOrderDialog(com.ichi2.anki.dialogs.CardBrowserOrderDialog) CardBrowser.sCardBrowserCard(com.ichi2.anki.CardBrowser.sCardBrowserCard) LinearLayout(android.widget.LinearLayout) WindowManager(android.view.WindowManager) UNDO(com.ichi2.async.CollectionTask.TASK_TYPE.UNDO) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) Permissions(com.ichi2.utils.Permissions) FunctionalInterfaces(com.ichi2.utils.FunctionalInterfaces) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) TaskData(com.ichi2.async.TaskData) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardBrowserMySearchesDialog(com.ichi2.anki.dialogs.CardBrowserMySearchesDialog) TabLayout(com.google.android.material.tabs.TabLayout) SEARCH_CARDS(com.ichi2.async.CollectionTask.TASK_TYPE.SEARCH_CARDS) ANSWER(com.ichi2.anki.CardBrowser.Column.ANSWER) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) AlertDialog(android.app.AlertDialog) Objects(java.util.Objects) List(java.util.List) TextView(android.widget.TextView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) SimpleAdapter(android.widget.SimpleAdapter) OrderListAdapter(com.ichi2.anki.widgets.OrderListAdapter) RelativeLayout(android.widget.RelativeLayout) Toolbar(androidx.appcompat.widget.Toolbar) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) Context(android.content.Context) EDITED(com.ichi2.anki.CardBrowser.Column.EDITED) Intent(android.content.Intent) HashMap(java.util.HashMap) CHECK_CARD_SELECTION(com.ichi2.async.CollectionTask.TASK_TYPE.CHECK_CARD_SELECTION) Collection(com.ichi2.libanki.Collection) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) HashSet(java.util.HashSet) CardsListAdapter(com.ichi2.anki.widgets.CardsListAdapter) DeckDropDownAdapter(com.ichi2.anki.widgets.DeckDropDownAdapter) WidgetStatus(com.ichi2.widget.WidgetStatus) QUESTION(com.ichi2.anki.CardBrowser.Column.QUESTION) Utils(com.ichi2.libanki.Utils) ListPopupWindow(androidx.appcompat.widget.ListPopupWindow) Iterator(java.util.Iterator) Stats(com.ichi2.libanki.stats.Stats) PopupWindow(android.widget.PopupWindow) CollectionTask(com.ichi2.async.CollectionTask) Spinner(android.widget.Spinner) KeyBoardListenerLayout(com.ichi2.ui.KeyBoardListenerLayout) Card(com.ichi2.libanki.Card) Collections(java.util.Collections) VisibleForTesting(androidx.annotation.VisibleForTesting) CustomStyleDialog(com.ichi2.ui.CustomStyleDialog) SimpleMessageDialog(com.ichi2.anki.dialogs.SimpleMessageDialog) HashMap(java.util.HashMap) Deck(com.ichi2.libanki.Deck) JSONException(com.ichi2.utils.JSONException) Intent(android.content.Intent) TaskData(com.ichi2.async.TaskData) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) CardBrowser.sCardBrowserCard(com.ichi2.anki.CardBrowser.sCardBrowserCard) Card(com.ichi2.libanki.Card) JSONObject(com.ichi2.utils.JSONObject) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) IntegerDialog(com.ichi2.anki.dialogs.IntegerDialog) Iterator(java.util.Iterator) JSONObject(com.ichi2.utils.JSONObject) ArrayAdapter(android.widget.ArrayAdapter)

Example 3 with RescheduleDialog

use of com.ichi2.anki.dialogs.RescheduleDialog in project AnkiChinaAndroid by ankichinateam.

the class Reviewer method showRescheduleCardDialog.

private void showRescheduleCardDialog() {
    Consumer<Integer> runnable = days -> CollectionTask.launchCollectionTask(DISMISS_MULTI, mRescheduleCardHandler, new TaskData(new Object[] { new long[] { mCurrentCard.getId() }, Collection.DismissType.RESCHEDULE_CARDS, days }));
    RescheduleDialog dialog = RescheduleDialog.rescheduleSingleCard(getResources(), mCurrentCard, runnable);
    showDialogFragment(dialog);
}
Also used : JavascriptInterface(android.webkit.JavascriptInterface) LinearLayout(android.widget.LinearLayout) COMMAND_NOTHING(com.ichi2.anki.cardviewer.ViewerCommand.COMMAND_NOTHING) Bundle(android.os.Bundle) MenuItemCompat(androidx.core.view.MenuItemCompat) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) UnderlineSpan(android.text.style.UnderlineSpan) DrawableRes(androidx.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) Permissions(com.ichi2.utils.Permissions) ActionBar(androidx.appcompat.app.ActionBar) Decks(com.ichi2.libanki.Decks) Handler(android.os.Handler) View(android.view.View) TaskData(com.ichi2.async.TaskData) ActionButtons(com.ichi2.anki.reviewer.ActionButtons) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ContextCompat(androidx.core.content.ContextCompat) FLAG_NONE(com.ichi2.anki.reviewer.CardMarker.FLAG_NONE) DismissType(com.ichi2.libanki.Collection.DismissType) CardMarker(com.ichi2.anki.reviewer.CardMarker) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) TextView(android.widget.TextView) Message(android.os.Message) Consts(com.ichi2.libanki.Consts) CompatHelper(com.ichi2.compat.CompatHelper) AudioView(com.ichi2.anki.multimediacard.AudioView) Context(android.content.Context) TaskListener(com.ichi2.async.TaskListener) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Intent(android.content.Intent) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) Collection(com.ichi2.libanki.Collection) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) TASK_TYPE(com.ichi2.async.CollectionTask.TASK_TYPE) WidgetStatus(com.ichi2.widget.WidgetStatus) PeripheralKeymap(com.ichi2.anki.reviewer.PeripheralKeymap) Menu(android.view.Menu) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) Utils(com.ichi2.libanki.Utils) Consumer(com.ichi2.utils.FunctionalInterfaces.Consumer) SpannableString(android.text.SpannableString) ActivityCompat(androidx.core.app.ActivityCompat) ReviewerUi(com.ichi2.anki.reviewer.ReviewerUi) CollectionTask(com.ichi2.async.CollectionTask) Themes(com.ichi2.themes.Themes) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ActionProvider(androidx.core.view.ActionProvider) FirefoxSnackbarWorkaround(com.ichi2.anki.workarounds.FirefoxSnackbarWorkaround) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) TaskData(com.ichi2.async.TaskData)

Example 4 with RescheduleDialog

use of com.ichi2.anki.dialogs.RescheduleDialog in project AnkiChinaAndroid by ankichinateam.

the class CardBrowser method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // (when another operation will be performed on the model, it will undo the latest operation)
    if (mUndoSnackbar != null && mUndoSnackbar.isShown()) {
        mUndoSnackbar.dismiss();
    }
    switch(item.getItemId()) {
        case android.R.id.home:
            endMultiSelectMode();
            return true;
        case R.id.action_add_note_from_card_browser:
            {
                Intent intent = new Intent(CardBrowser.this, NoteEditor.class);
                intent.putExtra(NoteEditor.EXTRA_CALLER, NoteEditor.CALLER_CARDBROWSER_ADD);
                startActivityForResultWithAnimation(intent, ADD_NOTE, ActivityTransitionAnimation.LEFT);
                return true;
            }
        case R.id.action_save_search:
            {
                String searchTerms = mSearchView.getQuery().toString();
                showDialogFragment(CardBrowserMySearchesDialog.newInstance(null, mMySearchesDialogListener, searchTerms, CardBrowserMySearchesDialog.CARD_BROWSER_MY_SEARCHES_TYPE_SAVE));
                return true;
            }
        case R.id.action_list_my_searches:
            {
                JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters");
                HashMap<String, String> savedFilters = new HashMap<>();
                if (savedFiltersObj != null) {
                    Iterator<String> it = savedFiltersObj.keys();
                    while (it.hasNext()) {
                        String searchName = it.next();
                        savedFilters.put(searchName, savedFiltersObj.optString(searchName));
                    }
                }
                showDialogFragment(CardBrowserMySearchesDialog.newInstance(savedFilters, mMySearchesDialogListener, "", CardBrowserMySearchesDialog.CARD_BROWSER_MY_SEARCHES_TYPE_LIST));
                return true;
            }
        case R.id.action_sort_by_size:
            showDialogFragment(CardBrowserOrderDialog.newInstance(mOrder, mOrderAsc, mOrderDialogListener));
            return true;
        case R.id.action_show_marked:
            mSearchTerms = "tag:marked";
            mSearchView.setQuery("", false);
            mSearchView.setQueryHint(getResources().getString(R.string.card_browser_show_marked));
            searchCards();
            return true;
        case R.id.action_show_suspended:
            mSearchTerms = "is:suspended";
            mSearchView.setQuery("", false);
            mSearchView.setQueryHint(getResources().getString(R.string.card_browser_show_suspended));
            searchCards();
            return true;
        case R.id.action_search_by_tag:
            showTagsDialog();
            return true;
        case R.id.action_flag_zero:
            flagTask(0);
            return true;
        case R.id.action_flag_one:
            flagTask(1);
            return true;
        case R.id.action_flag_two:
            flagTask(2);
            return true;
        case R.id.action_flag_three:
            flagTask(3);
            return true;
        case R.id.action_flag_four:
            flagTask(4);
            return true;
        case R.id.action_delete_card:
            if (mInMultiSelectMode) {
                CollectionTask.launchCollectionTask(DISMISS_MULTI, mDeleteNoteHandler, new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.DELETE_NOTE_MULTI }));
                mCheckedCards.clear();
                endMultiSelectMode();
                mCardsAdapter.notifyDataSetChanged();
            }
            return true;
        case R.id.action_mark_card:
            CollectionTask.launchCollectionTask(DISMISS_MULTI, markCardHandler(), new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.MARK_NOTE_MULTI }));
            return true;
        case R.id.action_suspend_card:
            CollectionTask.launchCollectionTask(DISMISS_MULTI, suspendCardHandler(), new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.SUSPEND_CARD_MULTI }));
            return true;
        case R.id.action_change_deck:
            {
                AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
                builderSingle.setTitle(getString(R.string.move_all_to_deck));
                // WARNING: changeDeck depends on this index, so any changes should be reflected there.
                final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.dropdown_deck_item);
                for (Deck deck : getValidDecksForChangeDeck()) {
                    try {
                        arrayAdapter.add(deck.getString("name"));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                builderSingle.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        changeDeck(which);
                    }
                });
                builderSingle.show();
                return true;
            }
        case R.id.action_undo:
            if (getCol().undoAvailable()) {
                CollectionTask.launchCollectionTask(UNDO, mUndoHandler);
            }
            return true;
        case R.id.action_select_none:
            onSelectNone();
            return true;
        case R.id.action_select_all:
            onSelectAll();
            return true;
        case R.id.action_preview:
            {
                Intent previewer = new Intent(CardBrowser.this, Previewer.class);
                if (mInMultiSelectMode && checkedCardCount() > 1) {
                    // Multiple cards have been explicitly selected, so preview only those cards
                    previewer.putExtra("index", 0);
                    previewer.putExtra("cardList", getSelectedCardIds());
                } else {
                    // Preview all cards, starting from the one that is currently selected
                    int startIndex = mCheckedCards.isEmpty() ? 0 : mCheckedCards.iterator().next().getPosition();
                    previewer.putExtra("index", startIndex);
                    previewer.putExtra("cardList", getAllCardIds());
                }
                startActivityForResultWithoutAnimation(previewer, PREVIEW_CARDS);
                return true;
            }
        case R.id.action_reset_cards_progress:
            {
                Timber.i("NoteEditor:: Reset progress button pressed");
                // Show confirmation dialog before resetting card progress
                ConfirmationDialog dialog = new ConfirmationDialog();
                String title = getString(R.string.reset_card_dialog_title);
                String message = getString(R.string.reset_card_dialog_message);
                dialog.setArgs(title, message);
                Runnable confirm = () -> {
                    Timber.i("CardBrowser:: ResetProgress button pressed");
                    CollectionTask.launchCollectionTask(DISMISS_MULTI, resetProgressCardHandler(), new TaskData(new Object[] { getSelectedCardIds(), Collection.DismissType.RESET_CARDS }));
                };
                dialog.setConfirm(confirm);
                showDialogFragment(dialog);
                return true;
            }
        case R.id.action_reschedule_cards:
            {
                Timber.i("CardBrowser:: Reschedule button pressed");
                long[] selectedCardIds = getSelectedCardIds();
                FunctionalInterfaces.Consumer<Integer> consumer = newDays -> CollectionTask.launchCollectionTask(DISMISS_MULTI, rescheduleCardHandler(), new TaskData(new Object[] { selectedCardIds, Collection.DismissType.RESCHEDULE_CARDS, newDays }));
                RescheduleDialog rescheduleDialog;
                if (selectedCardIds.length == 1) {
                    long cardId = selectedCardIds[0];
                    Card selected = getCol().getCard(cardId);
                    rescheduleDialog = RescheduleDialog.rescheduleSingleCard(getResources(), selected, consumer);
                } else {
                    rescheduleDialog = RescheduleDialog.rescheduleMultipleCards(getResources(), consumer, selectedCardIds.length);
                }
                showDialogFragment(rescheduleDialog);
                return true;
            }
        case R.id.action_reposition_cards:
            {
                Timber.i("CardBrowser:: Reposition button pressed");
                // Only new cards may be repositioned
                long[] cardIds = getSelectedCardIds();
                for (int i = 0; i < cardIds.length; i++) {
                    if (getCol().getCard(cardIds[i]).getQueue() != Consts.CARD_TYPE_NEW) {
                        SimpleMessageDialog dialog = SimpleMessageDialog.newInstance(getString(R.string.vague_error), getString(R.string.reposition_card_not_new_error), false);
                        showDialogFragment(dialog);
                        return false;
                    }
                }
                IntegerDialog repositionDialog = new IntegerDialog();
                repositionDialog.setArgs(getString(R.string.reposition_card_dialog_title), getString(R.string.reposition_card_dialog_message), 5);
                repositionDialog.setCallbackRunnable(days -> CollectionTask.launchCollectionTask(DISMISS_MULTI, repositionCardHandler(), new TaskData(new Object[] { cardIds, Collection.DismissType.REPOSITION_CARDS, days })));
                showDialogFragment(repositionDialog);
                return true;
            }
        case R.id.action_edit_note:
            {
                openNoteEditorForCurrentlySelectedNote();
            }
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : AlertDialog(android.app.AlertDialog) Arrays(java.util.Arrays) Bundle(android.os.Bundle) TagsDialog(com.ichi2.anki.dialogs.TagsDialog) Deck(com.ichi2.libanki.Deck) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) Compat(com.ichi2.compat.Compat) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) Permissions(com.ichi2.utils.Permissions) FunctionalInterfaces(com.ichi2.utils.FunctionalInterfaces) ActionBar(androidx.appcompat.app.ActionBar) Decks(com.ichi2.libanki.Decks) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) Handler(android.os.Handler) Map(java.util.Map) JSONException(com.ichi2.utils.JSONException) View(android.view.View) TaskData(com.ichi2.async.TaskData) AdapterView(android.widget.AdapterView) Media(com.ichi2.libanki.Media) CardBrowserMySearchesDialog(com.ichi2.anki.dialogs.CardBrowserMySearchesDialog) Upgrade(com.ichi2.upgrade.Upgrade) IntentFilter(android.content.IntentFilter) Set(java.util.Set) SearchView(androidx.appcompat.widget.SearchView) JSONObject(com.ichi2.utils.JSONObject) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) AlertDialog(android.app.AlertDialog) Objects(java.util.Objects) List(java.util.List) Nullable(androidx.annotation.Nullable) TextView(android.widget.TextView) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) BaseAdapter(android.widget.BaseAdapter) Consts(com.ichi2.libanki.Consts) CompatHelper(com.ichi2.compat.CompatHelper) Toolbar(androidx.appcompat.widget.Toolbar) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) ListView(android.widget.ListView) Pattern(java.util.regex.Pattern) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) Typeface(android.graphics.Typeface) Context(android.content.Context) Pair(android.util.Pair) Intent(android.content.Intent) SystemClock(android.os.SystemClock) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) HashMap(java.util.HashMap) SdCardReceiver(com.ichi2.anki.receiver.SdCardReceiver) Collection(com.ichi2.libanki.Collection) Column(com.ichi2.anki.CardBrowser.Column) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TASK_TYPE(com.ichi2.async.CollectionTask.TASK_TYPE) HashSet(java.util.HashSet) DeckDropDownAdapter(com.ichi2.anki.widgets.DeckDropDownAdapter) WidgetStatus(com.ichi2.widget.WidgetStatus) Menu(android.view.Menu) SimpleMessageDialog(com.ichi2.anki.dialogs.SimpleMessageDialog) Utils(com.ichi2.libanki.Utils) LinkedHashSet(java.util.LinkedHashSet) DialogInterface(android.content.DialogInterface) IntegerDialog(com.ichi2.anki.dialogs.IntegerDialog) CheckResult(androidx.annotation.CheckResult) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) AbsListView(android.widget.AbsListView) CollectionTask(com.ichi2.async.CollectionTask) Themes(com.ichi2.themes.Themes) Spinner(android.widget.Spinner) ArrayAdapter(android.widget.ArrayAdapter) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) SECONDS_PER_DAY(com.ichi2.libanki.stats.Stats.SECONDS_PER_DAY) LanguageUtil(com.ichi2.utils.LanguageUtil) Card(com.ichi2.libanki.Card) VisibleForTesting(androidx.annotation.VisibleForTesting) ActivityTransitionAnimation(com.ichi2.anim.ActivityTransitionAnimation) Collections(java.util.Collections) CardBrowserOrderDialog(com.ichi2.anki.dialogs.CardBrowserOrderDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) TaskData(com.ichi2.async.TaskData) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) Iterator(java.util.Iterator) SimpleMessageDialog(com.ichi2.anki.dialogs.SimpleMessageDialog) Deck(com.ichi2.libanki.Deck) JSONException(com.ichi2.utils.JSONException) Intent(android.content.Intent) Card(com.ichi2.libanki.Card) JSONObject(com.ichi2.utils.JSONObject) IntegerDialog(com.ichi2.anki.dialogs.IntegerDialog) JSONObject(com.ichi2.utils.JSONObject) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with RescheduleDialog

use of com.ichi2.anki.dialogs.RescheduleDialog in project Anki-Android by ankidroid.

the class Reviewer method showRescheduleCardDialog.

private void showRescheduleCardDialog() {
    Consumer<Integer> runnable = days -> {
        List<Long> cardIds = Collections.singletonList(mCurrentCard.getId());
        new SchedulerService.RescheduleCards(cardIds, days).runWithHandler(scheduleCollectionTaskHandler(R.plurals.reschedule_cards_dialog_acknowledge));
    };
    RescheduleDialog dialog = RescheduleDialog.rescheduleSingleCard(getResources(), mCurrentCard, runnable);
    showDialogFragment(dialog);
}
Also used : JavascriptInterface(android.webkit.JavascriptInterface) LinearLayout(android.widget.LinearLayout) COMMAND_NOTHING(com.ichi2.anki.cardviewer.ViewerCommand.COMMAND_NOTHING) Bundle(android.os.Bundle) MenuItemCompat(androidx.core.view.MenuItemCompat) PackageManager(android.content.pm.PackageManager) AnswerTimer(com.ichi2.anki.reviewer.AnswerTimer) NonNull(androidx.annotation.NonNull) AutomaticAnswerAction(com.ichi2.anki.reviewer.AutomaticAnswerAction) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) UnderlineSpan(android.text.style.UnderlineSpan) Animator(android.animation.Animator) DrawableRes(androidx.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) Permissions(com.ichi2.utils.Permissions) ColorStateList(android.content.res.ColorStateList) COMMAND_EXIT(com.ichi2.anki.cardviewer.ViewerCommand.COMMAND_EXIT) ActionBar(androidx.appcompat.app.ActionBar) Manifest(android.Manifest) Decks(com.ichi2.libanki.Decks) ViewerCommand(com.ichi2.anki.cardviewer.ViewerCommand) AndroidUiUtils(com.ichi2.utils.AndroidUiUtils) Handler(android.os.Handler) PluralsRes(androidx.annotation.PluralsRes) View(android.view.View) ActionButtons(com.ichi2.anki.reviewer.ActionButtons) WebView(android.webkit.WebView) ContextCompat(androidx.core.content.ContextCompat) CardMarker(com.ichi2.anki.reviewer.CardMarker) TaskListenerBuilder(com.ichi2.anki.servicelayer.TaskListenerBuilder) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SubMenu(android.view.SubMenu) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) IdRes(androidx.annotation.IdRes) List(java.util.List) Unit(kotlin.Unit) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Message(android.os.Message) Consts(com.ichi2.libanki.Consts) Gesture(com.ichi2.anki.cardviewer.Gesture) AudioView(com.ichi2.anki.multimediacard.AudioView) Context(android.content.Context) NextCard(com.ichi2.anki.servicelayer.SchedulerService.NextCard) ViewGroupUtils(com.ichi2.utils.ViewGroupUtils) KeyEvent(android.view.KeyEvent) ResourcesCompat(androidx.core.content.res.ResourcesCompat) HandlerUtils(com.ichi2.utils.HandlerUtils) Direction(com.ichi2.anim.ActivityTransitionAnimation.Direction) Counts(com.ichi2.libanki.sched.Counts) Intent(android.content.Intent) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) Collection(com.ichi2.libanki.Collection) AnswerButtons(com.ichi2.anki.reviewer.AnswerButtons) MenuItem(android.view.MenuItem) MenuRes(androidx.annotation.MenuRes) SuppressLint(android.annotation.SuppressLint) WidgetStatus(com.ichi2.widget.WidgetStatus) PeripheralKeymap(com.ichi2.anki.reviewer.PeripheralKeymap) Menu(android.view.Menu) CardAppearance(com.ichi2.anki.cardviewer.CardAppearance) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) Utils(com.ichi2.libanki.Utils) NoteService(com.ichi2.anki.servicelayer.NoteService) CheckResult(androidx.annotation.CheckResult) Computation(com.ichi2.utils.Computation) SpannableString(android.text.SpannableString) ActivityCompat(androidx.core.app.ActivityCompat) MenuBuilder(androidx.appcompat.view.menu.MenuBuilder) ReviewerUi(com.ichi2.anki.reviewer.ReviewerUi) Themes(com.ichi2.themes.Themes) File(java.io.File) Consumer(java.util.function.Consumer) SharedPreferences(android.content.SharedPreferences) ActionProvider(androidx.core.view.ActionProvider) FirefoxSnackbarWorkaround(com.ichi2.anki.workarounds.FirefoxSnackbarWorkaround) Card(com.ichi2.libanki.Card) VisibleForTesting(androidx.annotation.VisibleForTesting) FullScreenMode(com.ichi2.anki.reviewer.FullScreenMode) Collections(java.util.Collections) SchedulerService(com.ichi2.anki.servicelayer.SchedulerService) RescheduleDialog(com.ichi2.anki.dialogs.RescheduleDialog) ColorStateList(android.content.res.ColorStateList) List(java.util.List)

Aggregations

Context (android.content.Context)5 Intent (android.content.Intent)5 SharedPreferences (android.content.SharedPreferences)5 Bundle (android.os.Bundle)5 Menu (android.view.Menu)5 MenuItem (android.view.MenuItem)5 View (android.view.View)5 ViewGroup (android.view.ViewGroup)5 TextView (android.widget.TextView)5 NonNull (androidx.annotation.NonNull)5 VisibleForTesting (androidx.annotation.VisibleForTesting)5 Handler (android.os.Handler)4 TypedValue (android.util.TypedValue)4 CheckResult (androidx.annotation.CheckResult)4 Nullable (androidx.annotation.Nullable)4 ActionBar (androidx.appcompat.app.ActionBar)4 ConfirmationDialog (com.ichi2.anki.dialogs.ConfirmationDialog)4 RescheduleDialog (com.ichi2.anki.dialogs.RescheduleDialog)4 Collection (com.ichi2.libanki.Collection)4 Consts (com.ichi2.libanki.Consts)4