Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add view that lists all used libraries and their licenses #381

Merged
merged 4 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "com.github.triplet.play" version "3.6.0"
id "com.mikepenz.aboutlibraries.plugin"
}
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
Expand Down Expand Up @@ -99,6 +100,12 @@ android {
}
}

// https://github.com/mikepenz/AboutLibraries/blob/develop/plugin-build/plugin/src/main/kotlin/com/mikepenz/aboutlibraries/plugin/AboutLibrariesExtension.kt
aboutLibraries {
prettyPrint = true
configPath = "config/aboutLibraries"
}

dependencies {
// Room
implementation fileTree(include: ["*.jar"], dir: "libs")
Expand All @@ -107,23 +114,23 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.test:core-ktx:1.5.0"

def room_version = "2.4.3"
def roomVersion = "2.4.3"

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-runtime:$roomVersion"
kapt "androidx.room:room-compiler:$roomVersion"

// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.room:room-ktx:$roomVersion"

// optional - RxJava support for Room
implementation "androidx.room:room-rxjava2:$room_version"
implementation "androidx.room:room-rxjava2:$roomVersion"

// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
implementation "androidx.room:room-guava:$roomVersion"

implementation "net.sf.kxml:kxml2:2.3.0"
implementation "com.caverock:androidsvg:1.4"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"

// Tests
Expand All @@ -143,9 +150,9 @@ dependencies {
*
* https://github.com/noties/Markwon
*/
def markwon_version = "4.6.2"
implementation "io.noties.markwon:core:$markwon_version"
implementation "io.noties.markwon:linkify:$markwon_version"
def markwonVersion = "4.6.2"
implementation "io.noties.markwon:core:$markwonVersion"
implementation "io.noties.markwon:linkify:$markwonVersion"

/*
* CSV library for tour book export
Expand All @@ -156,6 +163,13 @@ dependencies {

// For introspection
implementation "org.jetbrains.kotlin:kotlin-reflect:1.6.0"

/*
* Listing all used libraries
*
* https://github.com/mikepenz/AboutLibraries
*/
implementation "com.mikepenz:aboutlibraries-core:${aboutlibrariesVersion}"
}
repositories {
mavenCentral()
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
android:parentActivityName=".AboutActivity"
android:theme="@style/AppTheme.ActionBar">
</activity>
<activity
android:name=".AboutLibrariesActivity"
android:exported="false"
android:parentActivityName=".AboutActivity"
android:theme="@style/AppTheme.ActionBar">
</activity>

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
14 changes: 10 additions & 4 deletions app/src/main/java/com/yacgroup/yacguide/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class AboutActivity : BaseNavigationActivity() {
_createEntry(getString(R.string.privacy_policy), callback = { _showPrivacyPolicy() })
_createEntry(getString(R.string.source_code_and_support), getString(R.string.github_url))
_createEntry(getString(R.string.license), getString(R.string.license_url))
_createEntry(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it make sense to migrate this view to RecyclerView using BaseViewItemAdapter, too? If yes, you may create a ticket for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a look. Thanks for the hint.

getString(R.string.software_and_licenses),
callback = { _showLibraries()}
)
_createEntry(
getString(R.string.whats_new),
WhatsNewInfo(this).getReleaseNotesUrl()
Expand All @@ -57,17 +61,15 @@ class AboutActivity : BaseNavigationActivity() {
description: String = "",
callback: (() -> Unit)? = null) {
layoutInflater.inflate(R.layout.about_entry, null).let {
val contentAbout = findViewById<LinearLayout>(R.id.aboutContent)
it.setOnClickListener { callback?.invoke() ?: _activityUtils.openUrl(description) }
it.findViewById<TextView>(R.id.aboutEntryTitle).text = title
it.findViewById<TextView>(R.id.aboutEntryDescription).text = description
contentAbout.addView(it)
findViewById<LinearLayout>(R.id.aboutContent).addView(it)
}
}

private fun _showPrivacyPolicy() {
val intent = Intent(this, PrivacyPolicyActivity::class.java)
startActivity(intent)
startActivity(Intent(this, PrivacyPolicyActivity::class.java))
}

private fun _selectContactConcern() {
Expand All @@ -82,4 +84,8 @@ class AboutActivity : BaseNavigationActivity() {
setNegativeButton()
}.show()
}

private fun _showLibraries() {
startActivity(Intent(this, AboutLibrariesActivity::class.java))
}
}
74 changes: 74 additions & 0 deletions app/src/main/java/com/yacgroup/yacguide/AboutLibrariesActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2023 Christian Sommer
*
* This program 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.
*
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/

/*
* NOTE:
* The library can automatically generate a view.
* However, it uses material design elements which makes things a bit inconsistent within
* this app. As soon as the app is migrated to material design, this and related code
* may become obsolete.
*/

package com.yacgroup.yacguide

import android.os.Bundle
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import com.yacgroup.yacguide.utils.ActivityUtils

class AboutLibrariesActivity : AppCompatActivity() {

private lateinit var _activityUtils: ActivityUtils

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
_activityUtils = ActivityUtils(this)
setTitle(R.string.software_and_licenses)
setContentView(R.layout.activity_about_libraries)
_displayContent()
}

private fun _displayContent() {
// The resource JSON file is automatically generated
// by the Gradle plugin com.mikepenz.aboutlibraries.plugin
val jsonStr = resources.openRawResource(R.raw.aboutlibraries)
.bufferedReader().use { it.readText() }
val libs = Libs.Builder()
.withJson(jsonStr)
.build()
libs.libraries.sortedBy { it.uniqueId }.forEach {
_createEntry(it)
}
}

private fun _createEntry(lib: Library) {
layoutInflater.inflate(R.layout.about_libraries_entry, null).let {
it.setOnClickListener { _activityUtils.openUrl(lib.website.orEmpty()) }
it.findViewById<TextView>(R.id.aboutLibrariesName).text = lib.uniqueId
it.findViewById<TextView>(R.id.aboutLibrariesVersion).text = lib.artifactVersion
val licenses = lib.licenses.joinToString(
separator = ", ",
transform = { license -> license.name }
)
it.findViewById<TextView>(R.id.aboutLibrariesLicenses).text = licenses
findViewById<LinearLayout>(R.id.aboutLibrariesContent).addView(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PrivacyPolicyActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setTitle(R.string.privacy_policy)
setContentView(R.layout.activity_privacy_policy)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
_displayContent()
}

Expand All @@ -52,4 +51,4 @@ class PrivacyPolicyActivity : AppCompatActivity() {
val privacyTextView = findViewById<TextView>(R.id.privacyPolicyTextView)
markwon.setMarkdown(privacyTextView, privacyStr)
}
}
}
10 changes: 4 additions & 6 deletions app/src/main/res/layout/about_entry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="20dp"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:textAlignment="textStart"
android:textSize="16sp"
android:textColor="?android:textColorPrimary"/>
Expand All @@ -37,16 +37,14 @@
android:id="@+id/aboutEntryDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:textAlignment="textStart"
android:textSize="14sp"
android:textColor="?android:textColorSecondary"/>

<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:background="?android:attr/listDivider"/>
style="@style/ThinDivider"/>

</LinearLayout>
</LinearLayout>
69 changes: 69 additions & 0 deletions app/src/main/res/layout/about_libraries_entry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2023 Christian Sommer

This program 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.

This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
-->

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:foreground="?android:attr/selectableItemBackground">

<TextView
android:id="@+id/aboutLibrariesName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:textAlignment="textStart"
android:textSize="16sp"
android:textColor="?android:textColorPrimary"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
android:id="@+id/aboutLibrariesLicenses"
android:layout_width="0dp"
android:layout_weight="0.8"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:textAlignment="textStart"
android:textSize="14sp"
android:textColor="?android:textColorSecondary"/>

<TextView
android:id="@+id/aboutLibrariesVersion"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:textAlignment="textEnd"
android:textSize="14sp"
android:textColor="?android:textColorSecondary"/>
</LinearLayout>

<View
chrgernoe marked this conversation as resolved.
Show resolved Hide resolved
android:id="@+id/divider"
android:layout_marginTop="10dp"
style="@style/ThinDivider"/>

</LinearLayout>
29 changes: 29 additions & 0 deletions app/src/main/res/layout/activity_about_libraries.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2023 Christian Sommer

This program 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.

This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
-->

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/aboutLibrariesContent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>

</ScrollView>
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 @@ -60,6 +60,7 @@
<string name="data_src">Datenbezugsquelle</string>
<string name="privacy_policy">Datenschutzerklärung</string>
<string name="license">Lizenz</string>
<string name="software_and_licenses">Externe Software und Lizenzen</string>
<string name="version">Version</string>
<string name="contact">Kontakt</string>
<string name="contact_details">Generelles Feedback und Fehler melden</string>
Expand Down
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = "1.7.20"
ext.kotlinVersion = "1.7.20"
ext.aboutlibrariesVersion = "10.5.2"

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.8.2.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id "com.mikepenz.aboutlibraries.plugin" version "${aboutlibrariesVersion}" apply false
}

allprojects {
repositories {
google()
Expand Down
6 changes: 6 additions & 0 deletions config/aboutLibraries/libraries/lib_apache_commons_csv.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"uniqueId": "org.apache.commons:commons-csv",
"licenses": [
"Apache-2.0"
]
}