Move libraries in About to main layout

About's layout has been wrapped in a NestedScrollView
Added a Library data class to store library information
Added fragment for libraries, listing their name and licenses, links to
their homepages
Added string about_libraries for the section title
This commit is contained in:
williamvds 2018-12-16 15:59:28 +00:00
parent 0ce24f8ed1
commit a1195f5733
No known key found for this signature in database
GPG key ID: 7A4DF5A8CDBD49C7
4 changed files with 273 additions and 199 deletions

View file

@ -7,9 +7,14 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import android.widget.TextView
import com.fsck.k9.activity.K9Activity
@ -18,9 +23,9 @@ import de.cketti.library.changelog.ChangeLog
import timber.log.Timber
class AboutActivity : K9Activity() {
private lateinit var webView: WebView
private data class Library(val name: String, val URL: String, val license: String = "")
class AboutActivity : K9Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setLayout(R.layout.about)
@ -52,10 +57,14 @@ class AboutActivity : K9Activity() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.app_revision_url))))
}
webView = findViewById(R.id.about_view)
val aboutHtml = buildHtml()
webView.loadDataWithBaseURL("file:///android_res/drawable/", aboutHtml, "text/html", "utf-8", null)
val manager = LinearLayoutManager(this)
val libraries = findViewById<RecyclerView>(R.id.libraries)
libraries.apply {
layoutManager = manager
adapter = LibrariesAdapter(USED_LIBRARIES)
setNestedScrollingEnabled(false)
setFocusable(false)
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -78,24 +87,6 @@ class AboutActivity : K9Activity() {
ChangeLog(this).fullLogDialog.show()
}
private fun buildHtml(): String {
val html = StringBuilder()
.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />")
val libs = StringBuilder().append("<ul>")
for ((library, url) in USED_LIBRARIES) {
libs.append("<li><a href=\"").append(url).append("\">")
.append(library)
.append("</a></li>")
}
libs.append("</ul>")
html.append(getString(R.string.app_libraries, libs.toString()))
.append("</p>")
return html.toString()
}
private fun getVersionNumber(): String {
return try {
val packageInfo = packageManager.getPackageInfo(packageName, 0)
@ -106,25 +97,24 @@ class AboutActivity : K9Activity() {
}
}
companion object {
private val USED_LIBRARIES = mapOf(
"Android Support Library" to "https://developer.android.com/topic/libraries/support-library/index.html",
"Android-Support-Preference-V7-Fix" to "https://github.com/Gericop/Android-Support-Preference-V7-Fix",
"ckChangeLog" to "https://github.com/cketti/ckChangeLog",
"Commons IO" to "http://commons.apache.org/io/",
"Glide" to "https://github.com/bumptech/glide",
"HoloColorPicker" to "https://github.com/LarsWerkman/HoloColorPicker",
"jsoup" to "https://jsoup.org/",
"jutf7" to "http://jutf7.sourceforge.net/",
"JZlib" to "http://www.jcraft.com/jzlib/",
"Mime4j" to "http://james.apache.org/mime4j/",
"Moshi" to "https://github.com/square/moshi",
"Okio" to "https://github.com/square/okio",
"SafeContentResolver" to "https://github.com/cketti/SafeContentResolver",
"ShowcaseView" to "https://github.com/amlcurran/ShowcaseView",
"Timber" to "https://github.com/JakeWharton/timber",
"TokenAutoComplete" to "https://github.com/splitwise/TokenAutoComplete/")
private val USED_LIBRARIES = arrayOf(
Library("Android Support Library", "https://developer.android.com/topic/libraries/support-library/index.html", "Apache License, Version 2.0"),
Library("Android-Support-Preference-V7-Fix", "https://github.com/Gericop/Android-Support-Preference-V7-Fix", "Unlicense/Apache License, Version 2.0"),
Library("ckChangeLog", "https://github.com/cketti/ckChangeLog", "Apache License, Version 2.0"),
Library("Commons IO", "https://commons.apache.org/io/", "Apache License, Version 2.0"),
Library("Glide", "https://github.com/bumptech/glide", "Mixed License"),
Library("HoloColorPicker", "https://github.com/LarsWerkman/HoloColorPicker", "Apache License, Version 2.0"),
Library("jsoup", "https://jsoup.org/", "MIT License"),
Library("jutf7", "http://jutf7.sourceforge.net/", "MIT License"),
Library("JZlib", "http://www.jcraft.com/jzlib/", "BSD-style License"),
Library("Mime4j", "http://james.apache.org/mime4j/", "Apache License, Version 2.0"),
Library("Moshi", "https://github.com/square/moshi", "Apache License, Version 2.0"),
Library("Okio", "https://github.com/square/okio", "Apache License, Version 2.0"),
Library("SafeContentResolver", "https://github.com/cketti/SafeContentResolver", "Apache License, Version 2.0"),
Library("ShowcaseView", "https://github.com/amlcurran/ShowcaseView", "Apache License, Version 2.0"),
Library("Timber", "https://github.com/JakeWharton/timber", "Apache License, Version 2.0"),
Library("TokenAutoComplete", "https://github.com/splitwise/TokenAutoComplete/", "Apache License, Version 2.0"))
fun start(context: Context) {
val intent = Intent(context, AboutActivity::class.java)
@ -132,3 +122,26 @@ class AboutActivity : K9Activity() {
}
}
}
private class LibrariesAdapter(private val dataset: Array<Library>)
: RecyclerView.Adapter<LibrariesAdapter.ViewHolder>() {
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.about_library, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, index: Int) {
val library = dataset[index]
holder.view.findViewById<TextView>(R.id.name).text = library.name
holder.view.findViewById<TextView>(R.id.license).text = library.license
holder.view.setOnClickListener {
holder.view.getContext()
.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(library.URL)))
}
}
override fun getItemCount() = dataset.size
}

View file

@ -6,180 +6,207 @@
<include layout="@layout/toolbar" />
<ImageView
android:src="@mipmap/icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="16dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:text="@string/about_title"
android:textColor="?android:attr/textColorPrimary"
android:textSize="34sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical">
<ImageView
android:src="?attr/iconSettingsAbout"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center" />
<android.support.v4.widget.NestedScrollView
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:orientation="vertical">
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<ImageView
android:src="@mipmap/icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="16dp" />
<TextView
android:text="@string/version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:text="@string/about_title"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:textSize="34sp"/>
<TextView
android:id="@+id/version"
android:text="Version"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical">
<ImageView
android:src="?attr/iconSettingsAbout"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center" />
<LinearLayout
android:id="@+id/authorsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<ImageView
android:src="?attr/iconAboutAuthors"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:orientation="vertical">
<TextView
android:text="@string/version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:text="Authors"
<TextView
android:id="@+id/version"
android:text="Version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/authorsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<ImageView
android:src="?attr/iconAboutAuthors"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:orientation="vertical">
<TextView
android:text="Authors"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:text="@string/app_authors"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/licenseLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<ImageView
android:src="?attr/iconAboutLicense"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:orientation="vertical">
<TextView
android:text="License"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:text="@string/app_license"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:layout_gravity="center">
<Button
android:id="@+id/source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="?android:attr/selectableItemBackground"
android:text="@string/source_code"
android:textAllCaps="true" />
<Button
android:id="@+id/changelog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="?android:attr/selectableItemBackground"
android:text="@string/changelog_full_title"
android:textAllCaps="true" />
<Button
android:id="@+id/revisions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:text="@string/app_revision_fmt"
android:textAllCaps="true" />
</LinearLayout>
<TextView
android:id="@+id/copyright"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall" />
<View
android:layout_height="2dp"
android:layout_width="match_parent"
android:background="?android:attr/listDivider" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:text="@string/about_libraries"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:textSize="34sp"/>
<TextView
android:text="@string/app_authors"
<android.support.v7.widget.RecyclerView
android:id="@+id/libraries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/licenseLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<ImageView
android:src="?attr/iconAboutLicense"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:orientation="vertical">
<TextView
android:text="License"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:text="@string/app_license"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:layout_gravity="center">
<Button
android:id="@+id/source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="?android:attr/selectableItemBackground"
android:text="@string/source_code"
android:textAllCaps="true" />
<Button
android:id="@+id/changelog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="?android:attr/selectableItemBackground"
android:text="@string/changelog_full_title"
android:textAllCaps="true" />
<Button
android:id="@+id/revisions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:text="@string/app_revision_fmt"
android:textAllCaps="true" />
</LinearLayout>
<TextView
android:id="@+id/copyright"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall" />
<WebView
android:id="@+id/about_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="Test"
android:textColor="?android:attr/textColorPrimary"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/license"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:gravity="center_vertical"
android:ellipsize="end"
android:maxLines="1"
android:text="Test"
android:textColor="?android:attr/textColorSecondary"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

View file

@ -22,6 +22,7 @@
<string name="app_source_url">https://github.com/k9mail/k-9</string>
<string name="app_license">Apache License, Version 2.0</string>
<string name="app_license_url">https://www.apache.org/licenses/LICENSE-2.0</string>
<string name="about_libraries">Libraries</string>
<!-- Welcome message -->