fixed deprecated onBackPressed Issue-#2961

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Ezhil Shanmugham 2023-05-18 15:09:54 +05:30 committed by Andy Scherzinger
parent f421788480
commit 7b5caf5007
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
17 changed files with 163 additions and 30 deletions

View file

@ -301,7 +301,7 @@ dependencies {
gplayImplementation 'com.google.android.gms:play-services-base:18.2.0'
gplayImplementation "com.google.firebase:firebase-messaging:23.1.2"
// implementation 'androidx.activity:activity-ktx:1.4.0'
implementation 'androidx.activity:activity-ktx:1.6.0-rc02'
implementation 'com.github.nextcloud.android-common:ui:0.10.0'

View file

@ -31,6 +31,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import com.nextcloud.talk.BuildConfig
@ -43,6 +44,13 @@ import java.io.File
class FullScreenImageActivity : AppCompatActivity() {
lateinit var binding: ActivityFullScreenImageBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
private lateinit var path: String
private var showFullscreen = false
@ -53,7 +61,8 @@ class FullScreenImageActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) {
onBackPressed()
// onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
true
} else if (item.itemId == R.id.share) {
val shareUri = FileProvider.getUriForFile(

View file

@ -28,6 +28,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.WindowManager
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import autodagger.AutoInjector
@ -46,6 +47,12 @@ import java.io.File
class FullScreenMediaActivity : AppCompatActivity(), Player.Listener {
lateinit var binding: ActivityFullScreenMediaBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
private lateinit var path: String
private lateinit var player: SimpleExoPlayer
@ -56,7 +63,8 @@ class FullScreenMediaActivity : AppCompatActivity(), Player.Listener {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) {
onBackPressed()
// onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
true
} else if (item.itemId == R.id.share) {
val shareUri = FileProvider.getUriForFile(

View file

@ -26,6 +26,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider
import androidx.core.content.res.ResourcesCompat
@ -45,6 +46,12 @@ import javax.inject.Inject
class FullScreenTextViewerActivity : AppCompatActivity() {
lateinit var binding: ActivityFullScreenTextBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@ -57,7 +64,8 @@ class FullScreenTextViewerActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) {
onBackPressed()
// onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
true
} else if (item.itemId == R.id.share) {
val shareUri = FileProvider.getUriForFile(

View file

@ -30,6 +30,7 @@ import android.os.Bundle
import android.provider.ContactsContract
import android.text.TextUtils
import android.util.Log
import androidx.activity.OnBackPressedCallback
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
@ -74,6 +75,12 @@ import javax.inject.Inject
class MainActivity : BaseActivity(), ActionBarProvider {
lateinit var binding: ActivityMainBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var ncApi: NcApi
@ -355,7 +362,8 @@ class MainActivity : BaseActivity(), ActionBarProvider {
override fun onBackPressed() {
if (!router!!.handleBack()) {
super.onBackPressed()
// super.onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
}

View file

@ -56,6 +56,7 @@ import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
@ -76,7 +77,6 @@ import static com.nextcloud.talk.utils.Mimetype.IMAGE_JPEG;
@AutoInjector(NextcloudTalkApplication.class)
public class TakePhotoActivity extends AppCompatActivity {
private static final String TAG = TakePhotoActivity.class.getSimpleName();
private static final float MAX_SCALE = 6.0f;
@ -223,20 +223,23 @@ public class TakePhotoActivity extends AppCompatActivity {
}, ContextCompat.getMainExecutor(this));
}
@Override
public void onBackPressed() {
Uri uri = (Uri) binding.photoPreview.getTag();
private OnBackPressedCallback callback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
Uri uri = (Uri) binding.photoPreview.getTag();
if (uri != null) {
File photoFile = new File(uri.getPath());
if (!photoFile.delete()) {
Log.w(TAG, "Error deleting temp camera image");
if (uri != null) {
File photoFile = new File(uri.getPath());
if (!photoFile.delete()) {
Log.w(TAG, "Error deleting temp camera image");
}
binding.photoPreview.setTag(null);
}
binding.photoPreview.setTag(null);
}
super.onBackPressed();
}
finish();
}
};
private void showCameraElements() {
binding.send.setVisibility(View.GONE);

View file

@ -36,6 +36,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.widget.SearchView
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.MenuItemCompat
@ -92,6 +93,12 @@ class ContactsActivity :
FlexibleAdapter.OnItemClickListener {
private lateinit var binding: ControllerContactsRvBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var userManager: UserManager
@ -188,7 +195,7 @@ class ContactsActivity :
private fun setupActionBar() {
setSupportActionBar(binding.contactsToolbar)
binding.contactsToolbar.setNavigationOnClickListener {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -5,10 +5,12 @@
* @author Andy Scherzinger
* @author Tim Krüger
* @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2022-2023 Marcel Hibbe (dev@mhibbe.de)
* Copyright (C) 2021-2022 Tim Krüger <t@timkrueger.me>
* Copyright (C) 2021 Andy Scherzinger (info@andy-scherzinger.de)
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -39,6 +41,7 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat
import androidx.work.Data
@ -107,6 +110,13 @@ class ConversationInfoActivity :
private lateinit var binding: ActivityConversationInfoBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var ncApi: NcApi
@ -193,7 +203,7 @@ class ConversationInfoActivity :
private fun setupActionBar() {
setSupportActionBar(binding.conversationInfoToolbar)
binding.conversationInfoToolbar.setNavigationOnClickListener {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -2,7 +2,9 @@
* Nextcloud Talk application
*
* @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2023 Marcel Hibbe (dev@mhibbe.de)
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,6 +32,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.core.net.toFile
import androidx.core.view.ViewCompat
import autodagger.AutoInjector
@ -69,6 +72,12 @@ class ConversationInfoEditActivity :
private lateinit var binding: ActivityConversationInfoEditBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var ncApi: NcApi
@ -149,7 +158,7 @@ class ConversationInfoEditActivity :
private fun setupActionBar() {
setSupportActionBar(binding.conversationInfoEditToolbar)
binding.conversationInfoEditToolbar.setNavigationOnClickListener {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -5,10 +5,12 @@
* @author Andy Scherzinger
* @author Marcel Hibbe
* @author Mario Danic
* @author Ezhil Shanmugham
* Copyright (C) 2022 Álvaro Brey <alvaro.brey@nextcloud.com>
* Copyright (C) 2022 Andy Scherzinger (info@andy-scherzinger.de)
* Copyright (C) 2022 Marcel Hibbe (dev@mhibbe.de)
* Copyright (C) 2017-2020 Mario Danic (mario@lovelyhq.com)
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -47,6 +49,7 @@ import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
@ -143,6 +146,12 @@ class ConversationsListActivity :
private lateinit var binding: ControllerConversationsRvBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var userManager: UserManager
@ -244,7 +253,7 @@ class ConversationsListActivity :
private fun setupActionBar() {
setSupportActionBar(binding.conversationListToolbar)
binding.conversationListToolbar.setNavigationOnClickListener {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
@ -1358,13 +1367,24 @@ class ConversationsListActivity :
showErrorDialog()
}
override fun onBackPressed() {
super.onBackPressed()
// TODO: replace this when conductor is removed. For now it avoids to load the MainActiviy which has no UI.
override fun onBackPressed() {
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
onBackPressedDispatcher.addCallback(this, callback)
// TODO: replace this when conductor is removed. For now it avoids loading the MainActivity which has no UI.
callback.isEnabled = true
callback.handleOnBackPressed()
finishAffinity()
}
companion object {
const val TAG = "ConvListController"
const val UNREAD_BUBBLE_DELAY = 2500

View file

@ -33,6 +33,7 @@ import android.view.MenuItem
import android.view.inputmethod.EditorInfo
import android.widget.AdapterView
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat
import androidx.preference.PreferenceManager
@ -78,6 +79,12 @@ class GeocodingActivity :
lateinit var adapter: GeocodingAdapter
private var geocodingResults: List<Address> = ArrayList()
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
@ -123,7 +130,7 @@ class GeocodingActivity :
private fun setupActionBar() {
setSupportActionBar(binding.geocodingToolbar)
binding.geocodingToolbar.setNavigationOnClickListener {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -2,7 +2,9 @@
* Nextcloud Talk application
*
* @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View file

@ -2,8 +2,10 @@
* Nextcloud Talk application
*
* @author Álvaro Brey
* @author Ezhil Shanmugham
* Copyright (C) 2022 Álvaro Brey
* Copyright (C) 2022 Nextcloud GmbH
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View file

@ -4,9 +4,11 @@
* @author Tobias Kaminsky
* @author Andy Scherzinger
* @author Tim Krüger
* @author Ezhil Shanmugham
* Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2021 Tobias Kaminsky <tobias.kaminsky@nextcloud.com>
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -39,6 +41,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.net.toFile
@ -86,6 +89,13 @@ import javax.inject.Inject
class ProfileActivity : BaseActivity() {
private lateinit var binding: ActivityProfileBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var ncApi: NcApi
@ -185,7 +195,7 @@ class ProfileActivity : BaseActivity() {
private fun setupActionBar() {
setSupportActionBar(binding.profileToolbar)
binding.profileToolbar.setNavigationOnClickListener {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -3,8 +3,10 @@
*
* @author Andy Scherzinger
* @author Álvaro Brey
* @author Ezhil Shanmugham
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2022 Álvaro Brey <alvaro.brey@nextcloud.com>
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -30,6 +32,7 @@ import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.DialogFragment
@ -192,10 +195,18 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
}
override fun onBackPressed() {
setResult(Activity.RESULT_CANCELED)
super.onBackPressed()
val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
setResult(Activity.RESULT_CANCELED)
finish()
}
}
onBackPressedDispatcher.addCallback(this, callback)
callback.handleOnBackPressed()
}
override fun onResume() {
super.onResume()
refreshCurrentPath()

View file

@ -4,9 +4,11 @@
* @author Andy Scherzinger
* @author Mario Danic
* @author Tim Krüger
* @author Ezhil Shanmugham
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
* Copyright (C) 2021-2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017 Mario Danic (mario@lovelyhq.com)
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -52,6 +54,7 @@ import android.widget.Checkable
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
@ -107,6 +110,12 @@ import javax.inject.Inject
class SettingsActivity : BaseActivity() {
private lateinit var binding: ActivitySettingsBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var ncApi: NcApi
@ -246,7 +255,7 @@ class SettingsActivity : BaseActivity() {
private fun setupActionBar() {
setSupportActionBar(binding.settingsToolbar)
binding.settingsToolbar.setNavigationOnClickListener {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
}
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -4,9 +4,11 @@
* @author Tim Krüger
* @author Álvaro Brey
* @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2023 Marcel Hibbe <dev@mhibbe.de>
* Copyright (C) 2022 Álvaro Brey
* Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,6 +30,7 @@ import android.os.Bundle
import android.util.Log
import android.view.MenuItem
import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.ViewModelProvider
@ -53,6 +56,13 @@ import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class)
class SharedItemsActivity : AppCompatActivity() {
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject
lateinit var viewModelFactory: ViewModelProvider.Factory
@ -246,7 +256,7 @@ class SharedItemsActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
true
} else {
super.onOptionsItemSelected(item)