Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is it?
Description of the changes in your PR
Use Android's view binding instead of
findViewById()
.I'd appreciate anyone's help. Btw I still need to figure out how to port things using a
ViewPager
over, so don't work on those yet.Why?
This results in cleaner code imho. This also gives us the opportunity to easily fix all memory leaks of the first category in #3517.
How could I port a fragment to use view binding?
onCreateView()
withbinding = Binding.inflate(inflater, container, false);
, whereBinding
should be e.g.FragmentChannelBinding
when the layout is calledfragment_channel.xml
. Of course also addbinding
as a class member, Thenreturn binding.getRoot();
inonCreateView()
.onViewCreated()
. Change all accesses to that class member tobinding.whatever
, wherewhatever
is the camel case version of the ID in the layout.binding
tonull
inonDestroyView()
(notonDestroy()
, you'll probably see a lot of cases in our app where things are done inonDestroy()
while they should be inonDestroyView()
), otherwise you'll cause a memory leak.How could I port an activity to use view binding?
onCreate()
withbinding = Binding.inflate(inflater);
, whereBinding
should be e.g.FragmentChannelBinding
when the layout is calledfragment_channel.xml
. Of course also addbinding
as a class member, Then callsetContentView(binding.getRoot());
inonCreate()
.binding.whatever
, wherewhatever
is the camel case version of the ID in the layout.How could I verify that it works correctly?
In Android's settings, enable Developer settings -> Don't keep activities. Then open the fragment/activity in NewPipe, switch to another app, switch back to NewPipe and verify that it doesn't crash or cause weird behavior. Don't forget to turn off that setting once you're finished with working on this PR, as it's pretty annoying to have that enabled in everyday use.
In case of a fragment, you should also verify that going to another fragment in NewPipe from there and then going back works correctly.
To do
Here should be a list of all fragments/activities that we need to port to use view binding. When you start working on one, please add your name behind the fragment/activity. When you've finished, please check the checkmark.
ChannelFragment
@wb9688SearchFragment
@StypoxMainActivity
@wb9688AboutActivity.java
LicenseFragment.java
DownloadActivity.java
DownloadDialog.java
VideoDetailFragment.java
PlaylistFragment.java
SuggestionListAdapter.java
RelatedVideosFragment.java
BaseListFragment.java
BaseStateFragment.java
MainFragment.java
ChannelMiniInfoItemHolder.java
CommentsInfoItemHolder.java
PlaylistMiniInfoItemHolder.java
CommentsMiniInfoItemHolder.java
StreamInfoItemHolder.java
StreamMiniInfoItemHolder.java
ChannelInfoItemHolder.java
InfoItemDialog.java
BookmarkFragment.java
PlaylistAppendDialog.java
PlaylistCreationDialog.java
StatisticsPlaylistFragment.java
PlaylistItemHolder.java
LocalPlaylistStreamItemHolder.java
LocalStatisticStreamItemHolder.java
LocalPlaylistFragment.java
SubscriptionsImportFragment.java
FeedImportExportItem.kt
BaseLocalListFragment.java
CustomBottomSheetBehavior.java
PlaybackParameterDialog.java
PlayQueueItemHolder.java
ServicePlayerActivity.java
VideoPlayer.java
VideoPlayerImpl.java
ErrorActivity.java
AddTabDialog.java
ChooseTabsFragment.java
SelectKioskFragment.java
SettingsActivity.java
NotificationSettingsFragment.java
SelectChannelFragment.java
SelectPlaylistFragment.java
PeertubeInstanceListFragment.java
PermissionHelper.java
FilePickerActivityHelper.java
StreamItemAdapter.java
FocusAwareCoordinator.java
ReCaptchaActivity.java
RouterActivity.java
Agreement