Update: 2026-05-16 21:43:57
This commit is contained in:
@@ -47,25 +47,50 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateButtonState()
|
||||
|
||||
// Scenario 1: Returning after uninstalling old version -> Start fresh install
|
||||
if (pendingInstallAfterUninstall && !isAppInstalled()) {
|
||||
pendingInstallAfterUninstall = false
|
||||
startDownloadAndInstall()
|
||||
return
|
||||
}
|
||||
|
||||
// Scenario 2: Returning after successful install -> Immediate cleanup
|
||||
if (isAppInstalled() && !pendingInstallAfterUninstall) {
|
||||
performImmediateCleanup()
|
||||
}
|
||||
|
||||
updateButtonState()
|
||||
}
|
||||
|
||||
private fun updateButtonState() {
|
||||
if (isAppInstalled()) {
|
||||
binding.btnInstall.text = "تحديث Jordan Bot"
|
||||
binding.tvStatus.text = "⚠️ يجب حذف النسخة القديمة أولاً قبل التحديث"
|
||||
binding.btnInstall.text = "تم التثبيت ✅"
|
||||
binding.tvStatus.text = "سيتم حذف هذا المخلص الآن..."
|
||||
} else {
|
||||
binding.btnInstall.text = "تثبيت Jordan Bot"
|
||||
binding.tvStatus.text = "جاهز للتثبيت ✅"
|
||||
}
|
||||
binding.btnInstall.isEnabled = true
|
||||
binding.btnInstall.isEnabled = !isAppInstalled()
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun performImmediateCleanup() {
|
||||
// Start the bot first so the user is where they want to be
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(JORDAN_BOT_PACKAGE)
|
||||
launchIntent?.let {
|
||||
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(it)
|
||||
}
|
||||
|
||||
// Then immediately trigger self-uninstall (System will still ask for confirmation)
|
||||
val intent = Intent(Intent.ACTION_DELETE, Uri.parse("package:$packageName"))
|
||||
startActivity(intent)
|
||||
|
||||
// Finish this activity so it's not in the backstack
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun isAppInstalled(): Boolean {
|
||||
return isPackageInstalled(JORDAN_BOT_PACKAGE) ||
|
||||
isPackageInstalled("$JORDAN_BOT_PACKAGE.debug")
|
||||
|
||||
Reference in New Issue
Block a user