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.

Optimisation: Remove doubled findViewById calls #1501

@ened

Description

@ened

Given I have a class like this:

@EFragment
public class VolumeDialog extends DialogFragment {
    @ViewById
    SeekBar volumeSeekBar;

    @SeekBarProgressChange
    protected void volumeSeekBar(final int progress, final boolean fromUser) {
    }
}

Then AA generates code like this:

public final class VolumeDialog_
    extends com.company.VolumeDialog
    implements HasViews, OnViewChangedListener
{
    @Override
    public void onViewChanged(HasViews hasViews) {
        volumeSeekBar = ((SeekBar) hasViews.findViewById(com.company.R.id.volumeSeekBar));
        {
            final SeekBar view = ((SeekBar) hasViews.findViewById(com.company.R.id.volumeSeekBar));
            if (view!= null) {
                view.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {


                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                        VolumeDialog_.this.volumeSeekBar(progress, fromUser);
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }

                }
                );
            }
        }
    }       
}

Which then causes lint to display this message:

The id com.company.R.id.volumeSeekBar has already been looked up in this method; possible cut & paste error?

Would it be sensible to keep a list of already looked up (& bound) members and then re-use them during processing stage?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions