diff --git a/app/build.gradle b/app/build.gradle index e6dde6ee4..a6e1ba438 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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.7.1' implementation 'com.github.nextcloud.android-common:ui:0.10.0' diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallBaseActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallBaseActivity.java index ece059e6e..261a3c058 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallBaseActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallBaseActivity.java @@ -35,6 +35,8 @@ import android.view.WindowManager; import com.nextcloud.talk.BuildConfig; +import androidx.activity.OnBackPressedCallback; + public abstract class CallBaseActivity extends BaseActivity { public static final String TAG = "CallBaseActivity"; @@ -43,6 +45,16 @@ public abstract class CallBaseActivity extends BaseActivity { public Boolean isInPipMode = Boolean.FALSE; long onCreateTime; + + private OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + if (isPipModePossible()) { + enterPipMode(); + } + } + }; + @SuppressLint("ClickableViewAccessibility") @Override public void onCreate(Bundle savedInstanceState) { @@ -58,6 +70,8 @@ public abstract class CallBaseActivity extends BaseActivity { if (isGreaterEqualOreo() && isPipModePossible()) { mPictureInPictureParamsBuilder = new PictureInPictureParams.Builder(); } + + getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback); } void hideNavigationIfNoPipAvailable(){ @@ -101,13 +115,6 @@ public abstract class CallBaseActivity extends BaseActivity { } } - @Override - public void onBackPressed() { - if (isPipModePossible()) { - enterPipMode(); - } - } - @Override protected void onUserLeaveHint() { long onUserLeaveHintTime = System.currentTimeMillis(); diff --git a/app/src/main/java/com/nextcloud/talk/activities/FullScreenImageActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/FullScreenImageActivity.kt index 5bdd38f25..ddd5c0813 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/FullScreenImageActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/FullScreenImageActivity.kt @@ -4,6 +4,8 @@ * @author Marcel Hibbe * @author Dariusz Olszewski * @author Andy Scherzinger + * @author Ezhil Shanmugham + * Copyright (C) 2023 Ezhil Shanmugham * Copyright (C) 2021 Andy Scherzinger * Copyright (C) 2021 Marcel Hibbe * Copyright (C) 2021 Dariusz Olszewski @@ -43,6 +45,7 @@ import java.io.File class FullScreenImageActivity : AppCompatActivity() { lateinit var binding: ActivityFullScreenImageBinding + private lateinit var path: String private var showFullscreen = false @@ -53,7 +56,7 @@ class FullScreenImageActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() true } else if (item.itemId == R.id.share) { val shareUri = FileProvider.getUriForFile( diff --git a/app/src/main/java/com/nextcloud/talk/activities/FullScreenMediaActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/FullScreenMediaActivity.kt index 2a076065d..7a665183d 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/FullScreenMediaActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/FullScreenMediaActivity.kt @@ -3,8 +3,10 @@ * * @author Marcel Hibbe * @author Andy Scherzinger + * @author Ezhil Shanmugham * Copyright (C) 2021 Andy Scherzinger * Copyright (C) 2021 Marcel Hibbe + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -56,7 +58,7 @@ class FullScreenMediaActivity : AppCompatActivity(), Player.Listener { override fun onOptionsItemSelected(item: MenuItem): Boolean { return if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() true } else if (item.itemId == R.id.share) { val shareUri = FileProvider.getUriForFile( diff --git a/app/src/main/java/com/nextcloud/talk/activities/FullScreenTextViewerActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/FullScreenTextViewerActivity.kt index e8e7375f8..00d17b7d5 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/FullScreenTextViewerActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/FullScreenTextViewerActivity.kt @@ -3,8 +3,10 @@ * * @author Marcel Hibbe * @author Andy Scherzinger + * @author Ezhil Shanmugham * Copyright (C) 2021 Andy Scherzinger * Copyright (C) 2021 Marcel Hibbe + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -57,7 +59,7 @@ class FullScreenTextViewerActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() true } else if (item.itemId == R.id.share) { val shareUri = FileProvider.getUriForFile( diff --git a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt index 151f11180..78f4d3535 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt @@ -4,9 +4,11 @@ * @author Mario Danic * @author Andy Scherzinger * @author Marcel Hibbe + * @author Ezhil Shanmugham * Copyright (C) 2023 Marcel Hibbe * Copyright (C) 2021 Andy Scherzinger (infoi@andy-scherzinger.de) * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com) + * Copyright (C) 2023 Ezhil Shanmugham * * 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.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 @@ -82,6 +85,14 @@ class MainActivity : BaseActivity(), ActionBarProvider { private var router: Router? = null + private val onBackPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if (!router!!.handleBack()) { + finish() + } + } + } + @Suppress("Detekt.TooGenericExceptionCaught") override fun onCreate(savedInstanceState: Bundle?) { Log.d(TAG, "onCreate: Activity: " + System.identityHashCode(this).toString()) @@ -136,6 +147,8 @@ class MainActivity : BaseActivity(), ActionBarProvider { } }) } + + onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } fun lockScreenIfConditionsApply() { @@ -353,12 +366,6 @@ class MainActivity : BaseActivity(), ActionBarProvider { } } - override fun onBackPressed() { - if (!router!!.handleBack()) { - super.onBackPressed() - } - } - private fun logRouterBackStack(router: Router) { if (BuildConfig.DEBUG) { val backstack = router.backstack diff --git a/app/src/main/java/com/nextcloud/talk/activities/TakePhotoActivity.java b/app/src/main/java/com/nextcloud/talk/activities/TakePhotoActivity.java index 3e8c6e52d..e7743ca2a 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/TakePhotoActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/TakePhotoActivity.java @@ -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; @@ -95,6 +95,23 @@ public class TakePhotoActivity extends AppCompatActivity { @Inject ViewThemeUtils viewThemeUtils; + private OnBackPressedCallback onBackPressedCallback = 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"); + } + binding.photoPreview.setTag(null); + } + + finish(); + } + }; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -221,21 +238,8 @@ public class TakePhotoActivity extends AppCompatActivity { finish(); } }, ContextCompat.getMainExecutor(this)); - } - @Override - public void onBackPressed() { - 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"); - } - binding.photoPreview.setTag(null); - } - - super.onBackPressed(); + getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback); } private void showCameraElements() { diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 3ab372485..5f7c67410 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -5,10 +5,12 @@ * @author Marcel Hibbe * @author Andy Scherzinger * @author Tim Krüger + * @author Ezhil Shanmugham * Copyright (C) 2021-2022 Tim Krüger * Copyright (C) 2021 Andy Scherzinger * Copyright (C) 2021-2022 Marcel Hibbe * Copyright (C) 2017-2019 Mario Danic + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -72,6 +74,7 @@ import android.widget.ImageView import android.widget.PopupMenu import android.widget.RelativeLayout import android.widget.Toast +import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AlertDialog import androidx.appcompat.view.ContextThemeWrapper import androidx.core.content.ContextCompat @@ -307,6 +310,14 @@ class ChatActivity : private var videoURI: Uri? = null + private val onBackPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + val intent = Intent(this@ChatActivity, ConversationsListActivity::class.java) + intent.putExtras(Bundle()) + startActivity(intent) + } + } + var typingTimer: CountDownTimer? = null val typingParticipants = HashMap() @@ -360,6 +371,8 @@ class ChatActivity : initAdapter() binding.messagesListView.setAdapter(adapter) + + onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } override fun onNewIntent(intent: Intent) { @@ -612,7 +625,7 @@ class ChatActivity : private fun setupActionBar() { setSupportActionBar(binding.chatToolbar) binding.chatToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) @@ -621,12 +634,6 @@ class ChatActivity : viewThemeUtils.material.themeToolbar(binding.chatToolbar) } - override fun onBackPressed() { - val intent = Intent(this, ConversationsListActivity::class.java) - intent.putExtras(Bundle()) - startActivity(intent) - } - private fun initAdapter() { val senderId = if (!conversationUser!!.userId.equals("?")) { "users/" + conversationUser!!.userId diff --git a/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt b/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt index b26ba20df..fea14592b 100644 --- a/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt @@ -188,7 +188,7 @@ class ContactsActivity : private fun setupActionBar() { setSupportActionBar(binding.contactsToolbar) binding.contactsToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index de1cf8918..fdfd44db4 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -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 * Copyright (C) 2021 Andy Scherzinger (info@andy-scherzinger.de) * Copyright (C) 2017-2018 Mario Danic + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -193,7 +195,7 @@ class ConversationInfoActivity : private fun setupActionBar() { setSupportActionBar(binding.conversationInfoToolbar) binding.conversationInfoToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt index ca836c839..6eecacb88 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfoedit/ConversationInfoEditActivity.kt @@ -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 * * 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 @@ -149,7 +151,7 @@ class ConversationInfoEditActivity : private fun setupActionBar() { setSupportActionBar(binding.conversationInfoEditToolbar) binding.conversationInfoEditToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index ab137f1e1..489a99ec4 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -5,10 +5,12 @@ * @author Andy Scherzinger * @author Marcel Hibbe * @author Mario Danic + * @author Ezhil Shanmugham * Copyright (C) 2022 Álvaro Brey * 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 * * 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 @@ -186,6 +189,13 @@ class ConversationsListActivity : private var searchHelper: MessageSearchHelper? = null private var searchViewDisposable: Disposable? = null + private val onBackPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + // TODO: replace this when conductor is removed. For now it avoids to load the MainActiviy which has no UI. + finishAffinity() + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) @@ -198,6 +208,8 @@ class ConversationsListActivity : viewThemeUtils.material.themeSearchBarText(binding.searchText) forwardMessage = intent.getBooleanExtra(KEY_FORWARD_MSG_FLAG, false) + + onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } override fun onResume() { @@ -244,7 +256,7 @@ class ConversationsListActivity : private fun setupActionBar() { setSupportActionBar(binding.conversationListToolbar) binding.conversationListToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) @@ -1358,13 +1370,6 @@ 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. - finishAffinity() - } - companion object { const val TAG = "ConvListController" const val UNREAD_BUBBLE_DELAY = 2500 diff --git a/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt b/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt index 0f43ecad0..535356699 100644 --- a/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/location/GeocodingActivity.kt @@ -123,7 +123,7 @@ class GeocodingActivity : private fun setupActionBar() { setSupportActionBar(binding.geocodingToolbar) binding.geocodingToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/com/nextcloud/talk/location/LocationPickerActivity.kt b/app/src/main/java/com/nextcloud/talk/location/LocationPickerActivity.kt index 48d4ced50..fef8a16ab 100644 --- a/app/src/main/java/com/nextcloud/talk/location/LocationPickerActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/location/LocationPickerActivity.kt @@ -2,7 +2,9 @@ * Nextcloud Talk application * * @author Marcel Hibbe + * @author Ezhil Shanmugham * Copyright (C) 2021 Marcel Hibbe + * Copyright (C) 2023 Ezhil Shanmugham * * 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.inputmethod.EditorInfo import android.widget.Toast +import androidx.activity.OnBackPressedCallback import androidx.appcompat.widget.SearchView import androidx.core.content.PermissionChecker import androidx.core.content.res.ResourcesCompat @@ -115,6 +118,13 @@ class LocationPickerActivity : var searchItem: MenuItem? = null var searchView: SearchView? = null + private val onBackPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + setResult(Activity.RESULT_CANCELED) + finish() + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) @@ -135,6 +145,8 @@ class LocationPickerActivity : setupSystemColors() getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context)) + + onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } override fun onStart() { @@ -175,7 +187,7 @@ class LocationPickerActivity : private fun setupActionBar() { setSupportActionBar(binding.locationPickerToolbar) binding.locationPickerToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) @@ -572,11 +584,6 @@ class LocationPickerActivity : // empty } - override fun onBackPressed() { - setResult(Activity.RESULT_CANCELED) - finish() - } - companion object { private val TAG = LocationPickerActivity::class.java.simpleName private const val REQUEST_PERMISSIONS_REQUEST_CODE = 1 diff --git a/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt b/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt index 0d1db5fa6..a4f8373c6 100644 --- a/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/messagesearch/MessageSearchActivity.kt @@ -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 * * 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 @@ -29,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.widget.SearchView import androidx.lifecycle.ViewModelProvider import autodagger.AutoInjector @@ -72,6 +75,13 @@ class MessageSearchActivity : BaseActivity() { private var searchViewDisposable: Disposable? = null private var adapter: FlexibleAdapter>? = null + private val onBackPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + setResult(Activity.RESULT_CANCELED) + finish() + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) @@ -90,6 +100,8 @@ class MessageSearchActivity : BaseActivity() { binding.swipeRefreshLayout.setOnRefreshListener { viewModel.refresh(searchView.query?.toString()) } + + onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } private fun setupActionBar() { @@ -210,7 +222,7 @@ class MessageSearchActivity : BaseActivity() { } override fun onMenuItemActionCollapse(item: MenuItem): Boolean { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return false } }) @@ -236,15 +248,10 @@ class MessageSearchActivity : BaseActivity() { .subscribe { newText -> viewModel.onQueryTextChange(newText) } } - override fun onBackPressed() { - setResult(Activity.RESULT_CANCELED) - finish() - } - override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { android.R.id.home -> { - onBackPressed() + onBackPressedDispatcher.onBackPressed() true } else -> super.onOptionsItemSelected(item) diff --git a/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt b/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt index 01eab3bd7..136b364ee 100644 --- a/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/profile/ProfileActivity.kt @@ -4,9 +4,11 @@ * @author Tobias Kaminsky * @author Andy Scherzinger * @author Tim Krüger + * @author Ezhil Shanmugham * Copyright (C) 2022 Tim Krüger * Copyright (C) 2022 Andy Scherzinger * Copyright (C) 2021 Tobias Kaminsky + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -185,7 +187,7 @@ class ProfileActivity : BaseActivity() { private fun setupActionBar() { setSupportActionBar(binding.profileToolbar) binding.profileToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt b/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt index 688845917..f1647ffc4 100644 --- a/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/remotefilebrowser/activities/RemoteFileBrowserActivity.kt @@ -3,8 +3,10 @@ * * @author Andy Scherzinger * @author Álvaro Brey + * @author Ezhil Shanmugham * Copyright (C) 2022 Andy Scherzinger * Copyright (C) 2022 Álvaro Brey + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -73,6 +76,13 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe private var filesSelectionDoneMenuItem: MenuItem? = null + private val onBackPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + setResult(Activity.RESULT_CANCELED) + finish() + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) @@ -110,6 +120,8 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe binding.sortButton.setOnClickListener { changeSorting() } viewModel.loadItems() + + onBackPressedDispatcher.addCallback(this, onBackPressedCallback) } private fun initViewModel(mimeTypeSelectionFilter: String?) { @@ -191,11 +203,6 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe return true } - override fun onBackPressed() { - setResult(Activity.RESULT_CANCELED) - super.onBackPressed() - } - override fun onResume() { super.onResume() refreshCurrentPath() @@ -213,7 +220,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { android.R.id.home -> { - onBackPressed() + onBackPressedDispatcher.onBackPressed() true } R.id.files_selection_done -> { diff --git a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt index c27e19d6c..55fd82bbf 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -4,9 +4,11 @@ * @author Andy Scherzinger * @author Mario Danic * @author Tim Krüger + * @author Ezhil Shanmugham * Copyright (C) 2021 Tim Krüger * Copyright (C) 2021-2022 Andy Scherzinger * Copyright (C) 2017 Mario Danic (mario@lovelyhq.com) + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -246,7 +248,7 @@ class SettingsActivity : BaseActivity() { private fun setupActionBar() { setSupportActionBar(binding.settingsToolbar) binding.settingsToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt b/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt index ee5b34583..d06a5f983 100644 --- a/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/shareditems/activities/SharedItemsActivity.kt @@ -4,9 +4,11 @@ * @author Tim Krüger * @author Álvaro Brey * @author Marcel Hibbe + * @author Ezhil Shanmugham * Copyright (C) 2023 Marcel Hibbe * Copyright (C) 2022 Álvaro Brey * Copyright (C) 2022 Tim Krüger + * Copyright (C) 2023 Ezhil Shanmugham * * 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 @@ -246,7 +248,7 @@ class SharedItemsActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return if (item.itemId == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() true } else { super.onOptionsItemSelected(item) diff --git a/app/src/main/java/com/nextcloud/talk/translate/ui/TranslateActivity.kt b/app/src/main/java/com/nextcloud/talk/translate/ui/TranslateActivity.kt index 7a5aef723..48ee313de 100644 --- a/app/src/main/java/com/nextcloud/talk/translate/ui/TranslateActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/translate/ui/TranslateActivity.kt @@ -127,7 +127,7 @@ class TranslateActivity : BaseActivity() { private fun setupActionBar() { setSupportActionBar(binding.translationToolbar) binding.translationToolbar.setNavigationOnClickListener { - onBackPressed() + onBackPressedDispatcher.onBackPressed() } supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)