Skip to content

Commit

Permalink
sync: forces update on playstore (fixes #3651) (#3652)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Jun 19, 2024
1 parent 6dba240 commit a82ccd5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions app/src/main/java/org/ole/planet/myplanet/datamanager/Service.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonObject?>, 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<JsonObject?>, 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)
}
})
}
Expand All @@ -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()
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/org/ole/planet/myplanet/utilities/Utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit a82ccd5

Please sign in to comment.