diff --git a/app/build.gradle b/app/build.gradle index 7f9cc08..102ca3c 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,6 +4,24 @@ plugins { id 'kotlin-kapt' } +def getGitCommitHash = { + def hashOutput = new ByteArrayOutputStream() + def changedFilesOutput = new ByteArrayOutputStream() + exec { + commandLine 'git', 'log', '-1', '--format=%h', 'HEAD' + standardOutput = hashOutput + } + exec { + commandLine 'git', 'diff-index', '--name-only', 'HEAD' + standardOutput = changedFilesOutput + } + def hash = hashOutput.toString().trim() + if (changedFilesOutput.toString().blank) { + return hash + } + return hash + '-dirty' +} + android { compileSdk 33 @@ -45,6 +63,14 @@ android { excludes += '/META-INF/{AL2.0,LGPL2.1}' } } + buildTypes { + debug { + buildConfigField "String", "GIT_COMMIT_HASH", "\"${getGitCommitHash()}\"" + } + release { + buildConfigField "String", "GIT_COMMIT_HASH", "\"${getGitCommitHash()}\"" + } + } } dependencies { diff --git a/app/src/main/java/com/scouting/app/view/settings/SettingsView.kt b/app/src/main/java/com/scouting/app/view/settings/SettingsView.kt index ee5a7c6..f626bcb 100644 --- a/app/src/main/java/com/scouting/app/view/settings/SettingsView.kt +++ b/app/src/main/java/com/scouting/app/view/settings/SettingsView.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.navigation.NavController +import com.scouting.app.BuildConfig import com.scouting.app.R import com.scouting.app.components.LargeHeaderBar import com.scouting.app.components.MediumButton @@ -271,6 +272,14 @@ fun SettingsView( }, modifier = Modifier.padding(top = 50.dp) ) + SettingsDivider(modifier = Modifier.padding(top = 50.dp)) + SettingsPreference( + title = stringResource(id = R.string.settings_commit_hash_title), + endContent = { + Text(text = BuildConfig.GIT_COMMIT_HASH) + }, + modifier = Modifier.padding(top = 50.dp, bottom = 15.dp) + ) } } FileNameDialog(viewModel) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 746e1ea..4dd142e 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -173,5 +173,6 @@ Yes No, go back Error! You must choose the correct type of template! + Commit hash \ No newline at end of file