Skip to content

Commit e57ae66

Browse files
committed
chore: use kotlin syntactic sugar where possible
1 parent b039f39 commit e57ae66

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

app/src/main/java/com/github/libretube/api/poToken/PoTokenGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.schabi.newpipe.extractor.services.youtube.PoTokenResult
1414
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
1515

1616
class PoTokenGenerator : PoTokenProvider {
17-
val TAG = PoTokenGenerator::class.simpleName
17+
private val TAG = PoTokenGenerator::class.simpleName
1818
private val supportsWebView by lazy { runCatching { CookieManager.getInstance() }.isSuccess }
1919

2020
private object WebPoTokenGenLock
@@ -34,7 +34,7 @@ class PoTokenGenerator : PoTokenProvider {
3434
/**
3535
* @param forceRecreate whether to force the recreation of [webPoTokenGenerator], to be used in
3636
* case the current [webPoTokenGenerator] threw an error last time
37-
* [PoTokenGenerator.generatePoToken] was called
37+
* [PoTokenGenerator.getWebClientPoToken] was called
3838
*/
3939
private fun getWebClientPoToken(videoId: String, forceRecreate: Boolean): PoTokenResult {
4040
// just a helper class since Kotlin does not have builtin support for 4-tuples

app/src/main/java/com/github/libretube/api/poToken/PoTokenWebView.kt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ class PoTokenWebView private constructor(
3030

3131
//region Initialization
3232
init {
33-
val webViewSettings = webView.settings
34-
//noinspection SetJavaScriptEnabled we want to use JavaScript!
35-
webViewSettings.javaScriptEnabled = true
36-
webViewSettings.safeBrowsingEnabled = false
37-
webViewSettings.userAgentString = USER_AGENT
38-
webViewSettings.blockNetworkLoads = true // the WebView does not need internet access
33+
webView.settings.apply {
34+
//noinspection SetJavaScriptEnabled we want to use JavaScript!
35+
javaScriptEnabled = true
36+
safeBrowsingEnabled = false
37+
userAgentString = USER_AGENT
38+
blockNetworkLoads = true // the WebView does not need internet access
39+
}
3940

4041
// so that we can run async functions and get back the result
4142
webView.addJavascriptInterface(this, JS_INTERFACE)
@@ -244,17 +245,17 @@ class PoTokenWebView private constructor(
244245
* Releases all [webView] resources.
245246
*/
246247
@MainThread
247-
fun close() {
248-
webView.clearHistory()
248+
fun close() = with(webView) {
249+
clearHistory()
249250
// clears RAM cache and disk cache (globally for all WebViews)
250-
webView.clearCache(true)
251+
clearCache(true)
251252

252253
// ensures that the WebView isn't doing anything when destroying it
253-
webView.loadUrl("about:blank")
254+
loadUrl("about:blank")
254255

255-
webView.onPause()
256-
webView.removeAllViews()
257-
webView.destroy()
256+
onPause()
257+
removeAllViews()
258+
destroy()
258259
}
259260
//endregion
260261

0 commit comments

Comments
 (0)