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

Replace MathUtils.clamp with Kotlin coerceIn #10224

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

TacoTheDank
Copy link
Member

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

  • Replace 'MathUtils.clamp' with Kotlin 'coerceIn' where possible
  • Also utilize the isGone extension function

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

Copy link
Member

@AudricV AudricV left a comment

Choose a reason for hiding this comment

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

Are you sure about your changes? A part of them has been intentionally reverted with #8737.

@TacoTheDank
Copy link
Member Author

@AudricV That's interesting, I wasn't aware of that.

If the problem is that (playerUi.screenWidth - playerUi.popupLayoutParams.width).toFloat() or (playerUi.screenHeight - playerUi.popupLayoutParams.height).toFloat() can somehow result in a negative number and therefore crash because it is less than the minimum (0f), then I think we can just use Kotlin's coerceAtLeast to make sure numbers can't go below '0f'. coerceAtLeast looks like this:

public fun Float.coerceAtLeast(minimumValue: Float): Float {
    return if (this < minimumValue) minimumValue else this
}

This would ensure we always have a maximum of at least '0f' and avoid a crash.

@TacoTheDank TacoTheDank force-pushed the moreKotlinMath branch 2 times, most recently from 67eae10 to 87ca30f Compare July 18, 2023 01:07
@sonarcloud
Copy link

sonarcloud bot commented Jul 18, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@AudricV AudricV added the codequality Improvements to the codebase to improve the code quality label Jul 22, 2023
@Stypox
Copy link
Member

Stypox commented Aug 6, 2023

ktlint fails

@sonarcloud
Copy link

sonarcloud bot commented Sep 19, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Member

@TobiGr TobiGr left a comment

Choose a reason for hiding this comment

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

LGTM

@TobiGr TobiGr merged commit 6859f73 into TeamNewPipe:dev Sep 20, 2023
6 checks passed
This was referenced Oct 5, 2023
@TacoTheDank TacoTheDank deleted the moreKotlinMath branch October 23, 2023 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codequality Improvements to the codebase to improve the code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants