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

[Q] Mimic an ExpandableListView #153

Closed
F43nd1r opened this issue Jul 29, 2016 · 14 comments
Closed

[Q] Mimic an ExpandableListView #153

F43nd1r opened this issue Jul 29, 2016 · 14 comments
Labels

Comments

@F43nd1r
Copy link

F43nd1r commented Jul 29, 2016

I want to create a view that is similar to an ExpandableListView.
I do not understand how I would approach this. I have read the guide on sections, but whatever I tried didn't work at all or behaved really weird.
Can you give me a simple (!) example how to create expandable (text-only) groups with (text-only) childs?

@F43nd1r F43nd1r changed the title [Q] Mimic a SimpleExpandableListView [Q] Mimic an ExpandableListView Jul 30, 2016
@F43nd1r
Copy link
Author

F43nd1r commented Jul 30, 2016

For example I tried to use one class extending AbstractExpandableHeaderItem and one extending AbstractSectionableItem, but I always run into

java.lang.ClassCastException: com.faendir.lightning_launcher.multitool.scriptmanager.ScriptGroupLayoutItem$ViewHolder cannot be cast to com.faendir.lightning_launcher.multitool.scriptmanager.ScriptLayoutItem$ViewHolder
at com.faendir.lightning_launcher.multitool.scriptmanager.ScriptLayoutItem.bindViewHolder(ScriptLayoutItem.java:20)
at eu.davidea.flexibleadapter.FlexibleAdapter.onBindViewHolder(FlexibleAdapter.java:1136)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5801)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5037)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4913)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2029)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1414)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:578)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3260)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3069)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3518)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
 at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1319)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:817)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1191)
at android.view.View.layout(View.java:16630)
 at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
at android.view.View.layout(View.java:16630)
at android.view.ViewGroup.layout(ViewGroup.java:5437)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
at android.view.View.layout(View.java:16630)
...

My setup code is

        ArrayList<AbstractFlexibleItem> testList = new ArrayList<>();
        ScriptGroupLayoutItem groupLayoutItem = new ScriptGroupLayoutItem(new ScriptGroup("TestGroup",true));
        ScriptLayoutItem scriptLayoutItem = new ScriptLayoutItem(groupLayoutItem,s);
        groupLayoutItem.addSubItem(scriptLayoutItem);
        testList.add(groupLayoutItem);
        FlexibleAdapter<AbstractFlexibleItem> flexibleAdapter = new FlexibleAdapter<>(testList);
        flexibleAdapter.expandItemsAtStartUp()
                .setAutoScrollOnExpand(true)
                .setAutoCollapseOnExpand(false)
                .setAnimationOnScrolling(true)
                .setAnimationOnReverseScrolling(true);
        recyclerView.setAdapter(flexibleAdapter);

@davideas
Copy link
Owner

davideas commented Jul 30, 2016

Hello @F43nd1r!
ScriptGroupLayoutItem$ViewHolder cannot be cast to ScriptLayoutItem$ViewHolder.
Probably you have the same layout in getLayoutRes(), because the Adapter calls the method of ScriptLayoutItem.bindViewHolder based on the mapping of the layout resource.

Then, be sure to use only the SNAPSHOT release until next beta.

Regarding the example, the code for creating items in the demoApp didn't help you?

@F43nd1r
Copy link
Author

F43nd1r commented Jul 30, 2016

Probably you have the same layout in getLayoutRes(), because the Adapter calls the method of ScriptLayoutItem.bindViewHolder based on the mapping of the layout resource.

Is that documented somewhere? If yes, my bad. If not, it should be.

Regarding the example, the code for creating items in the demoApp didn't help you?

