@@ -18,14 +18,14 @@ import java.util.Locale
1818
1919class UpdateChecker (private val context : Context ) {
2020 suspend fun checkUpdate (isManualCheck : Boolean = false) {
21- val currentAppVersion = BuildConfig .VERSION_NAME .replace( " . " , " " ) .toInt()
21+ val currentAppVersion = BuildConfig .VERSION_NAME .filter { it.isDigit() } .toInt()
2222
2323 try {
2424 val response = RetrofitInstance .externalApi.getLatestRelease()
2525 // version would be in the format "0.21.1"
26- val update = response.name.replace( " . " , " " ).toIntOrNull ()
26+ val update = response.name.filter { it.isDigit() }.toInt ()
2727
28- if (update != null && currentAppVersion < update) {
28+ if (currentAppVersion != update) {
2929 withContext(Dispatchers .Main ) {
3030 showUpdateAvailableDialog(response.body, response.htmlUrl)
3131 }
@@ -56,15 +56,15 @@ class UpdateChecker(private val context: Context) {
5656 }
5757
5858 private fun sanitizeChangelog (changelog : String ): String {
59- val removeBloat = changelog.substringBeforeLast(" **Full Changelog**" )
60- val removeLinks = removeBloat.replace(Regex (" in https://github\\ .com/\\ S+" ), " " )
61- val uppercaseChangeType =
62- removeLinks.lines().joinToString(" \n " ) { line ->
59+ return changelog.substringBeforeLast(" **Full Changelog**" )
60+ .replace(Regex (" in https://github\\ .com/\\ S+" ), " " )
61+ .lines().joinToString(" \n " ) { line ->
6362 if (line.startsWith(" ##" )) line.uppercase(Locale .ROOT ) + " :" else line
6463 }
65- val removeHashes = uppercaseChangeType.replace(" ## " , " " )
66- val cleanPrefix = removeHashes.replace(" *" , " •" )
67-
68- return cleanPrefix.trim()
64+ .replace(" ## " , " " )
65+ .replace(" >" , " " )
66+ .replace(" *" , " •" )
67+ .lines()
68+ .joinToString(" \n " ) { it.trim() }
6969 }
7070}
0 commit comments