Let the adapter handle the decorator
This should remove the hackiness of decorator being added several times.
This commit is contained in:
parent
48b21626e4
commit
fd22ee01e0
@ -28,8 +28,6 @@ class WhatsNewViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private final WhatsNewAdapter whatsNewAdapter;
|
||||
private final AppCompatActivity activity;
|
||||
|
||||
private static RecyclerView.ItemDecoration appListDecorator;
|
||||
|
||||
WhatsNewViewBinder(final AppCompatActivity activity, FrameLayout parent) {
|
||||
this.activity = activity;
|
||||
|
||||
@ -45,20 +43,6 @@ class WhatsNewViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
appList.setLayoutManager(layoutManager);
|
||||
appList.setAdapter(whatsNewAdapter);
|
||||
|
||||
// This is a bit hacky, but for some reason even though we are inflating the main_tab_whats_new
|
||||
// layout above, the app_list RecyclerView seems to remember that it has decorations from before.
|
||||
// If we blindly call addItemDecoration here without first removing the existing one, it will
|
||||
// double up on all of the paddings the second time we view it. The third time it will triple up
|
||||
// on the paddings, etc. In addition, the API doesn't allow us to "clearAllDecorators()". Instead
|
||||
// we need to hold onto the reference to the one we added in order to remove it.
|
||||
if (appListDecorator == null) {
|
||||
appListDecorator = new WhatsNewAdapter.ItemDecorator(activity);
|
||||
} else {
|
||||
appList.removeItemDecoration(appListDecorator);
|
||||
}
|
||||
|
||||
appList.addItemDecoration(appListDecorator);
|
||||
|
||||
final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) whatsNewView.findViewById(R.id.swipe_to_refresh);
|
||||
swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
|
@ -18,9 +18,23 @@ public class WhatsNewAdapter extends RecyclerView.Adapter<AppCardController> {
|
||||
|
||||
private Cursor cursor;
|
||||
private final Activity activity;
|
||||
private final RecyclerView.ItemDecoration appListDecorator;
|
||||
|
||||
public WhatsNewAdapter(Activity activity) {
|
||||
this.activity = activity;
|
||||
appListDecorator = new WhatsNewAdapter.ItemDecorator(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
recyclerView.addItemDecoration(appListDecorator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
|
||||
recyclerView.removeItemDecoration(appListDecorator);
|
||||
super.onDetachedFromRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,10 +106,10 @@ public class WhatsNewAdapter extends RecyclerView.Adapter<AppCardController> {
|
||||
* @see org.fdroid.fdroid.R.dimen#whats_new__padding__app_card__horizontal
|
||||
* @see org.fdroid.fdroid.R.dimen#whats_new__padding__app_card__vertical
|
||||
*/
|
||||
public static class ItemDecorator extends RecyclerView.ItemDecoration {
|
||||
private class ItemDecorator extends RecyclerView.ItemDecoration {
|
||||
private final Context context;
|
||||
|
||||
public ItemDecorator(Context context) {
|
||||
ItemDecorator(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user