Open Source: Release 02 Update project consistency

In this pull request for Hocktoberfest I contributed to a small android app project Travel-Mate. For this issue I needed to update a file to use butter-knife to keep the same coding techniques through out the project.

The Issue:

[ENHANCEMENT] Replace “findViewById” by “@BindView”

This issue is to conform the project so that every file where applicable is using butter-knife @BindView instead of findViewById.

Currently the project is using butter-knife but not every file is currently implementing this and in some cases butter-knife is being called but not used. On top of this there is an inconsistency for how it is being implemente. Some files are creating and using viewHolder classes to store the @BindView variables while others are at the top of Fragment or Activity classes.

Having never used butter-knife in the past it took me awhile to figure everything out, I begun by using the simple implementation (declaring the bind variable at the top of classes)

But after working on a few of the simpler files within the utilities of the application, I noticed the inconsistencies and raised the question for how the project managers would like this to be implemented, while waiting for a reply someone else pushed some work in the same files.

After receiving an answer, I decided to scrap my current work, as it was using the preferred method, and now with a little more experience and understanding moved on to the adapters instead of the activities and fragments.

Still simple but in the beginning had no idea how to approach this. but after reading and working with butter-knife it was a simple fix now that I understood what I needed to do.

The Pull Request:

#780 – ContributorsAdapter replace findViewById with @BindView

This leads to my pull request, I updated the last adapter within the adapters folder to implement butter-knife instead of calling variables through findViewById.

public View getView(int position, View convertView, ViewGroup parent) {
        final Contributor contributor = mContributors.get(position);
        if (convertView == null) {
            final LayoutInflater layoutInflater = LayoutInflater.from(mContext);
            convertView = layoutInflater.inflate(R.layout.contributors_gridview_item, null);
        }

        ViewHolder viewHolder = new ViewHolder(convertView);

        String contributorAvatarUrl = contributor.getAvatarUrl();
        Picasso.with(mContext).load(contributorAvatarUrl).centerCrop()
                .resize(250, 250)
                .into(viewHolder.contributor_avatarImageView);
        final String unameFormatted = "@" + contributor.getUsername();
        viewHolder.contributor_unameTextView.setText(unameFormatted);
        viewHolder.contributor_contributionsTextView.setText(String.valueOf(contributor.getContributions()));
        return convertView;
    }
    class ViewHolder {
        @BindView(R.id.contributor_image)
        CircleImageView contributor_avatarImageView;

        @BindView(R.id.contributor_name)
        TextView contributor_unameTextView;

        @BindView(R.id.contributor_contributions)
        AppCompatTextView contributor_contributionsTextView;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }

Moving forward, I will continue working on this project, and update everything to use butter-knife and ViewHolder classes to hold those bind variables to help standardize the use of butter-knife throughout the project.

Published by marss64

Computer Programming and Analysis student at Seneca College, Toronto. C/C++, Java, Linux, Android, SQL, and Database Administrations.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this: