# HG changeset patch # User Da Risk # Date 1681501131 14400 # Node ID 0525cb9d8dcbc86ae4bb48a071eb5e1a8d1bc8f4 # Parent f1eed32c4764facf91a1e72929ba6739e7e9b308 add some kdoc and fix a few warnings diff -r f1eed32c4764 -r 0525cb9d8dcb core/src/main/java/com/geekorum/aboutoss/core/LicenseInfoRepository.kt --- a/core/src/main/java/com/geekorum/aboutoss/core/LicenseInfoRepository.kt Thu Apr 13 20:57:29 2023 -0400 +++ b/core/src/main/java/com/geekorum/aboutoss/core/LicenseInfoRepository.kt Fri Apr 14 15:38:51 2023 -0400 @@ -25,6 +25,9 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.withContext +/** + * Retrieve License information stored in application resources + */ class LicenseInfoRepository( private val appContext: Context, private val mainCoroutineDispatcher: CoroutineDispatcher, diff -r f1eed32c4764 -r 0525cb9d8dcb ui/common/src/main/java/com/geekorum/aboutoss/ui/common/OpenSourceLicensesViewModel.kt --- a/ui/common/src/main/java/com/geekorum/aboutoss/ui/common/OpenSourceLicensesViewModel.kt Thu Apr 13 20:57:29 2023 -0400 +++ b/ui/common/src/main/java/com/geekorum/aboutoss/ui/common/OpenSourceLicensesViewModel.kt Fri Apr 14 15:38:51 2023 -0400 @@ -37,6 +37,9 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn +/** + * Manage opensource license information and allow to display them in an UI + */ class OpenSourceLicensesViewModel constructor( private val licenseInfoRepository: LicenseInfoRepository, private val browserLauncher: BrowserLauncher, diff -r f1eed32c4764 -r 0525cb9d8dcb ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceDependenciesListScreen.kt --- a/ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceDependenciesListScreen.kt Thu Apr 13 20:57:29 2023 -0400 +++ b/ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceDependenciesListScreen.kt Fri Apr 14 15:38:51 2023 -0400 @@ -52,6 +52,13 @@ import com.geekorum.aboutoss.ui.common.OpenSourceLicensesViewModel import com.geekorum.aboutoss.ui.common.R as commonR +/** + * Display the list of dependencies used in the application + * + * @param viewModel the [OpenSourceLicensesViewModel] to use + * @param onDependencyClick lambda to execute on click on one dependency item + * @param onUpClick lambda to execute on click on the up arrow + */ @Composable fun OpenSourceDependenciesListScreen( viewModel: OpenSourceLicensesViewModel, @@ -66,6 +73,13 @@ ) } +/** + * Display the list of dependencies used in the application + * + * @param dependencies the list of dependencies + * @param onDependencyClick lambda to execute on click on one dependency item + * @param onUpClick lambda to execute on click on the up arrow + */ @OptIn(ExperimentalMaterialApi::class) @Composable fun OpenSourceDependenciesListScreen( @@ -80,7 +94,8 @@ } } val topBarElevation by animateDpAsState( - if (hasScrolled) 4.dp else 0.dp + if (hasScrolled) 4.dp else 0.dp, + label = "topBarElevation" ) Scaffold(topBar = { TopAppBar(title = { Text(stringResource(commonR.string.title_oss_licenses)) }, diff -r f1eed32c4764 -r 0525cb9d8dcb ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceLicenseScreen.kt --- a/ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceLicenseScreen.kt Thu Apr 13 20:57:29 2023 -0400 +++ b/ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceLicenseScreen.kt Fri Apr 14 15:38:51 2023 -0400 @@ -58,18 +58,25 @@ import androidx.core.net.toUri import com.geekorum.aboutoss.ui.common.OpenSourceLicensesViewModel +/** + * Display the opensource license of a dependency + * + * @param viewModel the [OpenSourceLicensesViewModel] to use + * @param dependency the dependency + * @param onUpClick lambda to execute on click on the up arrow + */ @Composable fun OpenSourceLicenseScreen( viewModel: OpenSourceLicensesViewModel, dependency: String, - onBackClick: () -> Unit, + onUpClick: () -> Unit, ) { val context = LocalContext.current val license by viewModel.getLicenseDependency(dependency).collectAsState("") OpenSourceLicenseScreen( dependency = dependency, license = license, - onBackClick = onBackClick, + onUpClick = onUpClick, onUrlClick = { viewModel.openLinkInBrowser(context, it) }, @@ -80,12 +87,21 @@ ) } +/** + * Display the opensource license of a dependency + * + * @param dependency the dependency + * @param license the opensource license text + * @param onUpClick lambda to execute on click on the up arrow + * @param onUrlClick lambda to execute on click on a url + * @param onUrlsFound lambda to execute when all urls in the license have been found + */ @OptIn(ExperimentalLayoutApi::class, ExperimentalTextApi::class) @Composable fun OpenSourceLicenseScreen( dependency: String, license: String, - onBackClick: () -> Unit, + onUpClick: () -> Unit, onUrlClick: (String) -> Unit, onUrlsFound: (List) -> Unit, ) { @@ -101,12 +117,13 @@ derivedStateOf { scrollState.value > 0 } } val topBarElevation by animateDpAsState( - if (hasScrolled) 4.dp else 0.dp + if (hasScrolled) 4.dp else 0.dp, + label = "topBarElevation" ) Scaffold(topBar = { TopAppBar(title = { Text(dependency, overflow = TextOverflow.Ellipsis, maxLines = 1) }, navigationIcon = { - IconButton(onClick = onBackClick) { + IconButton(onClick = onUpClick) { Icon( Icons.Default.ArrowBack, contentDescription = null @@ -148,7 +165,7 @@ /** * https://regexr.com/37i6s */ -private val UrlRegexp = """https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)""".toRegex() +private val urlRegexp = """https?://(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)""".toRegex() @OptIn(ExperimentalTextApi::class) @Composable @@ -160,7 +177,7 @@ return remember(text, style) { buildAnnotatedString { var currentIdx = 0 - for (match in UrlRegexp.findAll(text)) { + for (match in urlRegexp.findAll(text)) { if (currentIdx < match.range.first) { append(text.substring(currentIdx, match.range.first)) } diff -r f1eed32c4764 -r 0525cb9d8dcb ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceLicensesActivity.kt --- a/ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceLicensesActivity.kt Thu Apr 13 20:57:29 2023 -0400 +++ b/ui/material2/src/main/java/com/geekorum/aboutoss/ui/material/OpenSourceLicensesActivity.kt Fri Apr 14 15:38:51 2023 -0400 @@ -32,6 +32,13 @@ import com.geekorum.aboutoss.ui.common.BaseOpensourceLicenseActivity import com.geekorum.aboutoss.ui.common.OpenSourceLicensesViewModel +/** + * Activity to display opensource license information + * + * This activity use Material compose to create the UI. + * You can specify the Material theme to use by setting [themeProvider] + * before launching the activity + */ class OpenSourceLicensesActivity : BaseOpensourceLicenseActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -51,6 +58,10 @@ } companion object { + /** + * The composable Theme function to set the theme of the UI in [OpenSourceLicensesActivity] + * Default to base material theme [MaterialTheme] + */ var themeProvider: @Composable (@Composable () -> Unit) -> Unit = { content -> MaterialTheme(content = content) } @@ -79,7 +90,7 @@ OpenSourceLicenseScreen( viewModel = openSourceLicensesViewModel, dependency = dependency, - onBackClick = { + onUpClick = { navController.popBackStack() }, )