Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Method based @ViewsById isEmpty() #1966

Description

@miszmaniac

I've tried to used method based @ViewsById method, but found out that method parameter is empty List.
This happens beacuse of wrong order of calls in generated code.
I've also noticed that test of this part of code is incorrect.
zrzut ekranu 2017-03-07 11 32 31

AndroidAnnotations version:
4.2.0
Android compile SDK version:
25
Annotated code:

 @ViewsById({R.id.divider_1, R.id.divider_2, R.id.divider_3, R.id.short_cut_container})
    void init(List<View> views) {
       ...
    }

Expected generated code:

@Override
    public void onViewChanged(HasViews hasViews) {
        ArrayList<View> list_init_views = new ArrayList<View>();
        View view_divider_1 = hasViews.findViewById(R.id.divider_1);
        View view_divider_2 = hasViews.findViewById(R.id.divider_2);
        View view_divider_3 = hasViews.findViewById(R.id.divider_3);
        View view_short_cut_container = hasViews.findViewById(R.id.short_cut_container);

        if (view_divider_1 != null) {
            list_init_views.add(view_divider_1);
        }
        if (view_divider_2 != null) {
            list_init_views.add(view_divider_2);
        }
        if (view_divider_3 != null) {
            list_init_views.add(view_divider_3);
        }
        if (view_short_cut_container!= null) {
            list_init_views.add(view_short_cut_container);
        }
    {
            List<View> views = null;
            views = list_init_views;
            init(views);
        }
    }

Actual generated code:

@Override
    public void onViewChanged(HasViews hasViews) {
        ArrayList<View> list_init_views = new ArrayList<View>();
        View view_divider_1 = hasViews.findViewById(R.id.divider_1);
        View view_divider_2 = hasViews.findViewById(R.id.divider_2);
        View view_divider_3 = hasViews.findViewById(R.id.divider_3);
        View view_short_cut_container = hasViews.findViewById(R.id.short_cut_container);

        {
            List<View> views = null;
            views = list_init_views;
            init(views);
        }
        if (view_divider_1 != null) {
            list_init_views.add(view_divider_1);
        }
        if (view_divider_2 != null) {
            list_init_views.add(view_divider_2);
        }
        if (view_divider_3 != null) {
            list_init_views.add(view_divider_3);
        }
        if (view_short_cut_container!= null) {
            list_init_views.add(view_short_cut_container);
        }
    }

Activity

  1. self-assigned this
    on Mar 7, 2017
  2. dodgex commented on Mar 7, 2017

    @dodgex
    Member

    Thank you for your detailed report. I'll investigate this asap.

  3. miszmaniac commented on Mar 7, 2017

    @miszmaniac
    Author

    I was about to make PR, but I didn't manage to configure project:)

    I'm not sure if the instructions are up-to-date:)

  4. dodgex commented on Mar 7, 2017

    @dodgex
    Member

    AFAIK the contribution guide should be up to date.

    where do you have trouble?

  5. miszmaniac commented on Mar 7, 2017

    @miszmaniac
    Author

    I can't run functional tests (basically compile tests also, but mvnw install starts tests also

    https://github.com/androidannotations/androidannotations/wiki/InstallingEnvironment#running-the-functional-tests

    I got Error:Android Source Generator: [androidannotations] AndroidManifest.xml file not found

    I've changed those preferences of paths to support /src/main/, so I Have no idea why that is:)

  6. dodgex commented on Mar 8, 2017

    @dodgex
    Member

    Have you configured intellij to use the correct folders? (see here)

    Unfortunately, due to an IntelliJ bug, you have to adjust the AndroidManifest.xml and res folder paths manually. Go to File > Project structure > Facets. For each facet, in the Structure tab, change the manifest to point to src/main/AndroidManifest.xml inside the module, and the resources directory to point to src/main/res inside the module. In the Maven tab, uncheck the Manifest and Resources directory checkboxes, so IntelliJ will not undo your settings when you reimport the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions