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);
}
Aggregations