From 0515806e92be8e3b519b6572a420caaf8f094efc Mon Sep 17 00:00:00 2001 From: amir Date: Wed, 20 Mar 2024 12:37:32 +0330 Subject: [PATCH 1/2] Remove deprecated codes in MainActivity.kt --- .../kotlin/com/v2ray/ang/ui/MainActivity.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt index fa2d5f194..27ef93991 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt @@ -22,6 +22,7 @@ import androidx.appcompat.app.ActionBarDrawerToggle import androidx.recyclerview.widget.ItemTouchHelper import android.util.Log import android.widget.Toast +import androidx.activity.OnBackPressedCallback import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog @@ -117,6 +118,17 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList toast(R.string.toast_permission_denied) } } + + onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) { + binding.drawerLayout.closeDrawer(GravityCompat.START) + } else { + //super.onBackPressed() + onBackPressedDispatcher.onBackPressed() + } + } + }) } private fun setupViewModel() { @@ -656,16 +668,6 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList } } - @Deprecated("Deprecated in Java") - override fun onBackPressed() { - if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) { - binding.drawerLayout.closeDrawer(GravityCompat.START) - } else { - //super.onBackPressed() - onBackPressedDispatcher.onBackPressed() - } - } - override fun onNavigationItemSelected(item: MenuItem): Boolean { // Handle navigation view item clicks here. when (item.itemId) { From 1dcd2478fc56b798f9082367d0f2181e2bd3d024 Mon Sep 17 00:00:00 2001 From: amir Date: Wed, 20 Mar 2024 12:37:53 +0330 Subject: [PATCH 2/2] Expression should use clarifying parentheses --- V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt index 27ef93991..79ba23cb8 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt @@ -70,7 +70,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList binding.fab.setOnClickListener { if (mainViewModel.isRunning.value == true) { Utils.stopVService(this) - } else if (settingsStorage?.decodeString(AppConfig.PREF_MODE) ?: "VPN" == "VPN") { + } else if ((settingsStorage?.decodeString(AppConfig.PREF_MODE) ?: "VPN") == "VPN") { val intent = VpnService.prepare(this) if (intent == null) { startV2Ray()