Update: 2026-05-16 22:03:25
This commit is contained in:
@@ -35,62 +35,46 @@ class MainActivity : AppCompatActivity() {
|
||||
setContentView(binding.root)
|
||||
|
||||
updateButtonState()
|
||||
|
||||
binding.btnInstall.setOnClickListener {
|
||||
if (isAppInstalled()) {
|
||||
showUninstallDialog()
|
||||
} else {
|
||||
startDownloadAndInstall()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// Scenario 1: Returning after uninstalling old version -> Start fresh install
|
||||
// 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 = "تم التثبيت ✅"
|
||||
binding.tvStatus.text = "سيتم حذف هذا المخلص الآن..."
|
||||
} else {
|
||||
binding.btnInstall.text = "تثبيت Jordan Bot"
|
||||
binding.tvStatus.text = "جاهز للتثبيت ✅"
|
||||
}
|
||||
binding.btnInstall.isEnabled = !isAppInstalled()
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun performImmediateCleanup() {
|
||||
// 1. Launch the Bot
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(JORDAN_BOT_PACKAGE)
|
||||
launchIntent?.let {
|
||||
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(it)
|
||||
|
||||
if (isAppInstalled()) {
|
||||
// App is installed - show success state, no install prompt
|
||||
binding.tvStatus.text = "✅ Jordan Bot مثبت بنجاح على جهازك"
|
||||
binding.btnInstall.text = "فتح Jordan Bot"
|
||||
binding.btnInstall.isEnabled = true
|
||||
binding.btnInstall.setOnClickListener {
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(JORDAN_BOT_PACKAGE)
|
||||
if (launchIntent != null) {
|
||||
startActivity(launchIntent)
|
||||
} else {
|
||||
android.widget.Toast.makeText(this, "تعذر فتح التطبيق", android.widget.Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// App is NOT installed - show install button
|
||||
binding.tvStatus.text = "جاهز للتثبيت ✅"
|
||||
binding.btnInstall.text = "تثبيت Jordan Bot"
|
||||
binding.btnInstall.isEnabled = true
|
||||
binding.btnInstall.setOnClickListener {
|
||||
startDownloadAndInstall()
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Trigger self-uninstall
|
||||
val intent = Intent(Intent.ACTION_DELETE)
|
||||
intent.data = Uri.parse("package:$packageName")
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
startActivity(intent)
|
||||
|
||||
// 3. Close the installer
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun isAppInstalled(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user