Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pls work 🙏 #182

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/buildCi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/buildRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -391,23 +395,26 @@ 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 ->
try {
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)
}
}
}
Expand Down