owncloud / owncloud/android

Start using Binding instead of using findViewByID

Open
#3,796 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Technical
Dominant language
Kotlin
Stars
4.2k
Forks
3.1k
Avg merge
1d 12h
Merged PRs (30d)
7

Description

The findViewById method is often used in the application to retrieve a view from a view hierarchy based on an identifier but the problem is that this seemingly harmless method can, in fact, cause performance issues in your Android application if used carelessly, as it is a very demanding method in terms of resource usage.

To solve this problem it is possible to make use of view binding, this is a feature that allows you to more easily write code that interacts with views. Once view linking is enabled in a module, a link class is generated for each XML layout file present in that module. An instance of a link class contains direct references to all views that have an ID in the corresponding layout.

An example of a method in which many are made is the getView method located in the following path owncloudApp/src/main/java/com/owncloud/android/ui/adapter/AccountListAdapter.java
in this method calls are made to the findViewById method 7 times which is evidenced in the code snippet below.

image_2022-11-25_222958101

TASKS
  • Investigate the different view binding libraries to find the implementation that best suits the project architecture. ex https://developer.android.com/topic/libraries/view-binding
  • Create branch name binding Transition
  • Development tasks
    • Identify classes where there is excessive use of the findViewByID method.
    • Implement view binding on the files identified in the previous step
  • Code review and apply changes requested
  • Design test plan
  • QA
  • Merge branch feature/feature_name into master

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading owncloudApp/src/main/java/com/owncloud/android/ui/adapter/AccountListAdapter.java, especially getView and its seven findViewById calls. Then investigate the project's architecture and candidate view-binding libraries, identify the affected classes, and define completion around migrating those classes with an agreed test and QA plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.