Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class NouTubeView(context: Context, appContext: AppContext) : ExpoView(context,
private var pageUrl = ""
private var customView: View? = null
private var pullToRefreshEnabled = true
private var pendingClearHistory = false
private lateinit var orientationListener: NouOrientationListener
private val swipeRefreshLayout = SwipeRefreshLayout(context).apply {
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
Expand Down Expand Up @@ -192,6 +193,10 @@ class NouTubeView(context: Context, appContext: AppContext) : ExpoView(context,

override fun onPageFinished(view: WebView, url: String) {
swipeRefreshLayout.isRefreshing = false
if (pendingClearHistory) {
pendingClearHistory = false
view.clearHistory()
}
}

override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
Expand Down Expand Up @@ -329,6 +334,13 @@ class NouTubeView(context: Context, appContext: AppContext) : ExpoView(context,
updateSwipeRefreshEnabled()
}

fun requestGoHome() {
val home = Uri.parse(webView.url ?: "").buildUpon()?.path("/")?.clearQuery()?.fragment(null)?.build()?.toString()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

instead of depending on current url, should we map to either https://m.youtube.com/ or https://music.youtube.com/

if (home.isNullOrBlank()) return
pendingClearHistory = true
webView.loadUrl(home)
}

private fun updateSwipeRefreshEnabled() {
// accidental pulls are too easy while scrubbing the player on /watch and /shorts
val path = Uri.parse(pageUrl).path ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ class NouTubeViewModule : Module() {
if (webView.canGoBack()) {
webView.goBack()
} else {
view.currentActivity?.finish()
val path = Uri.parse(webView.url ?: "").path ?: ""
if (path.isEmpty() || path == "/") {
view.currentActivity?.finish()
} else {
view.requestGoHome()
}
}
}

Expand Down