Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching between Linear/Grid LayoutManagers Bug #32

Closed
PatrickDattilio opened this issue Feb 19, 2015 · 3 comments
Closed

Switching between Linear/Grid LayoutManagers Bug #32

PatrickDattilio opened this issue Feb 19, 2015 · 3 comments

Comments

@PatrickDattilio
Copy link

When switching between a Linear/Grid LayoutManager, SuperSLiM... well it does this.

Source code for the example project here

@TonicArtos TonicArtos added the bug label Feb 19, 2015
@TonicArtos
Copy link
Owner

👍 That's pretty cool. I haven't tested swapping SLMs yet, but any time is a good time. I'll get this fixed as soon as I get some more sleep :)

@PatrickDattilio
Copy link
Author

It's pretty late on your side of the pond! From playing with the sample, it feels as though it's the switching of the header that breaks it.

If you leave the header using the LinearLM and switch the items to the GridLM, they simply stay the same size but headers are removed. It isn't until you switch the header over that the items appear as a grid. This of course gives us the awesome berserk header spam.

@TonicArtos TonicArtos removed the bug label Feb 19, 2015
@TonicArtos
Copy link
Owner

There is a bug in SuperSLiM and a bug in your code. Here is a patch to get your coding working.

From 66fb94f1387e0f4e6df49cba494db942239b0cc2 Mon Sep 17 00:00:00 2001
From: Tonic Artos <tonic.artos@gmail.com>
Date: Thu, 19 Feb 2015 13:39:16 +0000
Subject: [PATCH] Fix layout corruption on SLM swap.

- Workaround bug with sections with only headers.
- Correctly notify datachanges on SLM change, requestLayout() is not
  enough with RecyclerView.
---
 .../java/com/dattilio/patrick/superslimtest/RecyclerAdapter.java    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/src/main/java/com/dattilio/patrick/superslimtest/RecyclerAdapter.java b/app/src/main/java/com/dattilio/patrick/superslimtest/RecyclerAdapter.java
index 006e119..fb2e13d 100644
--- a/app/src/main/java/com/dattilio/patrick/superslimtest/RecyclerAdapter.java
+++ b/app/src/main/java/com/dattilio/patrick/superslimtest/RecyclerAdapter.java
@@ -87,7 +87,7 @@ public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
                 break;
             case GRID_ITEM:
                 lp.layoutId = 1;
-                lp.setFirstPosition(2);
+                lp.setFirstPosition(1);
                 holder.itemView.setLayoutParams(lp);
                 break;
         }
@@ -129,7 +129,7 @@ public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
                 @Override
                 public void onClick(View v) {
                     isList = true;
-                    recyclerView.requestLayout();
+                    notifyItemRangeChanged(1, getItemCount() - 1);
                 }
             });

@@ -137,7 +137,7 @@ public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
                 @Override
                 public void onClick(View v) {
                     isList = false;
-                    recyclerView.requestLayout();
+                    notifyItemRangeChanged(1, getItemCount() - 1);
                 }
             });
         }
-- 
2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants