Merge branch 'lighter_license' into 'master'
Lighter license activity Closes #303 See merge request pixeldroid/PixelDroid!402
This commit is contained in:
commit
9797060a7b
34347
app/src/main/assets/licenses.html
generated
34347
app/src/main/assets/licenses.html
generated
File diff suppressed because it is too large
Load Diff
1
app/src/main/assets/licenses.json
Normal file
1
app/src/main/assets/licenses.json
Normal file
File diff suppressed because one or more lines are too long
@ -1,19 +1,42 @@
|
|||||||
package org.pixeldroid.app.settings
|
package org.pixeldroid.app.settings
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import com.google.gson.Gson
|
||||||
import org.pixeldroid.app.R
|
import org.pixeldroid.app.R
|
||||||
import org.pixeldroid.app.databinding.ActivityLicensesBinding
|
import org.pixeldroid.app.databinding.OpenSourceLicenseBinding
|
||||||
import org.pixeldroid.app.utils.BaseActivity
|
import org.pixeldroid.app.utils.BaseActivity
|
||||||
|
|
||||||
class LicenseActivity : BaseActivity() {
|
/**
|
||||||
|
* Displays licenses for all app dependencies. JSON is
|
||||||
|
* generated by the plugin https://github.com/cookpad/LicenseToolsPlugin.
|
||||||
|
*/
|
||||||
|
class LicenseActivity: BaseActivity() {
|
||||||
|
|
||||||
|
private lateinit var binding: OpenSourceLicenseBinding
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
val binding = ActivityLicensesBinding.inflate(layoutInflater)
|
binding = OpenSourceLicenseBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
||||||
supportActionBar?.setTitle(R.string.dependencies_licenses)
|
|
||||||
|
|
||||||
binding.webview.loadUrl("file:///android_asset/licenses.html")
|
supportActionBar?.setTitle(R.string.dependencies_licenses)
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
supportActionBar?.setHomeButtonEnabled(true)
|
||||||
|
|
||||||
|
setupRecyclerView()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupRecyclerView() {
|
||||||
|
val text: String = applicationContext.assets.open("licenses.json")
|
||||||
|
.bufferedReader().use { it.readText().replace("\r\n", "\n") }
|
||||||
|
val listObj: List<OpenSourceItem> = Gson().fromJson(text, Libraries::class.java).libraries
|
||||||
|
|
||||||
|
val adapter = OpenSourceLicenseAdapter()
|
||||||
|
binding.openSourceLicenseRecyclerView.adapter = adapter
|
||||||
|
|
||||||
|
|
||||||
|
adapter.updateList(listObj)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package org.pixeldroid.app.settings
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.text.method.LinkMovementMethod
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.pixeldroid.app.databinding.OpenSourceItemBinding
|
||||||
|
|
||||||
|
class OpenSourceLicenseAdapter :
|
||||||
|
RecyclerView.Adapter<OpenSourceLicenseAdapter.OpenSourceLicenceViewHolder>() {
|
||||||
|
|
||||||
|
private var openSourceItems: List<OpenSourceItem> = emptyList()
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
|
fun updateList(newOpenSourceItems: List<OpenSourceItem>) {
|
||||||
|
openSourceItems = newOpenSourceItems
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OpenSourceLicenceViewHolder
|
||||||
|
{
|
||||||
|
val itemBinding = OpenSourceItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
return OpenSourceLicenceViewHolder(itemBinding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: OpenSourceLicenceViewHolder, position: Int) {
|
||||||
|
val item = openSourceItems[position]
|
||||||
|
holder.bind(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = openSourceItems.size
|
||||||
|
|
||||||
|
class OpenSourceLicenceViewHolder(val binding: OpenSourceItemBinding) :
|
||||||
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
fun bind(item: OpenSourceItem) {
|
||||||
|
with(binding) {
|
||||||
|
if (!item.libraryName.isNullOrEmpty()) {
|
||||||
|
title.isVisible = true
|
||||||
|
title.text = "${item.libraryName}"
|
||||||
|
} else {
|
||||||
|
title.isVisible = false
|
||||||
|
}
|
||||||
|
val license = item.license
|
||||||
|
if (license != null) {
|
||||||
|
val licenseUrl = item.licenseUrl?.let { " (${it} )" } ?: ""
|
||||||
|
copyright.isVisible = true
|
||||||
|
copyright.apply {
|
||||||
|
text = "$license$licenseUrl"
|
||||||
|
movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
copyright.isVisible = false
|
||||||
|
}
|
||||||
|
if (item.url != null || item.copyrightHolder != null) {
|
||||||
|
val licenseUrl = item.url?.let { " (${it} )" } ?: ""
|
||||||
|
url.isVisible = true
|
||||||
|
url.apply {
|
||||||
|
text = "${item.copyrightHolder ?: ""}$licenseUrl"
|
||||||
|
movementMethod = LinkMovementMethod.getInstance()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
url.isVisible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data class OpenSourceItem(
|
||||||
|
val libraryName: String?,
|
||||||
|
val copyrightHolder: String?,
|
||||||
|
val url: String?,
|
||||||
|
val license: String?,
|
||||||
|
val licenseUrl: String?,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Libraries(
|
||||||
|
val libraries: List<OpenSourceItem>
|
||||||
|
)
|
41
app/src/main/res/layout/open_source_item.xml
Normal file
41
app/src/main/res/layout/open_source_item.xml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingHorizontal="@dimen/spacing_xlarge"
|
||||||
|
android:paddingBottom="@dimen/spacing_xlarge">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginVertical="@dimen/spacing_xlarge"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:layout_editor_absoluteX="24dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/copyright"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginVertical="@dimen/spacing_large"
|
||||||
|
android:autoLink="web"
|
||||||
|
android:linksClickable="true"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/title"
|
||||||
|
tools:layout_editor_absoluteX="24dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/url"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/spacing_large"
|
||||||
|
android:autoLink="web"
|
||||||
|
android:linksClickable="true"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/copyright"
|
||||||
|
tools:layout_editor_absoluteX="24dp" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
16
app/src/main/res/layout/open_source_license.xml
Normal file
16
app/src/main/res/layout/open_source_license.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/open_source_license_recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fadeScrollbars="false"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -8,6 +8,7 @@
|
|||||||
<dimen name="spacing_small">4dp</dimen>
|
<dimen name="spacing_small">4dp</dimen>
|
||||||
<dimen name="spacing_medium">8dp</dimen>
|
<dimen name="spacing_medium">8dp</dimen>
|
||||||
<dimen name="spacing_large">16dp</dimen>
|
<dimen name="spacing_large">16dp</dimen>
|
||||||
|
<dimen name="spacing_xlarge">24dp</dimen>
|
||||||
|
|
||||||
<dimen name="stroke_small">4dp</dimen>
|
<dimen name="stroke_small">4dp</dimen>
|
||||||
<dimen name="stroke_medium">8dp</dimen>
|
<dimen name="stroke_medium">8dp</dimen>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user