Skip to content

Refactor: Video detail fragment kotlin conversion #12337

Merged
Stypox merged 18 commits intoTeamNewPipe:refactorfrom
Profpatsch:video-detail-fragment-kotlin-conversion
Jul 16, 2025
Merged

Refactor: Video detail fragment kotlin conversion #12337
Stypox merged 18 commits intoTeamNewPipe:refactorfrom
Profpatsch:video-detail-fragment-kotlin-conversion

Conversation

@Profpatsch
Copy link
Copy Markdown
Contributor

@Profpatsch Profpatsch commented Jun 5, 2025

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

This is a bunch of refactors that convert PlayerHolder and VideoDetailFragment to kotlin.

Please don’t review for “kotlin style”, there’s a lot more commits that are already done that do the fixup of the kotlin style.

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.

Due diligence

@github-actions github-actions Bot added the size/giant PRs with more than 750 changed lines label Jun 5, 2025
@Profpatsch Profpatsch force-pushed the video-detail-fragment-kotlin-conversion branch from 32e2053 to 2427ad1 Compare June 5, 2025 12:39
Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment on lines +1500 to +1255
binding!!.detailThumbnailImageView.setImageDrawable(
AppCompatResources.getDrawable(requireContext(), R.drawable.not_available_monkey)
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
binding!!.detailThumbnailImageView.setImageDrawable(
AppCompatResources.getDrawable(requireContext(), R.drawable.not_available_monkey)
)
binding!!.detailThumbnailImageView.setImageResource(R.drawable.not_available_monkey)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs setImageResource does decoding on the UI thread while setImageDrawable does not, and I can't understand if AppCompatResources.getDrawable itself does the decoding or if it uses a cache or something like that. Not so important anyway, as this will be ported to Jetpack Compose.

Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment on lines +1406 to +1178
private val preDrawListener: ViewTreeObserver.OnPreDrawListener =
object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
val metrics = getResources().getDisplayMetrics()

if (getView() != null) {
val height = (
if (DeviceUtils.isInMultiWindow(activity))
requireView()
else
activity.getWindow().getDecorView()
).getHeight()
setHeightThumbnail(height, metrics)
requireView().getViewTreeObserver().removeOnPreDrawListener(preDrawListener)
}
return false
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OneShotPreDrawListener might be useful here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool! However removeOnPreDrawListener() is called in other places, too, and at the same time it's not always called inside the function body (e.g. if getView() == null), so I don't know if what we have here is precisely one-shot, but in some edge cases it may be 0-shot or multishot.

Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
@Stypox
Copy link
Copy Markdown
Member

Stypox commented Jun 9, 2025

Please don’t review for “kotlin style”, there’s a lot more commits that are already done that do the fixup of the kotlin style.

Ooops I read this only now, I don't know why I did not notice before 😟. I just pushed a commit to fix the kotlin style, feel free to revert it if you have already done it elsewhere.

Comment thread app/src/main/java/org/schabi/newpipe/player/ui/PlayerUiList.kt Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that the changes in this file are not needed, but I'm fine either way

Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.kt Outdated
@Stypox Stypox force-pushed the video-detail-fragment-kotlin-conversion branch from e012d8d to d4bf7ed Compare June 9, 2025 16:05
Comment thread app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserImpl.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserImpl.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserImpl.kt Outdated
Comment thread app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserImpl.kt Outdated
@Stypox Stypox force-pushed the video-detail-fragment-kotlin-conversion branch from f540fe1 to 7558448 Compare June 10, 2025 16:31
Copy link
Copy Markdown
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Profpatsch sorry for making so many changes, I got carried away 😅, and it was probably useless as it's going to get rewritten. Anyway, I reviewed my changes twice just to be sure the same logic was maintained, and I compared the Kotlin code with the Java code and everything seems still correct.

@sonarqubecloud
Copy link
Copy Markdown

Comment thread app/src/main/java/org/schabi/newpipe/player/helper/PlayerHolder.kt
@ShareASmile ShareASmile added code quality Improvements to the codebase to improve the code quality rewrite Issues and PRs related to rewrite labels Jun 12, 2025
@github-project-automation github-project-automation Bot moved this to In Progress in Rewrite Jun 12, 2025
Profpatsch and others added 14 commits July 16, 2025 15:07
Both are only used once, and it’s easier to see what’s going on if
they are just inlined in `onCreate`.
Just the conversion, errors still there for easier rebasing later.
Mostly 1:1, I had to fix a few places where the automatic conversion
did not infer the right kotlin types, and places where it tried to
convert to `double` instead of using `float` like the original.

Everything else is the result of automatic conversion.
mediaSession is now `@NonNull`, so the getter is as well.
@Stypox Stypox force-pushed the video-detail-fragment-kotlin-conversion branch from 1e47816 to 046ea73 Compare July 16, 2025 13:53
@Stypox
Copy link
Copy Markdown
Member

Stypox commented Jul 16, 2025

Conflicts fixed by looking at 006b4c9...refactor, where 006b4c9 is the commit this PR was based on. These are the differences in the three files with conflicts:

image image image

Copy link
Copy Markdown
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Stypox Stypox merged commit da36b8a into TeamNewPipe:refactor Jul 16, 2025
5 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Rewrite Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Improvements to the codebase to improve the code quality rewrite Issues and PRs related to rewrite size/giant PRs with more than 750 changed lines

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants