Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit a1195f57 authored by williamvds's avatar williamvds
Browse files

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
parent 0ce24f8e
Loading
Loading
Loading
Loading
+55 −42
Original line number Diff line number Diff line
@@ -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
}
+179 −152
Original line number Diff line number Diff line
@@ -6,6 +6,15 @@

    <include layout="@layout/toolbar" />

    <android.support.v4.widget.NestedScrollView
              android:layout_height="fill_parent"
              android:layout_width="fill_parent">

        <LinearLayout
                  android:orientation="vertical"
                  android:layout_height="fill_parent"
                  android:layout_width="fill_parent">

            <ImageView
                    android:src="@mipmap/icon"
                    android:layout_width="100dp"
@@ -177,9 +186,27 @@
                    android:gravity="center_vertical"
                    android:textAppearance="?android:attr/textAppearanceSmall" />

    <WebView
            android:id="@+id/about_view"
            <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:textSize="34sp"/>

            <android.support.v7.widget.RecyclerView
                    android:id="@+id/libraries"
                    android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
                    android:layout_height="wrap_content" />

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</LinearLayout>
+33 −0
Original line number Diff line number Diff line
<?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>
+1 −0
Original line number Diff line number Diff line
@@ -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 -->