Beispiel #1
0
  @Override
  protected void onDestroy() {
    super.onDestroy();

    if (mRecyclerViewSwipeManager != null) {
      mRecyclerViewSwipeManager.release();
      mRecyclerViewSwipeManager = null;
    }

    if (mRecyclerViewTouchActionGuardManager != null) {
      mRecyclerViewTouchActionGuardManager.release();
      mRecyclerViewTouchActionGuardManager = null;
    }

    if (mRecyclerView != null) {
      mRecyclerView.setItemAnimator(null);
      mRecyclerView.setAdapter(null);
      mRecyclerView = null;
    }

    if (mWrappedAdapter != null) {
      WrapperAdapterUtils.releaseAll(mWrappedAdapter);
      mWrappedAdapter = null;
    }
    mAdapter = null;
    mLayoutManager = null;

    if (mLazyList != null) {
      mLazyList.close();
    }
  }
Beispiel #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_draft);

    mTip = findViewById(R.id.tip);
    mRecyclerView = (EasyRecyclerView) findViewById(R.id.recycler_view);
    mViewTransition = new ViewTransition(mTip, mRecyclerView);

    // Layout Manager
    mLayoutManager = new LinearLayoutManager(this);

    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss
    // animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);

    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();

    mAdapter = new DraftAdapter();
    mAdapter.setHasStableIds(true);
    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mAdapter); // wrap for swiping

    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();

    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works
    // properly.
    animator.setSupportsChangeAnimations(false);

    mRecyclerView.hasFixedSize();
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setOnItemClickListener(this);

    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event
    // handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);

    updateLazyList();
    checkEmpty(false);
  }