Skip to content

Commit

Permalink
Add OSS Licenses viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
fibelatti committed Nov 18, 2023
1 parent fa7ed46 commit 84fa8dc
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
alias(libs.plugins.room)
id("com.google.android.gms.oss-licenses-plugin")
}

val jacocoEnabled: Boolean by project
Expand Down Expand Up @@ -208,6 +209,8 @@ dependencies {

implementation(libs.jsoup)

implementation(libs.oss.licenses.library)

debugImplementation(libs.leakcanary)

// Test
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
</intent-filter>
</activity>

<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"
android:theme="@style/AppTheme.WithActionBar" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
android:theme="@style/AppTheme.WithActionBar" />

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.fibelatti.core.extension.shareText
import com.fibelatti.pinboard.R
import com.fibelatti.pinboard.core.AppConfig
import com.fibelatti.pinboard.core.android.ComposeBottomSheetDialog
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity

object NavigationMenu {

Expand All @@ -30,6 +31,9 @@ object NavigationMenu {

activity.startActivity(intent)
},
onLicensesClicked = {
activity.startActivity(Intent(activity, OssLicensesMenuActivity::class.java))
},
onOptionSelected = { dismiss() },
)
}.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fibelatti.pinboard.features.navigation

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -21,6 +22,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
Expand Down Expand Up @@ -52,6 +54,7 @@ fun NavigationMenuScreen(
authViewModel: AuthViewModel = hiltViewModel(),
onShareClicked: () -> Unit,
onRateClicked: () -> Unit,
onLicensesClicked: () -> Unit,
onOptionSelected: () -> Unit,
) {
val appMode by appStateViewModel.appMode.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -114,6 +117,10 @@ fun NavigationMenuScreen(
onRateClicked()
onOptionSelected()
},
onLicensesClicked = {
onLicensesClicked()
onOptionSelected()
},
)
}

Expand All @@ -134,6 +141,7 @@ private fun NavigationMenuScreen(
onLogoutClicked: () -> Unit,
onShareClicked: () -> Unit,
onRateClicked: () -> Unit,
onLicensesClicked: () -> Unit,
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -242,21 +250,43 @@ private fun NavigationMenuScreen(
textStyle = MaterialTheme.typography.bodySmall,
)

AppVersionDetails(
onClick = onLicensesClicked,
modifier = Modifier.padding(start = 16.dp, top = 32.dp, end = 16.dp),
)
}
}

@Composable
private fun AppVersionDetails(
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier
.fillMaxWidth()
.clickable(onClick = onClick, role = Role.Button),
) {
Text(
text = stringResource(id = R.string.about_developer),
modifier = Modifier.padding(start = 16.dp, top = 8.dp, end = 16.dp),
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontFamily = FontFamily(Font(R.font.jetbrainsmono)),
style = MaterialTheme.typography.bodySmall,
)

Text(
text = stringResource(R.string.about_version, BuildConfig.VERSION_NAME),
modifier = Modifier.padding(horizontal = 16.dp),
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontFamily = FontFamily(Font(R.font.jetbrainsmono)),
style = MaterialTheme.typography.bodySmall,
)

Text(
text = stringResource(id = R.string.about_oss_licenses),
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontFamily = FontFamily(Font(R.font.jetbrainsmono)),
style = MaterialTheme.typography.labelSmall,
)
}
}

Expand Down Expand Up @@ -312,6 +342,7 @@ private fun NavigationMenuScreenPreview() {
onLogoutClicked = {},
onShareClicked = {},
onRateClicked = {},
onLicensesClicked = {},
)
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<string name="about_rate">Rate Pinkt on Google Play</string>
<string name="about_developer">Developed with ❤ by Filipe Belatti</string>
<string name="about_version">App version: %s</string>
<string name="about_oss_licenses">OSS Licenses</string>

<!-- Share -->
<string name="share_to_pinkt">Save to pinboard</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<item name="materialAlertDialogTheme">@style/AppTheme.MaterialDialog</item>
</style>

<style name="AppTheme.WithActionBar" parent="Theme.Material3.DayNight">
<item name="colorPrimary">#0051E1</item>
</style>

<style name="AppTheme.Overlay" parent="ThemeOverlay.Material3.DynamicColors.DayNight">
<item name="android:colorBackground">@color/color_background</item>
</style>
Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ buildscript {

val jacocoEnabled: String? by project
extra["jacocoEnabled"] = jacocoEnabled?.toBoolean() ?: false

dependencies {
classpath(libs.oss.licenses.plugin)
}
}

allprojects {
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit
converter-moshi = { module = "com.squareup.retrofit2:converter-moshi", version.ref = "retrofit" }

jsoup = { module = "org.jsoup:jsoup", version = "1.16.2" }

oss-licenses-plugin = { module = "com.google.android.gms:oss-licenses-plugin", version = "0.10.6" }
oss-licenses-library = { module = "com.google.android.gms:play-services-oss-licenses", version = "17.0.1" }

leakcanary = { module = "com.squareup.leakcanary:leakcanary-android", version = "2.12" }

junit = { module = "junit:junit", version = "4.13.2" }
Expand Down

0 comments on commit 84fa8dc

Please sign in to comment.