Fixes #1162 - replaces about page with an Android Fragment
parent
5f5bb47706
commit
379875a62a
@ -0,0 +1,49 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.settings
|
||||||
|
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import kotlinx.android.synthetic.main.fragment_about.*
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.geckoview.BuildConfig
|
||||||
|
|
||||||
|
class AboutFragment : Fragment() {
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
return inflater.inflate(R.layout.fragment_about, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
val appName = requireContext().resources.getString(R.string.app_name)
|
||||||
|
(activity as AppCompatActivity).title = getString(R.string.preferences_about, appName)
|
||||||
|
|
||||||
|
val aboutText = try {
|
||||||
|
val packageInfo = requireContext().packageManager.getPackageInfo(requireContext().packageName, 0)
|
||||||
|
val geckoVersion = packageInfo.versionCode.toString() + " \uD83E\uDD8E " +
|
||||||
|
BuildConfig.MOZ_APP_VERSION + "-" + BuildConfig.MOZ_APP_BUILDID
|
||||||
|
String.format(
|
||||||
|
"%s (Build #%s)",
|
||||||
|
packageInfo.versionName,
|
||||||
|
geckoVersion
|
||||||
|
)
|
||||||
|
} catch (e: PackageManager.NameNotFoundException) {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
val buildDate = org.mozilla.fenix.BuildConfig.BUILD_DATE
|
||||||
|
val content = resources.getString(R.string.about_content, appName)
|
||||||
|
|
||||||
|
about_text.text = aboutText
|
||||||
|
about_content.text = content
|
||||||
|
build_date.text = buildDate
|
||||||
|
}
|
||||||
|
}
|
@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.mozilla.fenix.settings
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import androidx.annotation.RawRes
|
|
||||||
import org.mozilla.fenix.BuildConfig.BUILD_DATE
|
|
||||||
import org.mozilla.fenix.R
|
|
||||||
import org.mozilla.fenix.ext.replace
|
|
||||||
import org.mozilla.fenix.settings.SettingsFragment.Companion.wordmarkPath
|
|
||||||
import org.mozilla.geckoview.BuildConfig
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
object AboutPage {
|
|
||||||
fun createAboutPage(context: Context): String {
|
|
||||||
val substitutionMap = mutableMapOf<String, String>()
|
|
||||||
val appName = context.resources.getString(R.string.app_name)
|
|
||||||
|
|
||||||
try {
|
|
||||||
val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
|
|
||||||
val geckoVersion = packageInfo.versionCode.toString() + " \uD83E\uDD8E " +
|
|
||||||
BuildConfig.MOZ_APP_VERSION + "-" + BuildConfig.MOZ_APP_BUILDID
|
|
||||||
String.format(
|
|
||||||
"%s (Build #%s)",
|
|
||||||
packageInfo.versionName,
|
|
||||||
geckoVersion
|
|
||||||
).also { aboutVersion ->
|
|
||||||
substitutionMap["%about-version%"] = aboutVersion
|
|
||||||
}
|
|
||||||
} catch (e: PackageManager.NameNotFoundException) {
|
|
||||||
// Nothing to do if we can't find the package name.
|
|
||||||
}
|
|
||||||
|
|
||||||
substitutionMap["%build-date%"] = BUILD_DATE
|
|
||||||
|
|
||||||
context.resources.getString(R.string.about_content, appName, SupportUtils.MOZILLA_MANIFESTO_URL)
|
|
||||||
.also { content ->
|
|
||||||
substitutionMap["%about-content%"] = content
|
|
||||||
}
|
|
||||||
|
|
||||||
substitutionMap["%wordmark%"] = File(context.filesDir, wordmarkPath).readText()
|
|
||||||
|
|
||||||
return loadResourceFile(context, R.raw.about, substitutionMap)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun loadResourceFile(
|
|
||||||
context: Context,
|
|
||||||
@RawRes resId: Int,
|
|
||||||
replacements: Map<String, String>
|
|
||||||
): String {
|
|
||||||
context.resources.openRawResource(resId)
|
|
||||||
.bufferedReader()
|
|
||||||
.use { it.readText() }
|
|
||||||
.also { return it.replace(replacements) }
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
<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="match_parent"
|
||||||
|
tools:context="org.mozilla.fenix.settings.AboutFragment">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/wordmark"
|
||||||
|
android:importantForAccessibility="no"
|
||||||
|
android:src="?attr/fenixLogo"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
app:layout_constraintWidth_percent="0.5"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/about_text"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
app:layout_constraintWidth_percent="0.8"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/wordmark"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/about_content"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
app:layout_constraintWidth_percent="0.8"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/about_text"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/build_date"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:textSize="16sp"
|
||||||
|
app:layout_constraintWidth_percent="0.8"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/about_content"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,52 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
- License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
||||||
- You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta
|
|
||||||
name="viewport"
|
|
||||||
charset="utf-8"
|
|
||||||
content="width=device-width, initial-scale=1">
|
|
||||||
<style>
|
|
||||||
body, html {
|
|
||||||
background: #f9f9fa;
|
|
||||||
color: #0C0C0D;
|
|
||||||
font-family: sans-serif;
|
|
||||||
line-height: 24px;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
body{
|
|
||||||
padding-left: 24px;
|
|
||||||
padding-right: 24px;
|
|
||||||
margin-left: 0px;
|
|
||||||
margin-right: 0px;
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
color: #0A9AF4;
|
|
||||||
}
|
|
||||||
p.subtitle {
|
|
||||||
text-align: center;
|
|
||||||
opacity: .7;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
img#wordmark {
|
|
||||||
/* We need to set the dp size here, because by default webview assumes the image is not
|
|
||||||
density specific (but since it's an android resource, we get a density specific version). */
|
|
||||||
width: 180px;
|
|
||||||
display: block;
|
|
||||||
margin-left: auto;
|
|
||||||
margin-right: auto;
|
|
||||||
padding-top: 24px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body class="about">
|
|
||||||
<br>
|
|
||||||
<img src="%wordmark%" id="wordmark"/>
|
|
||||||
<br>
|
|
||||||
<p class="subtitle">%about-version%</p>
|
|
||||||
%about-content%
|
|
||||||
<p class="subtitle">Built on: %build-date%</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue