diff --git a/app/build.gradle b/app/build.gradle index bc4aa69f..3f5fe8be 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -42,6 +42,20 @@ def getVersionName = { -> } } +def getOldGitVersion = { -> + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'sh', '-c', 'git tag --sort=-committerdate | head -5 | tail -1' + standardOutput = stdout + } + return stdout.toString().trim() + } + catch (ignored) { + return null; + } +} + android { compileSdkVersion 31 buildToolsVersion "31.0.0" @@ -51,6 +65,7 @@ android { def final minor = name.split("\\.")[1].toInteger() def final patch = name.split("\\.")[2].toInteger() def final code = (major * 100000000) + (minor * 100000) + patch + def final oldGitVersion = getOldGitVersion() def final appIdBase = "com.github.premnirmal.tickerwidget" defaultConfig { @@ -63,6 +78,8 @@ android { versionName = name multiDexEnabled true + buildConfigField "String", "PREVIOUS_VERSION", "\"$oldGitVersion\"" + javaCompileOptions { annotationProcessorOptions { arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] diff --git a/app/src/main/kotlin/com/github/premnirmal/ticker/network/CommitsProvider.kt b/app/src/main/kotlin/com/github/premnirmal/ticker/network/CommitsProvider.kt index 64d887ba..faaa072d 100644 --- a/app/src/main/kotlin/com/github/premnirmal/ticker/network/CommitsProvider.kt +++ b/app/src/main/kotlin/com/github/premnirmal/ticker/network/CommitsProvider.kt @@ -28,10 +28,7 @@ class CommitsProvider @Inject constructor( return withContext(Dispatchers.IO) { try { val currentVersion = BuildConfig.VERSION_NAME - val major = currentVersion.split("\\.")[0].toInt() - val minor = currentVersion.split("\\.")[1].toInt() - val patch = currentVersion.split("\\.")[2].toInt() - val previousVersion = "$major.$minor.${patch - 2}" + val previousVersion = BuildConfig.PREVIOUS_VERSION val comparison = githubApi.compareTags( previousVersion, currentVersion )