egslava

Android Health 3

Oct 22nd, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.49 KB | None | 0 0
  1. /* Список товаров с возможностью положить их в корзину прямо из этого списка. Если что-то выбрано - появляется кнопка заказать. Если не выбрано - скрывается. В экшнбаре есть фильтр по названию. Работает всё быстро и без подключения к интернету. */
  2.  
  3. @EActivity(R.layout.activity_drug_list)
  4. @OptionsMenu(R.menu.menu_druglist)
  5. public class DrugListActivity extends ActionBarActivity { // instead of just Activity for SupportLoader
  6.  
  7.     @ViewById   ListView list;
  8.  
  9.     public  ContentListAdapter adapter;
  10.     @Bean   ContentListLoader contentListLoader;
  11.  
  12.     @ViewById   Toolbar toolbar;
  13.     @ViewById   Button  order;
  14.  
  15.     @OptionsMenuItem    MenuItem    searchBar;
  16.     SearchView  searchView;
  17.  
  18.     @AfterViews void init() {
  19.         list.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
  20.  
  21.         setSupportActionBar(toolbar);
  22.         getSupportActionBar().setDisplayShowHomeEnabled(true);
  23.  
  24.         adapter = new ContentListAdapter<>(this, list, SelectableDrugItem_::build);
  25.         list.setAdapter(adapter);
  26.         contentListLoader.init(getSupportLoaderManager(), DrugContract.CONTENT_URI, adapter,
  27.                 (context, uri, filter) -> new CursorLoader(context, uri, null,
  28.                         DrugContract.NAME + " LIKE ?", new String[]{"%" + filter + "%"}, null),
  29.                 c -> order.setVisibility( total(c) > 0 ? VISIBLE : GONE ) );
  30.     }
  31.  
  32.     @Override public boolean onCreateOptionsMenu(Menu menu) {
  33.         super.onCreateOptionsMenu(menu);
  34.         searchView = (SearchView) MenuItemCompat.getActionView(searchBar);
  35.         searchView.setOnQueryTextListener(new LiveSearch(contentListLoader));
  36.         return true;
  37.     }
  38.  
  39.  
  40.     @ItemClick void list ( Cursor cursor ) {
  41.         // I fixed that bug too much time. In the beginning ListView will call setChecked with
  42.         // its own (ListView) values. You can change it with ListView.setItemChecked
  43.         // (see listParams.setItemChecked( position, drug.inCart ) in DrugItem.bind );
  44.  
  45.         // So if you will notify right get Checkable.setChecked it will change cursor and
  46.         // in the new beginning will call setChecked again and again cursor will be changed
  47.         getContentResolver().notifyChange(DrugContract.CONTENT_URI, null);
  48.     }
  49.  
  50.     @Click  void order() {
  51.         OrderAccountActivity_.intent(this).start();
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment