From a82ccd54f1fb1ddebc1b24c58085e53742307381 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 19 Jun 2024 21:16:27 +0300 Subject: [PATCH] sync: forces update on playstore (fixes #3651) (#3652) Co-authored-by: dogi --- app/build.gradle | 4 ++-- .../planet/myplanet/datamanager/Service.kt | 22 ++++++++++++------- .../planet/myplanet/utilities/Utilities.kt | 16 ++++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9f1918080a..f14a367f97 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1601 - versionName "0.16.1" + versionCode 1602 + versionName "0.16.2" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt index 24cd4d02d3..d26e7e8ade 100644 --- a/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt +++ b/app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt @@ -321,33 +321,33 @@ class Service(private val context: Context) { val code = doc.getAsJsonPrimitive("code").asString listener?.onConfigurationIdReceived(id, code) } else { - showAlertDialog(context.getString(R.string.failed_to_get_configuration_id)) + showAlertDialog(context.getString(R.string.failed_to_get_configuration_id), false) } } else { - showAlertDialog(context.getString(R.string.failed_to_get_configuration_id)) + showAlertDialog(context.getString(R.string.failed_to_get_configuration_id), false) } customProgressDialog.dismiss() } override fun onFailure(call: Call, t: Throwable) { customProgressDialog.dismiss() - showAlertDialog(context.getString(R.string.device_couldn_t_reach_server_check_and_try_again)) + showAlertDialog(context.getString(R.string.device_couldn_t_reach_server_check_and_try_again), false) } }) } else { customProgressDialog.dismiss() - showAlertDialog(context.getString(R.string.below_min_apk)) + showAlertDialog(context.getString(R.string.below_min_apk), true) } } } else { customProgressDialog.dismiss() - showAlertDialog(context.getString(R.string.device_couldn_t_reach_server_check_and_try_again)) + showAlertDialog(context.getString(R.string.device_couldn_t_reach_server_check_and_try_again), false) } } override fun onFailure(call: Call, t: Throwable) { customProgressDialog.dismiss() - showAlertDialog(context.getString(R.string.device_couldn_t_reach_server_check_and_try_again)) + showAlertDialog(context.getString(R.string.device_couldn_t_reach_server_check_and_try_again), false) } }) } @@ -368,11 +368,17 @@ class Service(private val context: Context) { return parts1.size.compareTo(parts2.size) } - fun showAlertDialog(message: String?) { + fun showAlertDialog(message: String?, playStoreRedirect: Boolean) { val builder = AlertDialog.Builder(context) builder.setMessage(message) builder.setCancelable(true) - builder.setNegativeButton(R.string.okay) { dialog: DialogInterface, _: Int -> dialog.cancel() } + builder.setNegativeButton(R.string.okay) { + dialog: DialogInterface, _: Int -> + if (playStoreRedirect) { + Utilities.openPlayStore() + } + dialog.cancel() + } val alert = builder.create() alert.show() } diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/Utilities.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/Utilities.kt index 65c338768e..f3bb44346a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/Utilities.kt +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/Utilities.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.content.SharedPreferences import android.graphics.Color +import android.net.Uri import android.text.TextUtils import android.text.format.DateUtils import android.util.Base64 @@ -205,4 +206,19 @@ object Utilities { val extension = FileUtils.getFileExtension(url) return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension) } + + fun openPlayStore() { + val appPackageName = context.packageName + val intent = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appPackageName")).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + try { + context.startActivity(intent) + } catch (e: android.content.ActivityNotFoundException) { + val webIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + context.startActivity(webIntent) + } + } }