Search in sources :

Example 1 with OverscrollLinearLayoutManager

use of org.fdroid.fdroid.views.OverscrollLinearLayoutManager in project fdroidclient by f-droid.

the class AppDetails2 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    fdroidApp = (FDroidApp) getApplication();
    fdroidApp.applyTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.app_details2);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    // Nice and clean toolbar
    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_back);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    supportPostponeEnterTransition();
    if (!reset(getPackageNameFromIntent(getIntent()))) {
        finish();
        return;
    }
    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.rootCoordinator);
    appBarLayout = (AppBarLayout) coordinatorLayout.findViewById(R.id.app_bar);
    recyclerView = (RecyclerView) findViewById(R.id.rvDetails);
    adapter = new AppDetailsRecyclerViewAdapter(this, app, this);
    OverscrollLinearLayoutManager lm = new OverscrollLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    lm.setStackFromEnd(false);
    // Has to be invoked after AppDetailsRecyclerViewAdapter is created.
    refreshStatus();
    /* The recyclerView/AppBarLayout combo has a bug that prevents a "fling" from the bottom
         * to continue all the way to the top by expanding the AppBarLayout. It will instead stop
         * with the app bar in a collapsed state. See here: https://code.google.com/p/android/issues/detail?id=177729
         * Not sure this is the exact issue, but it is true that while in a fling the RecyclerView will
         * consume the scroll events quietly, without calling the nested scrolling mechanism.
         * We fix this behavior by using an OverscrollLinearLayoutManager that will give us information
         * of overscroll, i.e. when we have not consumed all of a scroll event, and use this information
         * to send the scroll to the app bar layout so that it will expand itself.
         */
    lm.setOnOverscrollListener(new OverscrollLinearLayoutManager.OnOverscrollListener() {

        @Override
        public int onOverscrollX(int overscroll) {
            return 0;
        }

        @Override
        public int onOverscrollY(int overscroll) {
            int consumed = 0;
            if (overscroll < 0) {
                CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
                CoordinatorLayout.Behavior behavior = lp.getBehavior();
                if (behavior != null && behavior instanceof AppBarLayout.Behavior) {
                    ((AppBarLayout.Behavior) behavior).onNestedScroll(coordinatorLayout, appBarLayout, recyclerView, 0, 0, 0, overscroll);
                    // Consume all of it!
                    consumed = overscroll;
                }
            }
            return consumed;
        }
    });
    recyclerView.setLayoutManager(lm);
    recyclerView.setAdapter(adapter);
    recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            supportStartPostponedEnterTransition();
            return true;
        }
    });
    // Load the feature graphic, if present
    final FeatureImage featureImage = (FeatureImage) findViewById(R.id.feature_graphic);
    DisplayImageOptions displayImageOptions = Utils.getRepoAppDisplayImageOptions();
    String featureGraphicUrl = app.getFeatureGraphicUrl(this);
    featureImage.loadImageAndDisplay(ImageLoader.getInstance(), displayImageOptions, featureGraphicUrl, app.iconUrl);
}
Also used : FeatureImage(org.fdroid.fdroid.views.apps.FeatureImage) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) AppDetailsRecyclerViewAdapter(org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter) AppBarLayout(android.support.design.widget.AppBarLayout) ViewTreeObserver(android.view.ViewTreeObserver) OverscrollLinearLayoutManager(org.fdroid.fdroid.views.OverscrollLinearLayoutManager) Toolbar(android.support.v7.widget.Toolbar) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Aggregations

AppBarLayout (android.support.design.widget.AppBarLayout)1 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)1 Toolbar (android.support.v7.widget.Toolbar)1 ViewTreeObserver (android.view.ViewTreeObserver)1 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)1 AppDetailsRecyclerViewAdapter (org.fdroid.fdroid.views.AppDetailsRecyclerViewAdapter)1 OverscrollLinearLayoutManager (org.fdroid.fdroid.views.OverscrollLinearLayoutManager)1 FeatureImage (org.fdroid.fdroid.views.apps.FeatureImage)1