Better naming for for top level function class.

* Using top-level extension function instead of object class function.
This commit is contained in:
MohitMaliFtechiz 2024-07-18 23:20:36 +05:30
parent 79add751a4
commit a5284afce6
4 changed files with 41 additions and 43 deletions

View File

@ -18,7 +18,7 @@ android {
base.archivesName.set(apkPrefix)
resValue("string", "app_name", "Kiwix")
resValue("string", "app_search_string", "Search Kiwix")
versionCode = GenerateVersionCode.getVersionCode()
versionCode = "".getVersionCode()
versionName = generateVersionName()
manifestPlaceholders["permission"] = "android.permission.MANAGE_EXTERNAL_STORAGE"
}
@ -85,7 +85,7 @@ task("generateVersionCodeAndName") {
file.printWriter().use {
it.print(
"${generateVersionName()}\n" +
"7${GenerateVersionCode.getVersionCode()}"
"7" + "".getVersionCode()
)
}
}

View File

@ -1,40 +0,0 @@
import java.time.LocalDate
import java.time.temporal.ChronoUnit
/*
* Kiwix Android
* Copyright (c) 2024 Kiwix <android.kiwix.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
object GenerateVersionCode {
fun getVersionCode(): Int {
// the date when the automatic version code generation started
val lastDate = LocalDate.of(2024, 7, 17)
// Calculate the number of days between the lastDate 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, LocalDate.now()).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
// Generate and return the new version code.
// The new version code is calculated by adding the number of days since lastDate
// to the base version code. This creates a unique version code for each day.
return baseVersionCode + daysDifference
}
}

View File

@ -0,0 +1,38 @@
import java.time.LocalDate
import java.time.temporal.ChronoUnit
/*
* Kiwix Android
* Copyright (c) 2024 Kiwix <android.kiwix.org>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
fun String.getVersionCode(): Int {
// the date when the automatic version code generation started
val lastDate = LocalDate.of(2024, 7, 17)
// Calculate the number of days between the lastDate 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, LocalDate.now()).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
// Generate and return the new version code.
// The new version code is calculated by adding the number of days since lastDate
// to the base version code. This creates a unique version code for each day.
return baseVersionCode + daysDifference
}

View File

@ -21,7 +21,7 @@ apply(plugin = "com.jakewharton.butterknife")
android {
defaultConfig {
buildConfigField("long", "VERSION_CODE", "${GenerateVersionCode.getVersionCode()}")
buildConfigField("long", "VERSION_CODE", "".getVersionCode().toString())
}
buildTypes {
getByName("release") {