Skip to content

Commit

Permalink
feat: show version code and commit hash on setting screen
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltchuang committed Oct 31, 2024
1 parent a0778e3 commit f84e6f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
28 changes: 21 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,23 @@ if (project.file(offrampGradlePath).exists()) {
apply from: offrampGradlePath
}

def getVersionCode = {
System.getenv("PERA_APP_VERSION_CODE")?.toInteger() ?: peraApplication.versionCode
}

def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

android {
compileSdkVersion targets.compileSdkVersion
defaultConfig {
versionCode peraApplication.versionCode
versionCode getVersionCode()
versionName peraApplication.versionName
applicationId application.applicationId
minSdkVersion targets.minSdkVersion
Expand All @@ -42,6 +55,12 @@ android {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}

buildConfigField "String", "GitHash", "\"${getGitHash()}\""
buildConfigField "String", "APPLICATION_NAME", '"pera"'
buildConfigField "String", "DEEPLINK_PREFIX", '"algorand://"'
buildConfigField "String", "VERSION_NAME", "\"$versionName\""
buildConfigField "Integer", "VERSION_CODE", "$versionCode"
}

signingConfigs {
Expand Down Expand Up @@ -69,8 +88,8 @@ android {
}

debug {
debuggable true
applicationIdSuffix ".debug"
versionNameSuffix " (DEBUG)"
multiDexEnabled true
minifyEnabled false
manifestPlaceholders = [enableCrashReporting: "false", enableFirebasePerformanceLogcat: "true"]
Expand All @@ -86,10 +105,7 @@ android {

staging {
dimension "server"
versionNameSuffix " (STAGING)"
applicationIdSuffix ".staging"
buildConfigField "String", "APPLICATION_NAME", '"pera"'
buildConfigField "String", "DEEPLINK_PREFIX", '"algorand://"'

apiKeyProps.load(new FileInputStream(file('../app/src/staging/api-key.properties')))
apiUrlProps.load(new FileInputStream(file('../app/src/main/api-url.properties')))
Expand Down Expand Up @@ -120,8 +136,6 @@ android {

prod {
dimension "server"
buildConfigField "String", "APPLICATION_NAME", '"pera"'
buildConfigField "String", "DEEPLINK_PREFIX", '"algorand://"'

apiKeyProps.load(new FileInputStream(file('../app/src/prod/api-key.properties')))
apiUrlProps.load(new FileInputStream(file('../app/src/main/api-url.properties')))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,24 @@ class SettingsFragment : DaggerBaseFragment(R.layout.fragment_settings),
developerListItem.setOnClickListener { onDeveloperSettingsClick() }
logoutButton.setOnClickListener { onLogoutClick() }
algorandSecureBackupListItem.setOnClickListener { onAlgorandSecureBackupClick() }
versionCodeTextView.text = getString(R.string.version_format, BuildConfig.VERSION_NAME)
versionCodeTextView.text = getVersionText()
}
}

private fun getVersionText(): String {
var versionName = getString(R.string.version_format, BuildConfig.VERSION_NAME)

val versionText = if (BuildConfig.DEBUG) {
versionName + " (${BuildConfig.FLAVOR.uppercase()} - DEBUG)"
} else if (BuildConfig.FLAVOR.uppercase() != "PROD") {
versionName + " (${BuildConfig.FLAVOR.uppercase()})"
} else {
versionName
}

return versionText + "\n (${BuildConfig.VERSION_CODE} - ${BuildConfig.GitHash})"
}

private fun initObservers() {
with(settingsViewModel.settingsPreviewFlow) {
collectLatestOnLifecycle(
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginTop="@dimen/spacing_large"
android:layout_marginBottom="52dp"
tools:text="@string/version_format" />
Expand Down

0 comments on commit f84e6f5

Please sign in to comment.