-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show open source libraries licenses in settings (#256)
- Loading branch information
David Ly
committed
Jun 25, 2023
1 parent
a7c5bea
commit d006a46
Showing
14 changed files
with
191 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
ui/settings/src/main/java/ly/david/ui/settings/components/ClickableItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ly.david.ui.settings.components | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.ChevronRight | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import ly.david.ui.common.preview.DefaultPreviews | ||
import ly.david.ui.common.theme.PreviewTheme | ||
import ly.david.ui.common.theme.TextStyles | ||
|
||
@Composable | ||
internal fun ClickableItem( | ||
text: String, | ||
onClick: () -> Unit = {} | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.clickable { onClick() } | ||
.padding(16.dp), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Text( | ||
text = text, | ||
style = TextStyles.getCardBodyTextStyle() | ||
) | ||
|
||
Spacer(modifier = Modifier.weight(1f)) | ||
|
||
Icon(imageVector = Icons.Default.ChevronRight, contentDescription = null) | ||
} | ||
} | ||
|
||
@DefaultPreviews | ||
@Composable | ||
internal fun PreviewClickableItem() { | ||
PreviewTheme { | ||
Surface { | ||
ClickableItem( | ||
text = "Click me" | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
ui/settings/src/main/java/ly/david/ui/settings/licenses/LicensesScaffold.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package ly.david.ui.settings.licenses | ||
|
||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.stringResource | ||
import com.mikepenz.aboutlibraries.ui.compose.LibrariesContainer | ||
import com.mikepenz.aboutlibraries.ui.compose.LibraryDefaults | ||
import ly.david.ui.common.R | ||
import ly.david.ui.common.topappbar.ScrollableTopAppBar | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun LicensesScaffold( | ||
modifier: Modifier = Modifier, | ||
onBack: () -> Unit = {}, | ||
) { | ||
Scaffold( | ||
modifier = modifier, | ||
topBar = { | ||
ScrollableTopAppBar( | ||
onBack = onBack, | ||
title = stringResource(id = R.string.open_source_licenses), | ||
) | ||
}, | ||
) { innerPadding -> | ||
|
||
LibrariesContainer( | ||
modifier = Modifier | ||
.padding(innerPadding) | ||
.fillMaxSize(), | ||
colors = LibraryDefaults.libraryColors( | ||
backgroundColor = MaterialTheme.colorScheme.background, | ||
contentColor = MaterialTheme.colorScheme.onBackground, | ||
badgeBackgroundColor = MaterialTheme.colorScheme.primary, | ||
badgeContentColor = MaterialTheme.colorScheme.onPrimary | ||
) | ||
) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
ui/settings/src/test/java/ly/david/ui/settings/PaparazziScreenshotTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package ly.david.ui.settings | ||
|
||
import androidx.compose.material3.Surface | ||
import androidx.compose.runtime.Composable | ||
import app.cash.paparazzi.DeviceConfig | ||
import app.cash.paparazzi.Paparazzi | ||
import com.android.ide.common.rendering.api.SessionParams | ||
import com.android.resources.NightMode | ||
import com.google.testing.junit.testparameterinjector.TestParameter | ||
import com.google.testing.junit.testparameterinjector.TestParameterInjector | ||
import ly.david.ui.common.theme.PreviewTheme | ||
import org.junit.Rule | ||
import org.junit.runner.RunWith | ||
|
||
private const val PAPARAZZI_THEME = "android:Theme.Material.Light.NoActionBar" | ||
|
||
/** | ||
* Common setup for running screenshot tests on light and dark mode. | ||
*/ | ||
@RunWith(TestParameterInjector::class) | ||
abstract class PaparazziScreenshotTest( | ||
private val isFullScreen: Boolean = false | ||
) { | ||
|
||
@TestParameter | ||
private lateinit var nightMode: NightMode | ||
|
||
// Note we cannot override junit Rule | ||
@get:Rule | ||
val paparazzi: Paparazzi by lazy { | ||
Paparazzi( | ||
deviceConfig = DeviceConfig.PIXEL_5.copy(nightMode = nightMode), | ||
theme = PAPARAZZI_THEME, | ||
renderingMode = if (isFullScreen) { | ||
SessionParams.RenderingMode.NORMAL | ||
} else { | ||
SessionParams.RenderingMode.SHRINK | ||
}, | ||
showSystemUi = false | ||
) | ||
} | ||
|
||
protected fun snapshot(content: @Composable () -> Unit) { | ||
paparazzi.snapshot { | ||
PreviewTheme { | ||
Surface { | ||
content() | ||
} | ||
} | ||
} | ||
} | ||
} |