Skip to content

Commit

Permalink
Enabled a function that displays an Alert Dialog if the user wants to…
Browse files Browse the repository at this point in the history
… leave the app
  • Loading branch information
D4rK7355608 committed May 23, 2024
1 parent 90d6350 commit fa31182
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
25 changes: 25 additions & 0 deletions app/src/main/kotlin/com/d4rk/cartcalculator/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.d4rk.cartcalculator.notifications.managers.AppUsageNotificationsManag
import com.d4rk.cartcalculator.ui.settings.display.theme.style.AppTheme
import com.d4rk.cartcalculator.ui.startup.StartupActivity
import com.google.android.gms.ads.MobileAds
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.android.play.core.appupdate.AppUpdateManager
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
Expand Down Expand Up @@ -65,6 +66,30 @@ class MainActivity : ComponentActivity() {
checkForFlexibleUpdate()
}

/**
* This method overrides the `onBackPressed()` method **(deprecated in Java)** to display a confirmation dialog
* before closing the activity. While this method might work, it's recommended to use more modern approaches
* for handling back button presses, such as using Navigation components or Activity lifecycles.
*
* This method is annotated with `@Deprecated` and `@Suppress("DEPRECATION")` to explicitly mark it as deprecated
* and suppress compiler warnings during its usage.
*
* Consider utilizing alternative approaches for handling back button events.
*/
@Deprecated("Deprecated in Java")
@Suppress("DEPRECATION")
override fun onBackPressed() {
MaterialAlertDialogBuilder(this)
.setTitle(R.string.close)
.setMessage(R.string.summary_close)
.setPositiveButton(android.R.string.yes) { _, _ ->
super.onBackPressed()
moveTaskToBack(true)
}
.setNegativeButton(android.R.string.no, null)
.apply { show() }
}

/**
* Overrides the `onActivityResult` method to handle the result of an activity launched for result.
*
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<string name="welcome">Welcome</string>
<string name="browse_terms_of_service_and_privacy_policy">Browse the <i><u>Terms of Service</u></i> and <i><u>Privacy Policy</u></i></string>
<string name="agree">Agree</string>
<string name="add_your_item">Add your item</string>
<string name="quantity">Quantity</string>
<string name="settings">Settings</string>
<string name="appearance">Appearance</string>
Expand All @@ -22,8 +21,6 @@
<string name="runtime">Runtime</string>
<string name="license">License</string>
<string name="share">Share</string>
<string name="share_using">Share using…</string>
<string name="share_subject">Try it now!!!</string>
<string name="device_info">Device Info</string>
<string name="app_build">App Build: Release\n%1$s\n%2$s\n%3$s\n%4$s\n%5$s</string>
<string name="manufacturer">Manufacturer:</string>
Expand Down

0 comments on commit fa31182

Please sign in to comment.