After several hours I slowly start to understand how it works. The relevant code is split up in so many classes, it really takes some time to seek through it all (particularly the DatabaseService isn't used via reference but via singleton, which makes it very hard to understand the correlation).

@F43nd1r
Copy link
Author

F43nd1r commented Jul 30, 2016

Okay now I have another problem: I can't collapse the group, whenever the item should be hidden it gets duplicated instead.
Attached: video.zip

@davideas
Copy link
Owner

Can you also write some code here?
The section collapsed/expanded is handled already from the ExpandableViewHolder. You can see the code of the library with lot of java doc in it.

Layout resource is documented in item interfaces wiki page.
Also about the Method A and B, I suppose you use method A, so it's easy to understand that every item represents a different layout.

You actually don't need to know how the database list is provided in the demo app, you can initialize the list how you want, that is just a demo to easily show different examples. What you need to know how to create the classes of the items and the view holders with the relative listeners. But wiki pages also explain everything.
Ok, I still need to write something more about expandable, but demoApp is well covered on it.

@F43nd1r
Copy link
Author

F43nd1r commented Jul 30, 2016

Code is here. Initialization is inside the ListManager, the two item classes are ScriptLayoutItemand ScriptGroupLayoutItem.

@davideas
Copy link
Owner

I've analyzed your code, but I don't find anything wrong for now.
Could you please enable logs with FlexibleAdapter.enableLogs(true); before initialization?
And paste the logs here when you collapse/expand just once?

I also published a new SNAPSHOT with also a little fix for multilevel expandable, but I don't think it is related to your problem.

@F43nd1r
Copy link
Author

F43nd1r commented Jul 31, 2016

07-31 05:28:58.818 1929-1929/com.faendir.lightning_launcher.multitool I/FlexibleAdapter: Mapped viewType 17367046 from ScriptGroupLayoutItem
07-31 05:28:58.819 1929-1929/com.faendir.lightning_launcher.multitool I/FlexibleAdapter: Mapped viewType 17367043 from ScriptLayoutItem
07-31 05:30:24.759 1929-1929/com.faendir.lightning_launcher.multitool V/FlexibleAdapter: Request to Collapse on position=0 expanded=true hasSubItemsSelected=false
07-31 05:30:24.759 1929-1929/com.faendir.lightning_launcher.multitool V/FlexibleAdapter: Collapsed 1 subItems on position 0
07-31 05:30:26.733 1929-1929/com.faendir.lightning_launcher.multitool V/FlexibleAdapter: Expanded 1 subItems on position=0

This looks perfectly fine, but sadly doesn't mirror the behaviour. I still have two items afterwards.

@davideas
Copy link
Owner

I'm trying your app but I can't have the list you have. How can I have the list to test?

  • I can't use it in the emulator because missing repository app.
  • When I use my phone, it doesn't load anything in ScriptManager.

@davideas
Copy link
Owner

davideas commented Jul 31, 2016

However the problem is here, dear @F43nd1r:
Do you see this warning message?

'equals()' should check the class of its parameter...
Reports equals() methods which do not check the type of their parameter.
Failure to check the type of the parameter in the equals() method may result in latent errors if the object is later used in an untyped collection.

This equals method returns always false:

@Override
public boolean equals(Object o) {
    return group.equals(o);
}

And also this is documented, for this time it passes, but for the next time please read the javaDoc of the methods and also the Wiki pages.

However, I would like to try your app, but I can't have the list loaded :-(

@F43nd1r
Copy link
Author

F43nd1r commented Jul 31, 2016

This equals method returns always false

I feel so dumb right now... I'm sorry. Yes it works now.

However, I would like to try your app, but I can't have the list loaded :-(

I'm sorry, this app is a helper for Lightning Launcher and requires another low-level helper, the Repository Importer to work. It won't be able to do anything without these, because the list of scripts displayed here is the list of scripts in the launcher (and the importer provides the service which loads these scripts from it).
I'd tell you to install these apps, but Lightning isn't free. So, all I can give you are videos.

@F43nd1r F43nd1r closed this as completed Jul 31, 2016
@davideas
Copy link
Owner

davideas commented Jul 31, 2016

Well the request was mainly to resolve your problem.
Not needed anymore.

Just if you want to mention the usage of this library in your app and to add your app in the main page, I will thank you. If you decide to use it eventually.

@F43nd1r
Copy link
Author

F43nd1r commented Jul 31, 2016

Of course your library will be added to the credits section in the play store, if I publish an update with it. (Right now there is no 'About' section in the app itself and I'm not sure if I'm legally required to add it, but if it exists some time, it'll be added there too.)

For now I have to get a lot of things working first. Right now I'm working on multi selection. You might see another issue from me in the future if I can't sort it out with help of the docs & sample.

@davideas
Copy link
Owner

Ok, the library is still in beta, something might not work as expected, even if, now it seems quite stable.
When I will be ready I will publish beta8, I hope during next month.

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

No branches or pull requests

2 participants