mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-06-07 05:02:10 +00:00
Hook up URL handling for about page
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -95,6 +95,8 @@ kotlin {
|
||||
implementation(libs.russhwolf.settings)
|
||||
|
||||
implementation(libs.about.libraries.compose.m3)
|
||||
|
||||
implementation(libs.touchlab.kermit)
|
||||
}
|
||||
commonTest.dependencies {
|
||||
implementation(libs.kotlin.test.core)
|
||||
@@ -104,6 +106,7 @@ kotlin {
|
||||
implementation(libs.jetbrains.compose.preview)
|
||||
implementation(libs.androidx.activity)
|
||||
implementation(libs.androidx.preference)
|
||||
implementation(libs.androidx.browser)
|
||||
}
|
||||
val androidDeviceTest by getting {
|
||||
dependencies {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.net.toUri
|
||||
import co.touchlab.kermit.Logger
|
||||
import org.koin.core.annotation.Singleton
|
||||
|
||||
/**
|
||||
* Handles sharing of data and information on Android
|
||||
* @property context Context on Android, injected automatically by Koin
|
||||
*/
|
||||
@Singleton(binds = [ShareHandler::class])
|
||||
class AndroidShareHandler(private val context: Context) : ShareHandler {
|
||||
|
||||
override fun openUrlInBrowser(url: String) {
|
||||
try {
|
||||
CustomTabsIntent.Builder()
|
||||
.build()
|
||||
.also { customIntent ->
|
||||
customIntent.intent.addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
)
|
||||
}
|
||||
.launchUrl(context, url.toUri())
|
||||
} catch (exception: Exception) {
|
||||
Logger.e(messageString = "Failed to share URL", throwable = exception)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Configuration
|
||||
import org.koin.core.annotation.Module
|
||||
|
||||
/**
|
||||
* Module to access various common implementations that are dependent upon platform.
|
||||
* See individual interfaces in this package and their implementations on platform packages
|
||||
* for the declarations included in this module.
|
||||
*/
|
||||
@Module
|
||||
@ComponentScan
|
||||
@Configuration
|
||||
object PlatformModule
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
/**
|
||||
* Helper methods related to sharing of data and information
|
||||
* See individual platform classes for real implementation.
|
||||
*/
|
||||
interface ShareHandler {
|
||||
fun openUrlInBrowser(url: String)
|
||||
}
|
||||
@@ -93,7 +93,10 @@ private val DEFAULT_LINKS = listOf(
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun AboutPage(links: List<Link> = DEFAULT_LINKS) {
|
||||
fun AboutPage(
|
||||
links: List<Link> = DEFAULT_LINKS,
|
||||
onOpenUrl: (url: String) -> Unit = {}
|
||||
) {
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
contentPadding = PaddingValues(spaceNormal),
|
||||
@@ -137,7 +140,8 @@ fun AboutPage(links: List<Link> = DEFAULT_LINKS) {
|
||||
// Links about NewPipe
|
||||
items(items = links, key = { link -> link.url }) { link ->
|
||||
LinkListItem(
|
||||
link = link
|
||||
link = link,
|
||||
onAction = { onOpenUrl(link.url) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,23 +24,30 @@ import androidx.compose.ui.tooling.preview.PreviewWrapper
|
||||
import androidx.compose.ui.util.fastForEachIndexed
|
||||
import kotlinx.coroutines.launch
|
||||
import net.newpipe.app.composable.TopAppBar
|
||||
import net.newpipe.app.platform.ShareHandler
|
||||
import net.newpipe.app.preview.ThemePreviewProvider
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import net.newpipe.app.screen.about.navigation.Page
|
||||
import newpipe.composeapp.generated.resources.Res
|
||||
import newpipe.composeapp.generated.resources.title_activity_about
|
||||
import org.koin.compose.koinInject
|
||||
|
||||
@Composable
|
||||
fun AboutScreen(onNavigateUp: () -> Unit) {
|
||||
fun AboutScreen(
|
||||
onNavigateUp: () -> Unit,
|
||||
shareHandler: ShareHandler = koinInject()
|
||||
) {
|
||||
ScreenContent(
|
||||
onNavigateUp = onNavigateUp
|
||||
onNavigateUp = onNavigateUp,
|
||||
onOpenUrl = { url -> shareHandler.openUrlInBrowser(url) }
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ScreenContent(
|
||||
pages: List<Page> = listOf(Page.ABOUT, Page.LICENSE),
|
||||
onNavigateUp: () -> Unit = {}
|
||||
onNavigateUp: () -> Unit = {},
|
||||
onOpenUrl: (url: String) -> Unit = {}
|
||||
) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -78,7 +85,7 @@ private fun ScreenContent(
|
||||
|
||||
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
|
||||
when (pages[page]) {
|
||||
Page.ABOUT -> AboutPage()
|
||||
Page.ABOUT -> AboutPage(onOpenUrl = onOpenUrl)
|
||||
Page.LICENSE -> LicensePage()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import co.touchlab.kermit.Logger
|
||||
import org.koin.core.annotation.Singleton
|
||||
import platform.Foundation.NSURL
|
||||
import platform.SafariServices.SFSafariViewController
|
||||
import platform.UIKit.UIApplication
|
||||
|
||||
/**
|
||||
* Handles sharing of data and information on iOS
|
||||
*/
|
||||
@Singleton(binds = [ShareHandler::class])
|
||||
class IosShareHandler : ShareHandler {
|
||||
|
||||
override fun openUrlInBrowser(url: String) {
|
||||
val nsUrl = NSURL.URLWithString(url)
|
||||
if (nsUrl == null) {
|
||||
Logger.e(messageString = "Unable to open malformatted URL, bailing out!")
|
||||
} else {
|
||||
val safariVC = SFSafariViewController(uRL = nsUrl)
|
||||
val rootVC = UIApplication.sharedApplication.keyWindow?.rootViewController
|
||||
rootVC?.presentViewController(safariVC, animated = true, completion = null)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.platform
|
||||
|
||||
import co.touchlab.kermit.Logger
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Configuration
|
||||
import org.koin.core.annotation.Module
|
||||
import org.koin.core.annotation.Singleton
|
||||
import java.awt.Desktop
|
||||
import java.net.URI
|
||||
|
||||
/**
|
||||
* Handles sharing of data and information on JVM
|
||||
*/
|
||||
@Singleton(binds = [ShareHandler::class])
|
||||
class JvmShareHandler : ShareHandler {
|
||||
|
||||
override fun openUrlInBrowser(url: String) {
|
||||
when {
|
||||
Desktop.isDesktopSupported() -> Desktop.getDesktop().browse(URI(url))
|
||||
else -> Logger.e(messageString = "Unsupported platform! Cannot open URL in browser")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user