diff --git a/.github/workflows/buildCi.yml b/.github/workflows/buildCi.yml index cf5ae174..4bba3adc 100644 --- a/.github/workflows/buildCi.yml +++ b/.github/workflows/buildCi.yml @@ -127,7 +127,7 @@ jobs: app/build/outputs/apk/debug/output-metadata.json - name: Send Telegram message - run: "curl --location --request POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' --header 'Content-Type:application/json' --data-raw '{\"chat_id\":\"${{ secrets.TELEGRAM_TO_MAIN }}\",\"message_thread_id\":${{ secrets.TELEGRAM_MAIN_TOPIC_ID_DEBUG }},\"text\":\"**${{ steps.extract_branch.outputs.BRANCH_NAME }}**\\n\\ncommit: `${{ github.event.head_commit.message }}` [${{ github.event.head_commit.id }}](${{ github.event.head_commit.url }})\",\"parse_mode\":\"markdown\",\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Download A12+\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-debug/app-debug.apk\"}]]}}'" + run: "curl --location --request POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' --header 'Content-Type:application/json' --data-raw '{\"chat_id\":\"${{ secrets.TELEGRAM_TO_MAIN }}\",\"message_thread_id\":${{ secrets.TELEGRAM_MAIN_TOPIC_ID_DEBUG }},\"text\":\"**${{ steps.extract_branch.outputs.BRANCH_NAME }}**\\n\\ncommit: `${{ github.event.head_commit.message }}` [${{ github.event.head_commit.id }}](${{ github.event.head_commit.url }})\",\"parse_mode\":\"markdown\",\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Download A12+\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/${{ fromJson(steps.metadataJson.outputs.json).elements[0].versionName }}-debug/app-debug.apk\"}]]}}'" - name: Send Notification uses: fjogeleit/http-request-action@master diff --git a/.github/workflows/buildRelease.yml b/.github/workflows/buildRelease.yml index 975964e1..a895cc40 100644 --- a/.github/workflows/buildRelease.yml +++ b/.github/workflows/buildRelease.yml @@ -115,10 +115,10 @@ jobs: data: '{"to": "/topics/update-v3-release","data": {"version": ${{ fromJson(steps.metadataJson.outputs.json).elements[0].versionCode }},"type": "update","notification": {"body": "Update available. ${{ steps.commitMessage.outputs.message }}","title": "Update"}}}' - name: Send Telegram message - run: "curl --location --request POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' --header 'Content-Type:application/json' --data-raw '{\"chat_id\":\"${{ secrets.TELEGRAM_TO_MAIN }}\",\"message_thread_id\":${{ secrets.TELEGRAM_MAIN_TOPIC_ID }},\"text\":\"commit: `${{ github.event.head_commit.message }}` [${{ github.event.head_commit.id }}](${{ github.event.head_commit.url }})\",\"parse_mode\":\"markdown\",\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Latest Android 12 Only\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-release/app-release.apk\"}],[{\"text\":\"Latest Android 12 and Below\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-rCompatible/app-release.apk\"}]]}}'" + run: "curl --location --request POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' --header 'Content-Type:application/json' --data-raw '{\"chat_id\":\"${{ secrets.TELEGRAM_TO_MAIN }}\",\"message_thread_id\":${{ secrets.TELEGRAM_MAIN_TOPIC_ID }},\"text\":\"commit: `${{ github.event.head_commit.message }}` [${{ github.event.head_commit.id }}](${{ github.event.head_commit.url }})\",\"parse_mode\":\"markdown\",\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Latest Android 12 Only\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/${{ fromJson(steps.metadataJson.outputs.json).elements[0].versionName }}/app-release.apk\"}]}}'" - name: Send Telegram message - run: "curl --location --request POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' --header 'Content-Type:application/json' --data-raw '{\"chat_id\":\"${{ secrets.TELEGRAM_TO_MAIN }}\",\"message_thread_id\":${{ secrets.TELEGRAM_MAIN_TOPIC_ID_DEBUG }},\"text\":\"**staging**\\n\\ncommit: `${{ github.event.head_commit.message }}` [${{ github.event.head_commit.id }}](${{ github.event.head_commit.url }})\",\"parse_mode\":\"markdown\",\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Download A12+\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-release/app-release.apk\"}]]}}'" + run: "curl --location --request POST 'https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage' --header 'Content-Type:application/json' --data-raw '{\"chat_id\":\"${{ secrets.TELEGRAM_TO_MAIN }}\",\"message_thread_id\":${{ secrets.TELEGRAM_MAIN_TOPIC_ID_DEBUG }},\"text\":\"**staging**\\n\\ncommit: `${{ github.event.head_commit.message }}` [${{ github.event.head_commit.id }}](${{ github.event.head_commit.url }})\",\"parse_mode\":\"markdown\",\"reply_markup\":{\"inline_keyboard\":[[{\"text\":\"Download A12+\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/${{ fromJson(steps.metadataJson.outputs.json).elements[0].versionName }}/app-release.apk\"}]]}}'" - name: Upload Assets id: upload_assets diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7a2a4251..0b0f70d9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -25,8 +25,8 @@ android { applicationId = "de.dertyp7214.rboardthememanager" minSdk = 31 targetSdk = 33 - versionCode = 371000 - versionName = "3.7.1" + versionCode = 372000 + versionName = "3.7.2" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt b/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt index e8008782..a54f5de4 100644 --- a/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt +++ b/app/src/main/java/de/dertyp7214/rboardthememanager/screens/MainActivity.kt @@ -72,8 +72,13 @@ class MainActivity : AppCompatActivity() { @Suppress("PrivatePropertyName") private val PLAY_UPDATE_ID = 3117 - private val updateUrl by lazy { - "https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-${BuildConfig.BUILD_TYPE}/app-${BuildConfig.BUILD_TYPE}.apk" + private val updateUrl: (versionName: String) -> String = { versionName -> + @Suppress("KotlinConstantConditions") + "https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/${versionName}${ + BuildConfig.BUILD_TYPE.let { + if (it == "release") "" else "-$it" + } + }/app-${BuildConfig.BUILD_TYPE}.apk" } private val updateUrlGitlab by lazy { "https://gitlab.com/dertyp7214/RboardMirror/-/raw/main/${BuildConfig.BUILD_TYPE}/app-${BuildConfig.BUILD_TYPE}.apk" @@ -761,7 +766,8 @@ class MainActivity : AppCompatActivity() { notify(this, notificationId, builder.build()) } var finished = false - val url = if (URL(updateUrl).isReachable()) updateUrl else updateUrlGitlab + val versionName = this.intent.getStringExtra("versionName") ?: "3.7.1" + val url = if (URL(updateUrl(versionName)).isReachable()) updateUrl(versionName) else updateUrlGitlab UpdateHelper(url, this).apply { addOnProgressListener { progress, bytes, total -> if (!finished) { diff --git a/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt b/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt index 7dd09037..e9f6ed3d 100644 --- a/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt +++ b/app/src/main/java/de/dertyp7214/rboardthememanager/utils/AppStartUp.kt @@ -375,13 +375,17 @@ class AppStartUp(private val activity: AppCompatActivity) { } !rootAccess -> NoRootDialog.open(this) - else -> checkForUpdate { update -> + else -> checkForUpdate { update, versionName -> checkedForUpdate = true isReady = true validApp(this) { preferences.edit { putBoolean("initialized", true) } - if (it) block(this, Intent().putExtra("update", update)) + if (it) block( + this, Intent() + .putExtra("update", update) + .putExtra("versionName", versionName) + ) else finish() } } @@ -391,13 +395,13 @@ class AppStartUp(private val activity: AppCompatActivity) { } } - private fun checkForUpdate(callback: (update: Boolean) -> Unit) { + private fun checkForUpdate(callback: (update: Boolean, versionName: String?) -> Unit) { if (preferences.getLong( "lastCheck", 0 ) + 5 * 60 * 100 > System.currentTimeMillis() || activity.verifyInstallerId() - ) callback(false) + ) callback(false, null) else doAsync({ URL(checkUpdateUrl).getTextFromUrl(URL(checkUpdateUrlGitlab)::getTextFromUrl) }) { text -> @@ -405,9 +409,12 @@ class AppStartUp(private val activity: AppCompatActivity) { val outputMetadata = Gson().fromJson(text, OutputMetadata::class.java) val versionCode = outputMetadata.elements.first().versionCode preferences.edit { putLong("lastCheck", System.currentTimeMillis()) } - callback(versionCode > BuildConfig.VERSION_CODE) + callback( + versionCode > BuildConfig.VERSION_CODE, + outputMetadata.elements.first().versionName + ) } catch (e: Exception) { - callback(false) + callback(false, null) } } }