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.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.annotation.IdRes
|
import androidx.annotation.IdRes
|
||||||
import androidx.annotation.NonNull
|
import androidx.annotation.NonNull
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
@@ -130,8 +131,28 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check self update only for stable release, skip debug & nightlies*/
|
/* Check self update only for stable release, skip debug & nightlies*/
|
||||||
if (BuildConfig.APPLICATION_ID == Constants.APP_ID)
|
if (BuildConfig.APPLICATION_ID == Constants.APP_ID) checkSelfUpdate()
|
||||||
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() {
|
private fun attachToolbar() {
|
||||||
@@ -218,24 +239,6 @@ class MainActivity : BaseActivity() {
|
|||||||
return navController.navigateUp()
|
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(
|
private fun checkExternalStorageAccessPermission() = runWithPermissions(
|
||||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class AppsGamesActivity : BaseActivity() {
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import androidx.activity.addCallback
|
||||||
import com.aurora.Constants
|
import com.aurora.Constants
|
||||||
import com.aurora.extensions.*
|
import com.aurora.extensions.*
|
||||||
import com.aurora.gplayapi.data.models.App
|
import com.aurora.gplayapi.data.models.App
|
||||||
@@ -189,14 +190,14 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
|||||||
setContentView(B.root)
|
setContentView(B.root)
|
||||||
|
|
||||||
onNewIntent(intent)
|
onNewIntent(intent)
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBackPressed() {
|
onBackPressedDispatcher.addCallback(this) {
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
open(MainActivity::class.java, true)
|
open(MainActivity::class.java, true)
|
||||||
|
} else {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
super.onBackPressed()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@@ -255,7 +256,7 @@ class AppDetailsActivity : BaseDetailsActivity() {
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_share -> {
|
R.id.action_share -> {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class ScreenshotActivity : BaseActivity() {
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class DownloadActivity : BaseActivity() {
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_pause_all -> {
|
R.id.action_pause_all -> {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package com.aurora.store.view.ui.onboarding
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import androidx.activity.addCallback
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
@@ -97,6 +98,14 @@ class OnboardingActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onNewIntent(intent)
|
onNewIntent(intent)
|
||||||
|
|
||||||
|
onBackPressedDispatcher.addCallback(this) {
|
||||||
|
if (B.viewpager2.currentItem == 0) {
|
||||||
|
finish()
|
||||||
|
} else {
|
||||||
|
B.viewpager2.currentItem = B.viewpager2.currentItem - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent?) {
|
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() {
|
private fun loadDefaultPreferences() {
|
||||||
/*Filters*/
|
/*Filters*/
|
||||||
save(PREFERENCE_FILTER_FDROID, true)
|
save(PREFERENCE_FILTER_FDROID, true)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class SettingsActivity : BaseActivity(),
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class SpoofActivity : BaseActivity() {
|
|||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
android.R.id.home -> {
|
android.R.id.home -> {
|
||||||
onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
R.id.action_export -> {
|
R.id.action_export -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user