Search in sources :

Example 1 with OrderListAdapter

use of com.ichi2.anki.widgets.OrderListAdapter in project AnkiChinaAndroid by ankichinateam.

the class SelfStudyActivity method showOrderListDialog.

private void showOrderListDialog() {
    mToolbar.setVisibility(View.GONE);
    mTop.setVisibility(View.VISIBLE);
    InputMethodManager manager = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
    if (manager != null && getCurrentFocus() != null) {
        manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
    View dialog = getLayoutInflater().inflate(R.layout.pop_window_order_choice, null);
    mOrderListWindow = new PopupWindow(dialog, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    mOrderAdapter = new OrderListAdapter(getLayoutInflater(), this);
    mOrderRecyclerView = dialog.findViewById(R.id.orders);
    mOrderRecyclerView.setAdapter(mOrderAdapter);
    mOrderRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    List<OrderListAdapter.OrderItem> orderItems = new ArrayList<>();
    String[] items = getResources().getStringArray(R.array.card_browser_order_labels);
    for (int c = 0; c < fSortTypes.length; ++c) {
        OrderListAdapter.OrderItem item = new OrderListAdapter.OrderItem();
        item.name = items[c];
        item.selected = c == mOrder;
        item.index = c;
        item.asc = mOrderAsc;
        if (c == mOrder) {
            selectedItem = item;
        }
        orderItems.add(item);
    }
    mOrderAdapter.setItems(orderItems);
    mOrderAdapter.setItemClickListener(v -> {
        for (OrderListAdapter.OrderItem item : orderItems) {
            item.selected = item == v.getTag();
        }
        selectedItem = (OrderListAdapter.OrderItem) v.getTag();
        mOrderAdapter.notifyDataSetChanged();
    });
    View.OnClickListener changeAsc = v -> {
        selectedItem.asc = !selectedItem.asc;
        mOrderAdapter.notifyItemChanged(selectedItem.index);
    };
    dialog.findViewById(R.id.confirm).setOnClickListener(v -> {
        mOrderListWindow.dismiss();
        if (selectedItem.index != mOrder) {
            mOrder = selectedItem.index;
            mOrderAsc = selectedItem.asc;
            if (mOrder == 0) {
                getCol().getConf().put("sortType", fSortTypes[1]);
                AnkiDroidApp.getSharedPrefs(getBaseContext()).edit().putBoolean("cardBrowserNoSorting", true).commit();
            } else {
                getCol().getConf().put("sortType", fSortTypes[mOrder]);
                AnkiDroidApp.getSharedPrefs(getBaseContext()).edit().putBoolean("cardBrowserNoSorting", false).commit();
            }
            getCol().getConf().put("sortBackwards", mOrderAsc);
            searchCards();
        } else if (selectedItem.index != CARD_ORDER_NONE && mOrderAsc != selectedItem.asc) {
            mOrderAsc = selectedItem.asc;
            getCol().getConf().put("sortBackwards", mOrderAsc);
            Collections.reverse(mCards);
            updateList();
        }
        mCardsAdapter.updateOrderState(mOrderNames[mOrder], mOrderAsc);
    });
    mOrderAdapter.setIvOrderClickListener(changeAsc);
    mOrderAdapter.setTvOrderClickListener(changeAsc);
    mOrderListWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    mOrderListWindow.setOutsideTouchable(false);
    mOrderListWindow.setFocusable(true);
    mOrderListWindow.setOnDismissListener(() -> {
        findViewById(R.id.shadeView).setVisibility(View.GONE);
        mToolbar.setVisibility(View.VISIBLE);
        mTop.setVisibility(View.GONE);
    });
    mOrderListWindow.showAsDropDown(mTop, 0, 0);
    findViewById(R.id.shadeView).setVisibility(View.VISIBLE);
}
Also used : 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) ListPopupWindow(androidx.appcompat.widget.ListPopupWindow) PopupWindow(android.widget.PopupWindow) ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) OrderListAdapter(com.ichi2.anki.widgets.OrderListAdapter)

Aggregations

AlertDialog (android.app.AlertDialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 TypedArray (android.content.res.TypedArray)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 SystemClock (android.os.SystemClock)1 TextUtils (android.text.TextUtils)1 TypedValue (android.util.TypedValue)1 Gravity (android.view.Gravity)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 WindowManager (android.view.WindowManager)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 AdapterView (android.widget.AdapterView)1