Skip to content

Commit

Permalink
Add commit hash to settings view
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Dec 3, 2023
1 parent 3e1809e commit 2489a90
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@
<string name="settings_competition_mode_dialog_positive_button_label">Yes</string>
<string name="settings_competition_mode_dialog_negative_button_label">No, go back</string>
<string name="settings_pick_incorrect_template_toast_text">Error! You must choose the correct type of template!</string>
<string name="settings_commit_hash_title">Commit hash</string>

</resources>

0 comments on commit 2489a90

Please sign in to comment.