Skip to content

Commit

Permalink
app: Switched to About libraries, Gradle updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Feb 13, 2022
1 parent 0e43d3a commit 22d398e
Show file tree
Hide file tree
Showing 17 changed files with 438 additions and 347 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
/.idea/deploymentTargetDropDown.xml
.DS_Store
/build
/captures
Expand Down
22 changes: 17 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {
id(Plugins.KOTLIN_ANDROID)
id(Plugins.KAPT)
id(Plugins.DAGGER_HILT)
id(Plugins.OSS_LICENSE)
id(Plugins.ABOUT_LIBRARIES)
}

project.group = App.GROUP
Expand All @@ -43,8 +43,12 @@ android {

defaultConfig {
applicationId = App.APP_ID
versionCode = App.VERSION_CODE
versionName = App.VERSION_NAME

//have to be specified explicitly for FDroid to work
versionCode = 1000000 // 1x major . 2x minor . 2x path . 2x build diff
versionName = "1.0.0"
assert(versionCode == App.VERSION_CODE)
assert(versionName == App.VERSION_NAME)

minSdk = App.MIN_SDK

Expand All @@ -55,7 +59,15 @@ android {
multiDexEnabled = true

}

configurations {
all {
//exclude(group = "org.apache.httpcomponents", module = "httpclient")
exclude(group = "commons-logging", module = "commons-logging")
}
}
lint {
abortOnError = false
}
buildTypes {
getByName("debug") {
applicationIdSuffix = ".debug"
Expand Down Expand Up @@ -130,7 +142,7 @@ dependencies {
implementation(Libs.KOTLINX_DATETIME)
implementation(Libs.SKRAPE_IT)
implementation(Libs.COIL_COMPOSE_COMPLETE)
implementation(Libs.OSS_LICENSE_ACCESSOR)
implementation(Libs.ABOUT_LIBRARIES_CORE)

}

Expand Down
4 changes: 2 additions & 2 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright 2022, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
* Menza 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.
*
* Menza 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 Menza. If not, see <https://www.gnu.org/licenses/>.
*/

package cz.lastaapps.menza.ui.dests.others.license

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.foundation.verticalScroll
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.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.aboutlibraries.entity.License
import cz.lastaapps.menza.R
import org.lighthousegames.logging.logging

@Composable
fun LibraryDetailWrapper(library: Library?, modifier: Modifier = Modifier) {
if (library == null) {
Box(modifier, contentAlignment = Alignment.Center) {
Text(stringResource(R.string.license_none_selected), textAlign = TextAlign.Center)
}
} else {
LibraryDetail(library, modifier)
}
}

@Composable
fun LibraryDetail(library: Library, modifier: Modifier = Modifier) {
SelectionContainer(modifier.verticalScroll(rememberScrollState())) {
Column(Modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {

val titleStyle = MaterialTheme.typography.titleMedium
val bodyStyle = MaterialTheme.typography.bodyMedium

Text(library.name, style = MaterialTheme.typography.headlineSmall)
Text(library.artifactId, style = titleStyle)

if (library.openSource) {
Text(stringResource(R.string.license_detail_opensource_yes), style = bodyStyle)
} else {
Text(stringResource(R.string.license_detail_opensource_no), style = bodyStyle)
}

if (library.developers.isNotEmpty()) {
Column {
Text(stringResource(R.string.license_detail_developer), style = titleStyle)
library.developers.forEach { developer ->
developer.name?.let { Text(it, style = bodyStyle) }
}
}
}

library.website?.let { website ->
Column {
Text(stringResource(R.string.license_detail_link), style = titleStyle)
Uri(website, style = bodyStyle)
}
}

library.organization?.let { organization ->
Column {
Text(stringResource(R.string.license_detail_organization), style = titleStyle)
Text(organization.name, style = bodyStyle)
}
}

library.description?.let { description ->
Column {
Text(stringResource(R.string.license_detail_description), style = titleStyle)
Text(description, style = bodyStyle)
}
}

if (library.licenses.isEmpty()) {
Text(stringResource(R.string.license_detail_no_license))
} else {
library.licenses.forEach { license ->
LicenseDetail(license, titleStyle = titleStyle, bodyStyle = bodyStyle)
}
}
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun LicenseDetail(
license: License,
modifier: Modifier = Modifier,
titleStyle: TextStyle = MaterialTheme.typography.titleMedium,
bodyStyle: TextStyle = MaterialTheme.typography.bodyMedium,
) {
ElevatedCard(
shape = RoundedCornerShape(8.dp),
modifier = modifier,
) {
Column(Modifier.padding(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(license.name, style = titleStyle)

license.year?.takeIf { it.isNotBlank() }?.let { Text(it, style = bodyStyle) }
license.url?.takeIf { it.isNotBlank() }?.let { Uri(it, style = bodyStyle) }

license.licenseContent?.takeIf { it.isNotBlank() }?.let { Text(it, style = bodyStyle) }
}
}
}

@Composable
private fun Uri(
link: String,
modifier: Modifier = Modifier,
style: TextStyle = LocalTextStyle.current,
) {
val handler = LocalUriHandler.current
Text(
link, textDecoration = TextDecoration.Underline,
style = style,
modifier = modifier.clickable {
logging("UriComposable").i { "Opening $link" }
handler.openUri(link)
},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2022, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
* Menza 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.
*
* Menza 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 Menza. If not, see <https://www.gnu.org/licenses/>.
*/

package cz.lastaapps.menza.ui.dests.others.license

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.entity.Library
import cz.lastaapps.menza.R
import org.lighthousegames.logging.logging

@Composable
fun LibraryList(
libraries: List<Library>,
onLibrarySelected: (Library?) -> Unit,
modifier: Modifier = Modifier,
) {
Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
LazyColumn(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {
items(libraries) { library ->
LicenseItem(library, Modifier.clickable { onLibrarySelected(library) })
}
item {
Spacer(modifier = Modifier.height(64.dp))
}
}

AppLicenseButton(Modifier.fillMaxWidth())
}
}

@Composable
private fun AppLicenseButton(modifier: Modifier = Modifier) {
val url = LocalUriHandler.current
OutlinedButton(
onClick = {
logging("AppLicenseButton").i { "Opening app license" }
url.openUri("https://github.com/Lastaapps/cvutbus/LICENSE")
},
modifier = modifier
) {
Text(
text = stringResource(R.string.license_this_app),
style = MaterialTheme.typography.bodyLarge,
textAlign = TextAlign.Center
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2022, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
* Menza 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.
*
* Menza 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 Menza. If not, see <https://www.gnu.org/licenses/>.
*/

package cz.lastaapps.menza.ui.dests.others.license

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.mikepenz.aboutlibraries.entity.Library

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LicenseItem(library: Library, modifier: Modifier = Modifier) {
ElevatedCard(
shape = RoundedCornerShape(8.dp),
modifier = modifier,
) {
Column(Modifier.padding(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Row(Modifier, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
LicenseName(library.name, Modifier.weight(1f))
LicenseVersion(library.artifactVersion)
}
library.developers.forEach { developer ->
LicenseDeveloper(developer.name)
}
library.licenses.map { it.name }.forEach {
LicenseLicense(it)
}
}
}
}

@Composable
private fun LicenseName(name: String, modifier: Modifier = Modifier) {
Text(name, style = MaterialTheme.typography.titleLarge, modifier = modifier)
}

@Composable
private fun LicenseDeveloper(developer: String?, modifier: Modifier = Modifier) {
if (developer != null)
Text(developer, style = MaterialTheme.typography.bodyLarge, modifier = modifier)
}

@Composable
private fun LicenseLicense(license: String, modifier: Modifier = Modifier) {
Text(license, style = MaterialTheme.typography.bodyMedium, modifier = modifier)
}

@Composable
private fun LicenseVersion(version: String?, modifier: Modifier = Modifier) {
if (version != null)
Text(version, style = MaterialTheme.typography.bodyMedium, modifier = modifier)
}


Loading

0 comments on commit 22d398e

Please sign in to comment.