Skip to content

Commit

Permalink
Fix download count reset after update
Browse files Browse the repository at this point in the history
  • Loading branch information
AkosPaha01 committed Dec 11, 2022
1 parent 7d17844 commit 9bb189c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/buildCi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,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 Expand Up @@ -257,7 +257,7 @@ jobs:
- name: Send Telegram message
if: steps.extract_branch.outputs.BRANCH_NAME == 'rCompatible'
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\":\"**${{ 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 A6+ Release\",\"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\":\"**${{ 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 A6+ Release\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/${{ fromJson(steps.metadataJson.outputs.json).elements[0].versionName }}-rCompatible/app-release.apk\"}]]}}'"

- name: Send Notification
if: steps.extract_branch.outputs.BRANCH_NAME == 'rCompatible'
Expand Down Expand Up @@ -388,7 +388,7 @@ jobs:
- name: Send Telegram message
if: steps.extract_branch.outputs.BRANCH_NAME == 'rCompatible-Dev'
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 A6+ Debug\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-rCompatible-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 A6+ Debug\",\"url\":\"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/${{ fromJson(steps.metadataJson.outputs.json).elements[0].versionName }}-rCompatible-debug/app-debug.apk\"}]]}}'"

- name: Send Notification
if: steps.extract_branch.outputs.BRANCH_NAME == 'rCompatible-Dev'
Expand Down
20 changes: 10 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
applicationId = "de.dertyp7214.rboardthememanager"
minSdk = 23
targetSdk = 33
versionCode = 371000
versionName = "3.7.1"
versionCode = 372000
versionName = "3.7.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -73,13 +73,13 @@ dependencies {
implementation(project(":mathc"))
implementation(project(":rboardcomponents"))

implementation(platform("com.google.firebase:firebase-bom:31.1.0"))
implementation("com.google.firebase:firebase-messaging-ktx:23.1.0")
implementation(platform("com.google.firebase:firebase-bom:31.1.1"))
implementation("com.google.firebase:firebase-messaging-ktx:23.1.1")
implementation("com.google.firebase:firebase-analytics-ktx:21.2.0")

implementation("com.github.DerTyp7214:PreferencesPlus:1.0")

implementation("com.google.protobuf:protobuf-kotlin:3.21.10")
implementation("com.google.protobuf:protobuf-kotlin:3.21.11")

implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("androidx.navigation:navigation-fragment-ktx:2.6.0-alpha04")
Expand All @@ -94,14 +94,14 @@ dependencies {
//noinspection DifferentStdlibGradleVersion
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.21")
implementation("androidx.core:core:1.9.0")
implementation("com.google.android.material:material:1.8.0-alpha03")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-alpha04")
implementation("com.google.android.material:material:1.8.0-beta01")
implementation("androidx.constraintlayout:constraintlayout:2.2.0-alpha05")
implementation("androidx.preference:preference-ktx:1.2.0")
implementation("androidx.activity:activity-ktx:1.7.0-alpha02")
implementation("androidx.fragment:fragment-ktx:1.6.0-alpha03")
implementation("androidx.fragment:fragment-ktx:1.6.0-alpha04")
implementation("com.jaredrummler:android-shell:1.0.0")
implementation("com.google.firebase:firebase-analytics:21.2.0")
implementation("com.google.firebase:firebase-messaging:23.1.0")
implementation("com.google.firebase:firebase-messaging:23.1.1")
implementation("com.google.code.gson:gson:2.10")
implementation("com.bignerdranch.android:simple-item-decoration:1.0.0")
implementation("de.dertyp7214:PRDownloader:v0.6.0")
Expand All @@ -116,6 +116,6 @@ dependencies {
implementation("com.github.murgupluoglu:flagkit-android:1.0.2")
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))

debugImplementation("androidx.compose.ui:ui-tooling:1.4.0-alpha02")
debugImplementation("androidx.compose.ui:ui-tooling:1.4.0-alpha03")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.21")
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ import kotlin.math.roundToInt

class MainActivity : AppCompatActivity() {

private val updateUrl by lazy {
if (BuildConfig.DEBUG){
"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-rCompatible-debug/app-debug.apk"
}
else{
"https://github.com/DerTyp7214/RboardThemeManagerV3/releases/download/latest-rCompatible/app-release.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") "-rCompatible" else "-rCompatible-debug"
}
}/app-${BuildConfig.BUILD_TYPE}.apk"
}

private val updateUrlGitlab by lazy {
Expand Down Expand Up @@ -740,7 +740,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 @@ -406,13 +406,17 @@ class AppStartUp(private val activity: AppCompatActivity) {
finish()
}
!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 @@ -422,22 +426,25 @@ 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()
) 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

0 comments on commit 9bb189c

Please sign in to comment.