Skip to content

Commit

Permalink
added open source libraries section
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed May 18, 2024
1 parent bd86a95 commit 9f340d3
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ TODO*
composeApp/sekret.properties
composeApp/sekret/src
composeApp/release/*
composeApp/src/commonMain/moko-resources/assets/*

*.so
*.dll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ data object Constants {
const val GITHUB_REPO = "https://github.com/DatL4g/AniFlow"
const val GITHUB_OWNER = "https://github.com/DatL4g"

const val SPDX_LICENSE_BASE = "https://spdx.org/licenses/"

data object AniList {
const val SERVER_URL = "https://graphql.anilist.co/"
const val CACHE_FACTORY = "AniListCacheFactory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ sealed class DialogConfig {

@Serializable
data object Settings : DialogConfig()

@Serializable
data object About : DialogConfig()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import dev.datlag.aniflow.settings.Settings
import dev.datlag.aniflow.settings.model.TitleLanguage
import dev.datlag.aniflow.trace.TraceRepository
import dev.datlag.aniflow.ui.navigation.DialogComponent
import dev.datlag.aniflow.ui.navigation.screen.home.dialog.about.AboutDialogComponent
import dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.SettingsDialogComponent
import dev.datlag.tooling.compose.ioDispatcher
import dev.datlag.tooling.decompose.ioScope
Expand Down Expand Up @@ -113,6 +114,14 @@ class HomeScreenComponent(
componentContext = context,
di = di,
onNekos = onNekos,
onDismiss = dialogNavigation::dismiss,
onAbout = {
dialogNavigation.activate(DialogConfig.About)
}
)
is DialogConfig.About -> AboutDialogComponent(
componentContext = context,
di = di,
onDismiss = dialogNavigation::dismiss
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.about

import dev.datlag.aniflow.ui.navigation.DialogComponent

interface AboutComponent : DialogComponent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.about

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.Libs
import dev.datlag.aniflow.LocalEdgeToEdge
import dev.datlag.aniflow.SharedRes
import dev.datlag.aniflow.common.merge
import dev.datlag.aniflow.ui.navigation.screen.home.dialog.about.component.LibraryCard
import dev.icerock.moko.resources.compose.readTextAsState
import dev.icerock.moko.resources.compose.stringResource

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AboutDialog(component: AboutComponent) {
val sheetState = rememberModalBottomSheetState()
val (insets, bottomPadding) = if (LocalEdgeToEdge.current) {
WindowInsets(
left = 0,
top = 0,
right = 0,
bottom = 0
) to BottomSheetDefaults.windowInsets.only(WindowInsetsSides.Bottom).asPaddingValues()
} else {
BottomSheetDefaults.windowInsets to PaddingValues()
}

ModalBottomSheet(
onDismissRequest = component::dismiss,
windowInsets = insets,
sheetState = sheetState
) {
val libsJson by SharedRes.assets.aboutlibraries_json.readTextAsState()
val libs = remember(libsJson) {
libsJson?.let { json ->
Libs.Builder().withJson(json).build()
}
}
val libsList = remember(libs) {
libs?.libraries.orEmpty()
}

LazyColumn(
modifier = Modifier.fillMaxWidth(),
contentPadding = bottomPadding.merge(PaddingValues(16.dp)),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
item {
Text(
modifier = Modifier.fillParentMaxWidth(),
text = stringResource(SharedRes.strings.open_source_licenses),
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center
)
}
item {
Text(
modifier = Modifier.fillParentMaxWidth().padding(vertical = 16.dp),
text = stringResource(SharedRes.strings.open_source_licenses_text),
textAlign = TextAlign.Center
)
}
items(libsList, key = { it.uniqueId }) {
LibraryCard(it)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.about

import androidx.compose.runtime.Composable
import com.arkivanov.decompose.ComponentContext
import dev.datlag.aniflow.common.onRender
import org.kodein.di.DI

class AboutDialogComponent(
componentContext: ComponentContext,
override val di: DI,
private val onDismiss: () -> Unit
) : AboutComponent, ComponentContext by componentContext {

@Composable
override fun render() {
onRender {
AboutDialog(this)
}
}

override fun dismiss() {
onDismiss()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.about.component

import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.entity.Library
import dev.datlag.aniflow.other.Constants

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun LibraryCard(
library: Library
) {
val uriHandler = LocalUriHandler.current
val website = library.website?.ifBlank { null } ?: library.scm?.url?.ifBlank { null }

ElevatedCard(
onClick = {
if (!website.isNullOrBlank()) {
uriHandler.openUri(website)
}
},
modifier = Modifier.fillMaxWidth(),
enabled = !website.isNullOrBlank(),
) {
Column(
modifier = Modifier.fillMaxWidth().padding(8.dp),
verticalArrangement = Arrangement.spacedBy(2.dp, Alignment.CenterVertically)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(4.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier.weight(1F),
text = library.name,
softWrap = true,
overflow = TextOverflow.Ellipsis,
maxLines = 2,
fontWeight = FontWeight.Medium
)
library.artifactVersion?.let {
Text(
text = it,
style = MaterialTheme.typography.bodySmall
)
}
}
Text(
text = library.organization?.name?.ifBlank { null } ?: library.developers.map { it.name }.joinToString(),
style = MaterialTheme.typography.bodySmall,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
softWrap = true
)
FlowRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically)
) {
library.licenses.forEach { lic ->
val url = lic.url?.ifBlank { null } ?: lic.spdxId?.ifBlank { null }?.let { "${Constants.SPDX_LICENSE_BASE}$it" }

SuggestionChip(
onClick = {
if (!url.isNullOrBlank()) {
uriHandler.openUri(url)
}
},
enabled = !url.isNullOrBlank(),
label = {
Text(text = lic.name)
},
colors = SuggestionChipDefaults.suggestionChipColors(
containerColor = MaterialTheme.colorScheme.tertiary,
labelColor = MaterialTheme.colorScheme.onTertiary
),
border = null
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ interface SettingsComponent : DialogComponent {
fun changeCharLanguage(value: SettingsChar?)
fun logout()
fun nekos()
fun about()
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ fun SettingsScreen(component: SettingsComponent) {
item {
SponsorSection(modifier = Modifier.fillParentMaxWidth())
}
item {
AboutSection(
modifier = Modifier.fillParentMaxWidth(),
onClick = component::about
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class SettingsDialogComponent(
componentContext: ComponentContext,
override val di: DI,
private val onNekos: () -> Unit,
private val onDismiss: () -> Unit
private val onDismiss: () -> Unit,
private val onAbout: () -> Unit
) : SettingsComponent, ComponentContext by componentContext {

private val appSettings by di.instance<Settings.PlatformAppSettings>()
Expand Down Expand Up @@ -77,4 +78,8 @@ class SettingsDialogComponent(
override fun dismiss() {
onDismiss()
}

override fun about() {
onAbout()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dev.datlag.aniflow.ui.navigation.screen.home.dialog.settings.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Lightbulb
import androidx.compose.material.icons.rounded.Savings
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.unit.dp
import dev.datlag.aniflow.SharedRes
import dev.datlag.tooling.compose.onClick
import dev.icerock.moko.resources.compose.painterResource
import dev.icerock.moko.resources.compose.stringResource

@Composable
fun AboutSection(
modifier: Modifier = Modifier,
onClick: () -> Unit
) {
Row(
modifier = modifier
.defaultMinSize(minHeight = ButtonDefaults.MinHeight)
.clip(MaterialTheme.shapes.medium)
.onClick {
onClick()
},
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
Icon(
imageVector = Icons.Rounded.Lightbulb,
contentDescription = null,
)
Text(text = stringResource(SharedRes.strings.open_source_licenses))
}
}
Empty file.
2 changes: 2 additions & 0 deletions composeApp/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@
<string name="list">List</string>
<string name="episode">Episode</string>
<string name="repeat">Repeat</string>
<string name="open_source_licenses">Open-Source Licenses</string>
<string name="open_source_licenses_text">This is a list of (all) libraries used in this project and it\'s licenses</string>
</resources>
28 changes: 15 additions & 13 deletions composeApp/src/commonMain/moko-resources/de-DE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,20 @@
<string name="plus_one">+1</string>
<string name="minus_one">-1</string>
<string name="filter">Filter</string>
<string name="all">All</string>
<string name="oh_noo">Oh noo...</string>
<string name="error_try_again">An error occurred, please try again later QwQ</string>
<string name="matching_anime">Matching Anime</string>
<string name="all">Alle</string>
<string name="oh_noo">Oh nein...</string>
<string name="error_try_again">Ein Fehler ist aufgetreten, bitte versuch es später nochmal QwQ</string>
<string name="matching_anime">Gefundene Anime</string>
<string name="scan">Scan</string>
<string name="schedule">Schedule</string>
<string name="trending">Trending</string>
<string name="popular">Popularität</string>
<string name="upcoming">Upcoming</string>
<string name="discover">Discover</string>
<string name="search">Search</string>
<string name="list">List</string>
<string name="episode">Episode</string>
<string name="repeat">Repeat</string>
<string name="schedule">Sendeplan</string>
<string name="trending">Im Trend</string>
<string name="popular">Beliebt</string>
<string name="upcoming">Bald verfügbar</string>
<string name="discover">Entdecken</string>
<string name="search">Suchen</string>
<string name="list">Liste</string>
<string name="episode">Folge</string>
<string name="repeat">Wiederholung</string>
<string name="open_source_licenses">Open-Source Lizenzen</string>
<string name="open_source_licenses_text">Das ist eine Liste von (allen) Bibliotheken, die in diesem Projekt verwendet werden und deren Lizenzen</string>
</resources>
Loading

0 comments on commit 9f340d3

Please sign in to comment.