Esempio n. 1
0
  @AfterViews
  void bindDrawer() {

    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawerLayout == null) {
      return;
    }
    drawer = findViewById(R.id.drawer);

    View headerView = inflater.inflate(R.layout.drawer_listview_header, null);
    headerView.findViewById(R.id.create_payment_group).setOnClickListener(this);

    ListView drawerListView = (ListView) drawer.findViewById(R.id.drawer_listview);
    drawerListView.addHeaderView(headerView);

    List<PaymentGroup> paymentGroups = paymentGroupDao.queryForAllSorted();

    adapter = new PaymentGroupAdapter(this);
    adapter.setData(paymentGroups);

    drawerListView.setAdapter(adapter);

    drawerToggle =
        new ActionBarDrawerToggle(
            this, drawerLayout, R.drawable.ic_drawer, R.string.app_name, R.string.app_name) {

          public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            adapter.notifyDataSetChanged();
            invalidateOptionsMenu();
          }

          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            adapter.notifyDataSetChanged();
            invalidateOptionsMenu();
          }

          @Override
          public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
          }

          @Override
          public void onDrawerStateChanged(int newState) {
            super.onDrawerStateChanged(newState);
          }
        };

    drawerLayout.setDrawerListener(drawerToggle);
  }
Esempio n. 2
0
  @ItemLongClick
  public void drawerListviewItemLongClicked(final int position) {
    if (adapter.getCount() == 1) {
      Notifier.toast(R.string.msg_more_than_one);
      return;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder
        .setTitle(R.string.delete)
        .setMessage(R.string.delete_desc)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                ListView drawerListView = (ListView) drawer.findViewById(R.id.drawer_listview);
                int headerViewsCount = drawerListView.getHeaderViewsCount();

                final PaymentGroup group = adapter.getItem(position - headerViewsCount);

                int firstPosition = drawerListView.getFirstVisiblePosition();
                int lastPosition = drawerListView.getLastVisiblePosition();

                if (firstPosition <= position && lastPosition >= position) {
                  int selectedIndex = position - firstPosition;
                  final View view = drawerListView.getChildAt(selectedIndex);
                  AnimUtils.fadeOut(
                      view,
                      new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                          deletePaymentGroup(group);
                          view.setAlpha(1);
                        }
                      });
                } else {
                  deletePaymentGroup(group);
                }
              }
            })
        .setNegativeButton(android.R.string.cancel, null)
        .show();
  }
Esempio n. 3
0
 @UiThread
 void setUpListview(List<PaymentGroup> paymentGroups) {
   adapter.setData(paymentGroups);
 }
Esempio n. 4
0
 public void onEventMainThread(PaymentGroupChangedEvent event) {
   adapter.refresh(event.group);
 }
Esempio n. 5
0
 public void onEventMainThread(CreatePaymentGroupEvent event) {
   adapter.addDataAt(0, event.group);
 }