Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Список товаров с возможностью положить их в корзину прямо из этого списка. Если что-то выбрано - появляется кнопка заказать. Если не выбрано - скрывается. В экшнбаре есть фильтр по названию. Работает всё быстро и без подключения к интернету. */
- @EActivity(R.layout.activity_drug_list)
- @OptionsMenu(R.menu.menu_druglist)
- public class DrugListActivity extends ActionBarActivity { // instead of just Activity for SupportLoader
- @ViewById ListView list;
- public ContentListAdapter adapter;
- @Bean ContentListLoader contentListLoader;
- @ViewById Toolbar toolbar;
- @ViewById Button order;
- @OptionsMenuItem MenuItem searchBar;
- SearchView searchView;
- @AfterViews void init() {
- list.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
- setSupportActionBar(toolbar);
- getSupportActionBar().setDisplayShowHomeEnabled(true);
- adapter = new ContentListAdapter<>(this, list, SelectableDrugItem_::build);
- list.setAdapter(adapter);
- contentListLoader.init(getSupportLoaderManager(), DrugContract.CONTENT_URI, adapter,
- (context, uri, filter) -> new CursorLoader(context, uri, null,
- DrugContract.NAME + " LIKE ?", new String[]{"%" + filter + "%"}, null),
- c -> order.setVisibility( total(c) > 0 ? VISIBLE : GONE ) );
- }
- @Override public boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- searchView = (SearchView) MenuItemCompat.getActionView(searchBar);
- searchView.setOnQueryTextListener(new LiveSearch(contentListLoader));
- return true;
- }
- @ItemClick void list ( Cursor cursor ) {
- // I fixed that bug too much time. In the beginning ListView will call setChecked with
- // its own (ListView) values. You can change it with ListView.setItemChecked
- // (see listParams.setItemChecked( position, drug.inCart ) in DrugItem.bind );
- // So if you will notify right get Checkable.setChecked it will change cursor and
- // in the new beginning will call setChecked again and again cursor will be changed
- getContentResolver().notifyChange(DrugContract.CONTENT_URI, null);
- }
- @Click void order() {
- OrderAccountActivity_.intent(this).start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment