62 lines
2.2 KiB
Kotlin
62 lines
2.2 KiB
Kotlin
/*
|
|
* 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) }
|
|
}
|
|
}
|