Skip to content

Commit

Permalink
Third-party licenses information
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0oked committed Mar 12, 2024
1 parent d5484c9 commit c70ce29
Show file tree
Hide file tree
Showing 22 changed files with 248 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ height="80">](https://github.com/Kr0oked/Metronome/releases/latest)
| *default* | English | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| cs | Czech | :white_check_mark: | :white_check_mark: | :x: |
| de | German | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| pt-BR | Brazilian Portuguese | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| ru | Russian | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| pt-BR | Brazilian Portuguese | :white_check_mark: | :white_check_mark: | :x: |
| ru | Russian | :white_check_mark: | :white_check_mark: | :x: |

## License

Expand Down
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
id("com.google.android.gms.oss-licenses-plugin")
id("kotlin-kapt")
id("kotlin-parcelize")
}
Expand Down Expand Up @@ -95,6 +96,8 @@ dependencies {

implementation(libs.material)

implementation(libs.oss.licenses.parser)

implementation(libs.guava)

testImplementation(libs.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of Metronome.
* Copyright (C) 2023 Philipp Bobek <[email protected]>
* Copyright (C) 2024 Philipp Bobek <[email protected]>
*
* 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
Expand All @@ -18,7 +18,6 @@

package com.bobek.metronome

import android.Manifest.permission.ACCESS_FINE_LOCATION
import android.Manifest.permission.POST_NOTIFICATIONS
import android.content.Intent
import androidx.annotation.StringRes
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
~ This file is part of Metronome.
~ Copyright (C) 2023 Philipp Bobek <[email protected]>
~ Copyright (C) 2024 Philipp Bobek <[email protected]>
~
~ 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
Expand Down Expand Up @@ -34,14 +34,14 @@
android:label="@string/metronome"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Metronome"
android:theme="@style/Theme.App"
tools:targetApi="31">

<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.Metronome">
android:theme="@style/Theme.App.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/bobek/metronome/SettingsFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of Metronome.
* Copyright (C) 2023 Philipp Bobek <[email protected]>
* Copyright (C) 2024 Philipp Bobek <[email protected]>
*
* 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
Expand All @@ -19,6 +19,7 @@
package com.bobek.metronome

import android.os.Bundle
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.Preference.SummaryProvider
import androidx.preference.PreferenceFragmentCompat
Expand All @@ -31,5 +32,10 @@ class SettingsFragment : PreferenceFragmentCompat() {

findPreference<Preference>(PreferenceConstants.VERSION)?.summaryProvider =
SummaryProvider<Preference> { BuildConfig.VERSION_NAME }

findPreference<Preference>(PreferenceConstants.THIRD_PARTY_LICENSES)?.setOnPreferenceClickListener { _ ->
findNavController().navigate(R.id.action_SettingsFragment_to_ThirdPartyLicensesFragment)
true
}
}
}
37 changes: 37 additions & 0 deletions app/src/main/java/com/bobek/metronome/ThirdPartyLicenseFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of Metronome.
* Copyright (C) 2024 Philipp Bobek <[email protected]>
*
* 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.
*
* Metronome 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 <http://www.gnu.org/licenses/>.
*/

package com.bobek.metronome

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.bobek.metronome.databinding.FragmentThirdPartyLicenseBinding

class ThirdPartyLicenseFragment : Fragment() {

private lateinit var binding: FragmentThirdPartyLicenseBinding

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentThirdPartyLicenseBinding.inflate(inflater, container, false)
binding.licenseContent = arguments?.getString("licenseContent")
return binding.root
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is part of Metronome.
* Copyright (C) 2024 Philipp Bobek <[email protected]>
*
* 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.
*
* Metronome 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 <http://www.gnu.org/licenses/>.
*/

package com.bobek.metronome

import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import de.philipp_bobek.oss_licenses_parser.OssLicensesParser
import de.philipp_bobek.oss_licenses_parser.ThirdPartyLicense
import de.philipp_bobek.oss_licenses_parser.ThirdPartyLicenseMetadata

class ThirdPartyLicensesFragment : PreferenceFragmentCompat() {

override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
val context = preferenceManager.context
val screen = preferenceManager.createPreferenceScreen(context)

context.resources
.openRawResource(R.raw.third_party_license_metadata)
.use(OssLicensesParser::parseMetadata)
.sortedBy { metadata -> metadata.libraryName }
.map(::getPreference)
.forEach(screen::addPreference)

preferenceScreen = screen
}

private fun getPreference(metadata: ThirdPartyLicenseMetadata): Preference {
val preference = Preference(requireContext())
preference.title = metadata.libraryName
preference.setOnPreferenceClickListener {
navigateToThirdPartyLicenseFragment(metadata)
true
}
return preference
}

private fun navigateToThirdPartyLicenseFragment(metadata: ThirdPartyLicenseMetadata) {
val thirdPartyLicense = requireContext().resources
.openRawResource(R.raw.third_party_licenses)
.use { thirdPartyLicensesFile -> OssLicensesParser.parseLicense(metadata, thirdPartyLicensesFile) }

navigateToThirdPartyLicenseFragment(thirdPartyLicense)
}

private fun navigateToThirdPartyLicenseFragment(thirdPartyLicense: ThirdPartyLicense) {
val bundle = bundleOf(
"libraryName" to thirdPartyLicense.libraryName,
"licenseContent" to thirdPartyLicense.licenseContent
)
findNavController().navigate(R.id.action_ThirdPartyLicensesFragment_to_ThirdPartyLicenseFragment, bundle)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of Metronome.
* Copyright (C) 2023 Philipp Bobek <[email protected]>
* Copyright (C) 2024 Philipp Bobek <[email protected]>
*
* 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
Expand Down Expand Up @@ -35,5 +35,7 @@ object PreferenceConstants {

const val POST_NOTIFICATIONS_PERMISSION_REQUESTED = "post_notifications_permission_requested"

const val THIRD_PARTY_LICENSES = "third_party_licenses"

const val VERSION = "version"
}
45 changes: 45 additions & 0 deletions app/src/main/res/layout/fragment_third_party_license.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ This file is part of Metronome.
~ Copyright (C) 2024 Philipp Bobek <[email protected]>
~
~ 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.
~
~ Metronome 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 <http://www.gnu.org/licenses/>.
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ThirdPartyLicenseFragment">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:autoLink="web"
android:text="@{licenseContent}" />

</androidx.core.widget.NestedScrollView>

<data>

<variable
name="licenseContent"
type="String" />
</data>

</layout>
32 changes: 29 additions & 3 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
~ This file is part of Metronome.
~ Copyright (C) 2022 Philipp Bobek <[email protected]>
~ Copyright (C) 2024 Philipp Bobek <[email protected]>
~
~ 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
Expand Down Expand Up @@ -41,8 +41,34 @@
android:label="@string/settings">

<action
android:id="@+id/action_SettingsFragment_to_MetronomeFragment"
app:destination="@id/MetronomeFragment" />
android:id="@+id/action_SettingsFragment_to_ThirdPartyLicensesFragment"
app:destination="@id/ThirdPartyLicensesFragment" />
</fragment>

<fragment
android:id="@+id/ThirdPartyLicensesFragment"
android:name="com.bobek.metronome.ThirdPartyLicensesFragment"
android:label="@string/third_party_licenses">

<action
android:id="@+id/action_ThirdPartyLicensesFragment_to_ThirdPartyLicenseFragment"
app:destination="@id/ThirdPartyLicenseFragment" />
</fragment>

<fragment
android:id="@+id/ThirdPartyLicenseFragment"
android:name="com.bobek.metronome.ThirdPartyLicenseFragment"
android:label="{libraryName}">

<argument
android:name="libraryName"
android:defaultValue=""
app:argType="string" />

<argument
android:name="licenseContent"
android:defaultValue=""
app:argType="string" />
</fragment>

</navigation>
4 changes: 3 additions & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
~ This file is part of Metronome.
~ Copyright (C) 2023 Philipp Bobek <[email protected]>
~ Copyright (C) 2024 Philipp Bobek <[email protected]>
~
~ 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
Expand Down Expand Up @@ -54,6 +54,8 @@
<string name="about">O aplikaci</string>
<string name="author">Autor</string>
<string name="license">Licence</string>
<!--TODO<string name="third_party_licenses">Third-party licenses</string>-->
<!--TODO<string name="third_party_licenses_summary">Licenses of included open source libraries</string>-->
<string name="source_code">Zdrojový kód</string>
<string name="version">Verze</string>

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
~ This file is part of Metronome.
~ Copyright (C) 2023 Philipp Bobek <[email protected]>
~ Copyright (C) 2024 Philipp Bobek <[email protected]>
~
~ 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
Expand Down Expand Up @@ -54,6 +54,8 @@
<string name="about">Über die App</string>
<string name="author">Author</string>
<string name="license">Lizenz</string>
<string name="third_party_licenses">Drittanbieter-Lizenzen</string>
<string name="third_party_licenses_summary">Lizenzen von enthaltenen Open-Source-Bibliotheken</string>
<string name="source_code">Quelltext</string>
<string name="version">Version</string>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!--
~ This file is part of Metronome.
~ Copyright (C) 2022 Philipp Bobek <[email protected]>
~ Copyright (C) 2024 Philipp Bobek <[email protected]>
~
~ 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
Expand All @@ -20,7 +20,7 @@

<resources>

<style name="Base.Theme.Metronome" parent="Theme.Material3.Dark.NoActionBar">
<style name="Base.Theme.App" parent="Theme.Material3.Dark">
<item name="colorPrimary">@color/md_theme_dark_primary</item>
<item name="colorOnPrimary">@color/md_theme_dark_onPrimary</item>
<item name="colorPrimaryContainer">@color/md_theme_dark_primaryContainer</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<string name="about">Sobre</string>
<string name="author">Autor</string>
<string name="license">Licença</string>
<!--TODO<string name="third_party_licenses">Third-party licenses</string>-->
<!--TODO<string name="third_party_licenses_summary">Licenses of included open source libraries</string>-->
<string name="source_code">Código fonte</string>
<string name="version">Versão</string>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<string name="about">О программе</string>
<string name="author">Автор</string>
<string name="license">Лицензии</string>
<!--TODO<string name="third_party_licenses">Third-party licenses</string>-->
<!--TODO<string name="third_party_licenses_summary">Licenses of included open source libraries</string>-->
<string name="source_code">Исходный код</string>
<string name="version">Версия приложения</string>

Expand Down
Loading

0 comments on commit c70ce29

Please sign in to comment.