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);
}
Aggregations