Switch from onBackPressed to onBackPressedDispatcher
onBackPressed is deprecated Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -32,6 +32,7 @@ import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.addCallback
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.annotation.NonNull
|
||||
import androidx.core.graphics.ColorUtils
|
||||
@@ -130,8 +131,28 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
/* Check self update only for stable release, skip debug & nightlies*/
|
||||
if (BuildConfig.APPLICATION_ID == Constants.APP_ID)
|
||||
checkSelfUpdate()
|
||||
if (BuildConfig.APPLICATION_ID == Constants.APP_ID) checkSelfUpdate()
|
||||
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (!B.drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
if (Preferences.getBoolean(this@MainActivity, Preferences.PREFERENCE_QUICK_EXIT)) {
|
||||
finish()
|
||||
} else {
|
||||
if (lastBackPressed + 1000 > System.currentTimeMillis()) {
|
||||
finish()
|
||||
} else {
|
||||
lastBackPressed = System.currentTimeMillis()
|
||||
Toast.makeText(
|
||||
this@MainActivity,
|
||||
getString(R.string.toast_double_press_to_exit),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
B.drawerLayout.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun attachToolbar() {
|
||||
@@ -218,24 +239,6 @@ class MainActivity : BaseActivity() {
|
||||
return navController.navigateUp()
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onBackPressed() {
|
||||
if (!B.drawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
if (Preferences.getBoolean(this, Preferences.PREFERENCE_QUICK_EXIT)) {
|
||||
this.finish()
|
||||
} else {
|
||||
if (lastBackPressed + 1000 > System.currentTimeMillis()) {
|
||||
super.onBackPressed()
|
||||
} else {
|
||||
lastBackPressed = System.currentTimeMillis()
|
||||
Toast.makeText(this, getString(R.string.toast_double_press_to_exit), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
B.drawerLayout.close()
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkExternalStorageAccessPermission() = runWithPermissions(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
|
||||
@@ -62,7 +62,7 @@ class AppsGamesActivity : BaseActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -116,4 +116,4 @@ class AppsGamesActivity : BaseActivity() {
|
||||
3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import androidx.activity.addCallback
|
||||
import com.aurora.Constants
|
||||
import com.aurora.extensions.*
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
@@ -189,14 +190,14 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
setContentView(B.root)
|
||||
|
||||
onNewIntent(intent)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (isExternal) {
|
||||
open(MainActivity::class.java, true)
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (isExternal) {
|
||||
open(MainActivity::class.java, true)
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
super.onBackPressed()
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -255,7 +256,7 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
@@ -826,4 +827,4 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
||||
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class ScreenshotActivity : BaseActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -112,4 +112,4 @@ class ScreenshotActivity : BaseActivity() {
|
||||
|
||||
override fun onReconnected() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ class DownloadActivity : BaseActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
R.id.action_pause_all -> {
|
||||
@@ -244,4 +244,4 @@ class DownloadActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.aurora.store.view.ui.onboarding
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.addCallback
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
@@ -97,6 +98,14 @@ class OnboardingActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
onNewIntent(intent)
|
||||
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (B.viewpager2.currentItem == 0) {
|
||||
finish()
|
||||
} else {
|
||||
B.viewpager2.currentItem = B.viewpager2.currentItem - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
@@ -155,14 +164,6 @@ class OnboardingActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (B.viewpager2.currentItem == 0) {
|
||||
super.onBackPressed()
|
||||
} else {
|
||||
B.viewpager2.currentItem = B.viewpager2.currentItem - 1
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadDefaultPreferences() {
|
||||
/*Filters*/
|
||||
save(PREFERENCE_FILTER_FDROID, true)
|
||||
|
||||
@@ -79,7 +79,7 @@ class SettingsActivity : BaseActivity(),
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class SpoofActivity : BaseActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
return true
|
||||
}
|
||||
R.id.action_export -> {
|
||||
@@ -138,4 +138,4 @@ class SpoofActivity : BaseActivity() {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user