Move to different versioning scheme and show version in About dialog

Change-Id: I87004c05f9a54d3b2f7854695349e8b506fa7e44
This commit is contained in:
Torsten Grote 2020-10-23 10:25:44 -03:00 committed by Chirayu Desai
parent 63c2d2be11
commit 447f1e5fb4
6 changed files with 46 additions and 3 deletions

View file

@ -3,6 +3,15 @@ import groovy.xml.XmlUtil
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
def gitDescribe = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--always', '--tags', '--dirty=-dirty'
standardOutput = stdout
}
return stdout.toString().trim()
}
android { android {
compileSdkVersion 29 compileSdkVersion 29
@ -11,6 +20,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 29 minSdkVersion 29
targetSdkVersion 29 targetSdkVersion 29
versionNameSuffix "-$gitDescribe"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments disableAnalytics: 'true' testInstrumentationRunnerArguments disableAnalytics: 'true'
} }

View file

@ -2,8 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.stevesoltys.seedvault" package="com.stevesoltys.seedvault"
android:versionCode="7" android:versionCode="29000001"
android:versionName="1.0.0"> android:versionName="10-1.0.0">
<!--
The version code is the targeted SDK_VERSION plus 6 digits for our own version code.
The version name is the targeted Android version followed by - and our own version name.
-->
<uses-permission <uses-permission
android:name="android.permission.BACKUP" android:name="android.permission.BACKUP"

View file

@ -8,9 +8,14 @@ import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.R
import com.stevesoltys.seedvault.transport.backup.PackageService
import org.koin.android.ext.android.inject
class AboutDialogFragment : DialogFragment() { class AboutDialogFragment : DialogFragment() {
private val packageService: PackageService by inject()
private lateinit var versionView: TextView
private lateinit var licenseView: TextView private lateinit var licenseView: TextView
private lateinit var authorView: TextView private lateinit var authorView: TextView
private lateinit var designView: TextView private lateinit var designView: TextView
@ -24,11 +29,15 @@ class AboutDialogFragment : DialogFragment() {
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
val v: View = inflater.inflate(R.layout.fragment_about, container, false) val v: View = inflater.inflate(R.layout.fragment_about, container, false)
versionView = v.findViewById(R.id.versionView)
licenseView = v.findViewById(R.id.licenseView) licenseView = v.findViewById(R.id.licenseView)
authorView = v.findViewById(R.id.authorView) authorView = v.findViewById(R.id.authorView)
designView = v.findViewById(R.id.designView) designView = v.findViewById(R.id.designView)
sponsorView = v.findViewById(R.id.sponsorView) sponsorView = v.findViewById(R.id.sponsorView)
val versionName = packageService.getVersionName(requireContext().packageName) ?: "???"
versionView.text = getString(R.string.about_version, versionName)
return v return v
} }

View file

@ -112,6 +112,12 @@ internal class PackageService(
return ExpectedAppTotals(appsTotal, appsOptOut) return ExpectedAppTotals(appsTotal, appsOptOut)
} }
fun getVersionName(packageName: String): String? = try {
packageManager.getPackageInfo(packageName, 0).versionName
} catch (e: PackageManager.NameNotFoundException) {
null
}
private fun logPackages(packages: List<String>) { private fun logPackages(packages: List<String>) {
packages.chunked(LOG_MAX_PACKAGES).forEach { packages.chunked(LOG_MAX_PACKAGES).forEach {
Log.i(TAG, it.toString()) Log.i(TAG, it.toString())

View file

@ -62,6 +62,19 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appNameView" /> app:layout_constraintTop_toBottomOf="@+id/appNameView" />
<TextView
android:id="@+id/versionView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text="@string/about_version"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/summaryView" />
<TextView <TextView
android:id="@+id/licenseView" android:id="@+id/licenseView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -73,7 +86,7 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/summaryView" /> app:layout_constraintTop_toBottomOf="@+id/versionView" />
<TextView <TextView
android:id="@+id/authorView" android:id="@+id/authorView"

View file

@ -126,6 +126,7 @@
<!-- About --> <!-- About -->
<string name="about_title">About</string> <string name="about_title">About</string>
<string name="about_summary">A backup application using Android\'s internal backup API.</string> <string name="about_summary">A backup application using Android\'s internal backup API.</string>
<string name="about_version">Version: %s</string>
<string name="about_license">License: <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache2</a></string> <string name="about_license">License: <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache2</a></string>
<string name="about_author">Written by: <a href="https://github.com/stevesoltys">Steve Soltys</a> and <a href="https://blog.grobox.de">Torsten Grote</a></string> <string name="about_author">Written by: <a href="https://github.com/stevesoltys">Steve Soltys</a> and <a href="https://blog.grobox.de">Torsten Grote</a></string>
<string name="about_design">Design by: <a href="https://www.glennsorrentino.com/">Glenn Sorrentino</a></string> <string name="about_design">Design by: <a href="https://www.glennsorrentino.com/">Glenn Sorrentino</a></string>