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

Start using Binding instead of using findViewByID #3796

Open
9 tasks
nangarita-coder opened this issue Nov 26, 2022 · 6 comments
Open
9 tasks

Start using Binding instead of using findViewByID #3796

nangarita-coder opened this issue Nov 26, 2022 · 6 comments

Comments

@nangarita-coder
Copy link

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
@abelgardep
Copy link
Contributor

Hi @nangarita-coder!

First of all, thanks for opening an issue!

Currently, we are working hard to refactor a lot of classes in the app and release a 3.0 version. During this process, we have already moved some classes from findViewById to ViewBinding. For example, the LoginActivity is already using ViewBinding

We will take a deeper look after releasing 3.0 to keep replacing the findViewById with ViewBinding 👍

@dev-divyansh
Copy link
Contributor

Hey , i would like to work on this ;;

@abelgardep
Copy link
Contributor

Hey, @dev-divyansh Go ahead!

We already use ViewBinding for some screens but there are still several uses of findViewById, so take it easy!

@dev-divyansh
Copy link
Contributor

Hey @abelgardep I am beginner in OpenSource would need your guidance ;
Can I open a PR if i refract all the changes in minimum of one Activity ?

@abelgardep
Copy link
Contributor

Sure @dev-divyansh, here you have a little guide on how to contribute

You can send a PR with the changes you propose. If it's your first time, this activity could be a good candidate to start using binding instead of findViewById.

That activity is the one it is shown when we try to move/copy files from one folder to another one.

There are some servers available for testing:
demo.owncloud.com u:demo p:demo

If u need something else, just let me know!

@dev-divyansh
Copy link
Contributor

@abelgardep hey , can you review my PR

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

No branches or pull requests

3 participants