# HG changeset patch # User Da Risk # Date 1745353578 14400 # Node ID a8cfcfe9a6ed172e81b79bea9e378725fef3d87b # Parent 4ca4a17fe9f7d06b443082ea09f47c5e7a64f91e make :ui:common multiplatform diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed gradle/libs.versions.toml --- a/gradle/libs.versions.toml Tue Apr 22 14:35:57 2025 -0400 +++ b/gradle/libs.versions.toml Tue Apr 22 16:26:18 2025 -0400 @@ -32,7 +32,8 @@ androidx-navigation = "2.8.9" androidx-compose-bom = "2025.04.00" androidx-lifecycle = "2.8.7" -geekdroid = "geekttrss-1.6.2" +org-jetbrains-androidx-lifecycle = "2.8.4" +geekdroid = "geekttrss-1.6.7" [libraries] @@ -47,6 +48,7 @@ androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref="androidx-lifecycle" } androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" } +org-jetbrains-androidx-lifecycle-viewmodel = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel", version.ref = "org-jetbrains-androidx-lifecycle" } androidx-activity = { module = "androidx.activity:activity-ktx", version.ref="androidx-activity" } androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref="androidx-activity" } diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/build.gradle.kts --- a/ui/common/build.gradle.kts Tue Apr 22 14:35:57 2025 -0400 +++ b/ui/common/build.gradle.kts Tue Apr 22 16:26:18 2025 -0400 @@ -19,9 +19,11 @@ * You should have received a copy of the GNU General Public License * along with AboutOss. If not, see . */ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + plugins { id("com.android.library") - kotlin("android") + kotlin("multiplatform") id("com.geekorum.build.source-license-checker") `maven-publish` } @@ -29,6 +31,39 @@ group = "com.geekorum.aboutoss" version = "0.1.0" +kotlin { + androidTarget { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_17) + } + } + + jvm("desktop") + + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64(), + ).forEach { iosTarget -> + iosTarget.binaries.framework { + baseName = "aboutoss-core" + isStatic = true + } + } + + sourceSets { + commonMain.dependencies { + implementation(project(":core")) + api(libs.org.jetbrains.androidx.lifecycle.viewmodel) + } + + androidMain.dependencies { + api(libs.androidx.activity) + api(libs.geekdroid) + } + } +} + android { namespace = "com.geekorum.aboutoss.ui.common" compileSdk = 35 @@ -55,11 +90,8 @@ } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = "1.8" + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } publishing { @@ -71,15 +103,6 @@ } dependencies { - implementation(project(":core")) - api(libs.appcompat) - implementation(libs.androidx.lifecycle.viewmodel) - implementation(libs.androidx.activity) - api(libs.geekdroid) { - //TODO get rid of dagger platform in geekdroid - exclude("com.google.dagger", "dagger-platform") - } - testImplementation(libs.junit) androidTestImplementation(libs.androidx.test.ext.junit) androidTestImplementation(libs.espresso.core) diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/androidMain/kotlin/com/geekorum/aboutoss/ui/common/AndroidBrowserLauncher.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/src/androidMain/kotlin/com/geekorum/aboutoss/ui/common/AndroidBrowserLauncher.kt Tue Apr 22 16:26:18 2025 -0400 @@ -0,0 +1,48 @@ +/* + * AboutOss is an utility library to retrieve and display + * opensource licenses in Android applications. + * + * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. + * + * This file is part of AboutOss. + * + * AboutOss is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AboutOss is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AboutOss. If not, see . + */ +package com.geekorum.aboutoss.ui.common + +import android.content.Context +import androidx.core.net.toUri +import com.geekorum.geekdroid.network.BrowserLauncher as GeekdroidBrowserLauncher + +class AndroidBrowserLauncher( + private val context: Context, + private val delegate: GeekdroidBrowserLauncher +) : BrowserLauncher { + override fun warmUp() { + delegate.warmUp(null) + } + + override fun launchUrl(link: String) { + delegate.launchUrl(context, link.toUri(), null as GeekdroidBrowserLauncher.LaunchCustomizer?) + } + + override fun mayLaunchUrl(vararg uris: String) { + val asUris = uris.map { it.toUri() }.toTypedArray() + delegate.mayLaunchUrl(*asUris) + } + + override fun shutdown() { + delegate.shutdown() + } +} \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/androidMain/kotlin/com/geekorum/aboutoss/ui/common/BaseOpensourceLicenseActivity.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/src/androidMain/kotlin/com/geekorum/aboutoss/ui/common/BaseOpensourceLicenseActivity.kt Tue Apr 22 16:26:18 2025 -0400 @@ -0,0 +1,29 @@ +/* + * AboutOss is an utility library to retrieve and display + * opensource licenses in Android applications. + * + * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. + * + * This file is part of AboutOss. + * + * AboutOss is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AboutOss is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AboutOss. If not, see . + */ +package com.geekorum.aboutoss.ui.common + +import androidx.activity.ComponentActivity + +abstract class BaseOpensourceLicenseActivity : ComponentActivity() { + protected abstract val viewModel: OpenSourceLicensesViewModel + +} \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/androidMain/kotlin/com/geekorum/aboutoss/ui/common/OpenSourceLicensesViewModel.android.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/src/androidMain/kotlin/com/geekorum/aboutoss/ui/common/OpenSourceLicensesViewModel.android.kt Tue Apr 22 16:26:18 2025 -0400 @@ -0,0 +1,41 @@ +/* + * AboutOss is an utility library to retrieve and display + * opensource licenses in Android applications. + * + * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. + * + * This file is part of AboutOss. + * + * AboutOss is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AboutOss is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AboutOss. If not, see . + */ +package com.geekorum.aboutoss.ui.common + +import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY +import androidx.lifecycle.viewmodel.initializer +import androidx.lifecycle.viewmodel.viewModelFactory +import com.geekorum.aboutoss.core.LicenseInfoRepository +import com.geekorum.geekdroid.network.BrowserLauncher as GeekdroidBrowserLauncher + + +fun OpenSourceLicensesViewModel.Companion.Factory(licenseInfoRepository: LicenseInfoRepository) = viewModelFactory { + initializer { + val application = this[APPLICATION_KEY]!! + val geekdroidBrowserLauncher = GeekdroidBrowserLauncher(application, application.packageManager) + val browserLauncher = AndroidBrowserLauncher(application, geekdroidBrowserLauncher) + OpenSourceLicensesViewModel( + licenseInfoRepository, + browserLauncher + ) + } +} \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/androidMain/res/values/strings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/src/androidMain/res/values/strings.xml Tue Apr 22 16:26:18 2025 -0400 @@ -0,0 +1,27 @@ + + + + Opensource Licenses + \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/commonMain/kotlin/BrowserLauncher.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/src/commonMain/kotlin/BrowserLauncher.kt Tue Apr 22 16:26:18 2025 -0400 @@ -0,0 +1,36 @@ +/* + * AboutOss is an utility library to retrieve and display + * opensource licenses in Android applications. + * + * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. + * + * This file is part of AboutOss. + * + * AboutOss is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AboutOss is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AboutOss. If not, see . + */ +package com.geekorum.aboutoss.ui.common + + +/** + * Interface to be able to launch a browser to display a link + */ +interface BrowserLauncher { + fun warmUp() + + fun launchUrl(link: String) + + fun mayLaunchUrl(vararg uris: String) + + fun shutdown() +} \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/commonMain/kotlin/OpenSourceLicensesViewModel.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/src/commonMain/kotlin/OpenSourceLicensesViewModel.kt Tue Apr 22 16:26:18 2025 -0400 @@ -0,0 +1,66 @@ +/* + * AboutOss is an utility library to retrieve and display + * opensource licenses in Android applications. + * + * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. + * + * This file is part of AboutOss. + * + * AboutOss is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AboutOss is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AboutOss. If not, see . + */ +package com.geekorum.aboutoss.ui.common + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.geekorum.aboutoss.core.LicenseInfoRepository +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn + +/** + * Manage opensource license information and allow to display them in an UI + */ +class OpenSourceLicensesViewModel( + private val licenseInfoRepository: LicenseInfoRepository, + private val browserLauncher: BrowserLauncher, +) : ViewModel() { + init { + browserLauncher.warmUp() + } + + private val licensesInfo = flow { + emit(licenseInfoRepository.getLicensesInfo()) + }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyMap()) + + val dependenciesList = licensesInfo.map { licensesInfo -> + licensesInfo.keys.sortedBy { it.lowercase() } + } + + fun getLicenseDependency(dependency: String) = flow { + emit(licenseInfoRepository.getLicenseFor(dependency)) + } + + fun openLinkInBrowser(link: String) { + browserLauncher.launchUrl(link) + } + + fun mayLaunchUrl(vararg uris: String) = browserLauncher.mayLaunchUrl(*uris) + + override fun onCleared() { + browserLauncher.shutdown() + } + + companion object +} \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/iosMain/kotlin/IosBrowserLauncher.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/common/src/iosMain/kotlin/IosBrowserLauncher.kt Tue Apr 22 16:26:18 2025 -0400 @@ -0,0 +1,42 @@ +/* + * AboutOss is an utility library to retrieve and display + * opensource licenses in Android applications. + * + * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. + * + * This file is part of AboutOss. + * + * AboutOss is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AboutOss is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AboutOss. If not, see . + */ +package com.geekorum.aboutoss.ui.common + +import platform.Foundation.NSURL.Companion.URLWithString +import platform.UIKit.UIApplication + + +class IosBrowserLauncher : BrowserLauncher { + override fun warmUp() {} + + override fun launchUrl(link: String) { + UIApplication.sharedApplication.openURL( + URLWithString(link)!!, + options = emptyMap(), + completionHandler = {} + ) + } + + override fun mayLaunchUrl(vararg uris: String) {} + + override fun shutdown() {} +} \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/main/java/com/geekorum/aboutoss/ui/common/BaseOpensourceLicenseActivity.kt --- a/ui/common/src/main/java/com/geekorum/aboutoss/ui/common/BaseOpensourceLicenseActivity.kt Tue Apr 22 14:35:57 2025 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* - * AboutOss is an utility library to retrieve and display - * opensource licenses in Android applications. - * - * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. - * - * This file is part of AboutOss. - * - * AboutOss is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * AboutOss is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with AboutOss. If not, see . - */ -package com.geekorum.aboutoss.ui.common - -import androidx.activity.viewModels -import androidx.appcompat.app.AppCompatActivity - -abstract class BaseOpensourceLicenseActivity : AppCompatActivity() { - protected open val viewModel: OpenSourceLicensesViewModel by viewModels( - factoryProducer = { - OpenSourceLicensesViewModel.Factory - } - ) -} \ No newline at end of file diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed 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 Tue Apr 22 14:35:57 2025 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * AboutOss is an utility library to retrieve and display - * opensource licenses in Android applications. - * - * Copyright (C) 2023-2025 by Frederic-Charles Barthelery. - * - * This file is part of AboutOss. - * - * AboutOss is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * AboutOss is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with AboutOss. If not, see . - */ -package com.geekorum.aboutoss.ui.common - -import android.content.Context -import android.net.Uri -import androidx.core.net.toUri -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY -import androidx.lifecycle.viewModelScope -import androidx.lifecycle.viewmodel.initializer -import androidx.lifecycle.viewmodel.viewModelFactory -import com.geekorum.aboutoss.core.LicenseInfoRepository -import com.geekorum.aboutoss.core.gms.GmsLicenseInfoRepository -import com.geekorum.geekdroid.network.BrowserLauncher -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.flow -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, -) : ViewModel() { - init { - browserLauncher.warmUp(null) - } - - private val licensesInfo = flow { - emit(licenseInfoRepository.getLicensesInfo()) - }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyMap()) - - val dependenciesList = licensesInfo.map { licensesInfo -> - licensesInfo.keys.sortedBy { it.lowercase() } - } - - fun getLicenseDependency(dependency: String) = flow { - emit(licenseInfoRepository.getLicenseFor(dependency)) - } - - fun openLinkInBrowser(context: Context, link: String) { - browserLauncher.launchUrl(context, link.toUri(), null as BrowserLauncher.LaunchCustomizer?) - } - - fun mayLaunchUrl(vararg uris: Uri) = browserLauncher.mayLaunchUrl(*uris) - - override fun onCleared() { - browserLauncher.shutdown() - } - - companion object { - val Factory = viewModelFactory { - initializer { - val application = this[APPLICATION_KEY]!! - val licenseInfoRepository = GmsLicenseInfoRepository( - appContext = application, - mainCoroutineDispatcher = Dispatchers.Main, - ioCoroutineDispatcher = Dispatchers.IO - ) - val browserLauncher = BrowserLauncher(application, application.packageManager) - OpenSourceLicensesViewModel( - licenseInfoRepository, - browserLauncher - ) - } - } - } -} diff -r 4ca4a17fe9f7 -r a8cfcfe9a6ed ui/common/src/main/res/values/strings.xml --- a/ui/common/src/main/res/values/strings.xml Tue Apr 22 14:35:57 2025 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ - - - - Opensource Licenses - \ No newline at end of file