Skip to content

Commit

Permalink
Dynamically set version string on About page
Browse files Browse the repository at this point in the history
  • Loading branch information
svetter committed Jul 11, 2024
1 parent 0be6b99 commit 8c47708
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionName = "0.1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.gmail.simetist.stereophoniccalculator

import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
Expand All @@ -10,20 +13,30 @@ import androidx.core.view.WindowInsetsCompat


class AboutActivity : AppCompatActivity() {
private lateinit var versionLabel: TextView
private lateinit var backButton: Button

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
// Show notification bar in the same color as the app's background
enableEdgeToEdge()
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.mainLayout)) { v, insets ->
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.mainLayout)) { view, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
view.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}

backButton = findViewById(R.id.backButton)
versionLabel = findViewById(R.id.versionLabel)
backButton = findViewById(R.id.backButton)

try {
val pInfo: PackageInfo = applicationContext.packageManager.getPackageInfo(applicationContext.packageName, 0)
val version = pInfo.versionName
versionLabel.text = "Version $version"
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
}

backButton.setOnClickListener {
finish()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Version 0.1"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/logoDivider"
app:layout_constraintStart_toStartOf="@+id/appNameLabel" />
app:layout_constraintStart_toStartOf="@+id/appNameLabel"
tools:text="Version X.X.X" />

<View
android:id="@+id/logoDivider"
Expand Down

0 comments on commit 8c47708

Please sign in to comment.