mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 10:46:53 -04:00
Renamed the environment variable to KIWIX_ANDROID_RELEASE_DATE
.
* Made `LAST_DATE` and `BASE_VERSION_CODE` constants, as these values are crucial for our app and should not be changed. We have marked them as constants and added comments to ensure they remain unchanged.
This commit is contained in:
parent
29616b1cf7
commit
caa45c5f51
@ -1,6 +1,3 @@
|
||||
import java.time.LocalDate
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2024 Kiwix <android.kiwix.org>
|
||||
@ -19,29 +16,37 @@ import java.time.temporal.ChronoUnit
|
||||
*
|
||||
*/
|
||||
|
||||
fun String.getVersionCode(): Int {
|
||||
// the date when the automatic version code generation started
|
||||
val lastDate = LocalDate.of(2024, 7, 17)
|
||||
import java.time.LocalDate
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
// Get the current date. If the "RELEASE_DATE" environment variable is set(in YYYY-MM-DD format).
|
||||
// it uses the specified date to generate the APK version code.
|
||||
/**
|
||||
* The date when the automatic version code generation started.
|
||||
*/
|
||||
val LAST_DATE: LocalDate = LocalDate.of(2024, 7, 17)
|
||||
|
||||
/**
|
||||
* Base version code. This is the version code of the last release uploaded to the Play Store.
|
||||
* We use this as the starting point for generating new version codes automatically.
|
||||
*/
|
||||
const val BASE_VERSION_CODE = 231101
|
||||
|
||||
fun String.getVersionCode(): Int {
|
||||
// Get the current date. If the "KIWIX_ANDROID_RELEASE_DATE" environment
|
||||
// variable is set(in YYYY-MM-DD format).
|
||||
// It uses the specified date to generate the APK version code.
|
||||
// Otherwise, it generates the version code based on the current date.
|
||||
// See https://github.com/kiwix/kiwix-android/issues/4120 for more details.
|
||||
val currentDate = if (!System.getenv("RELEASE_DATE").isNullOrEmpty()) {
|
||||
LocalDate.parse(System.getenv("RELEASE_DATE"))
|
||||
val currentDate = if (!System.getenv("KIWIX_ANDROID_RELEASE_DATE").isNullOrEmpty()) {
|
||||
LocalDate.parse(System.getenv("KIWIX_ANDROID_RELEASE_DATE"))
|
||||
} else {
|
||||
LocalDate.now()
|
||||
}
|
||||
// Calculate the number of days between the lastDate and today's date.
|
||||
// Calculate the number of days between the LAST_DATE and today's date.
|
||||
// This gives us the total number of days since the last version code was set.
|
||||
val daysDifference = ChronoUnit.DAYS.between(lastDate, currentDate).toInt()
|
||||
|
||||
// Base version code. This is the version code of the last release uploaded to the Play Store.
|
||||
// We use this as the starting point for generating new version codes automatically.
|
||||
val baseVersionCode = 231101
|
||||
val daysDifference = ChronoUnit.DAYS.between(LAST_DATE, currentDate).toInt()
|
||||
|
||||
// Generate and return the new version code.
|
||||
// The new version code is calculated by adding the number of days since lastDate
|
||||
// The new version code is calculated by adding the number of days since LAST_DATE
|
||||
// to the base version code. This creates a unique version code for each day.
|
||||
return baseVersionCode + daysDifference
|
||||
return BASE_VERSION_CODE + daysDifference
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user