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.android.gms:play-services-base:18.2.0'
gplayImplementation "com.google.firebase:firebase-messaging:23.1.2" 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' 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.MenuItem
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import com.nextcloud.talk.BuildConfig import com.nextcloud.talk.BuildConfig
@ -43,6 +44,13 @@ import java.io.File
class FullScreenImageActivity : AppCompatActivity() { class FullScreenImageActivity : AppCompatActivity() {
lateinit var binding: ActivityFullScreenImageBinding lateinit var binding: ActivityFullScreenImageBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
private lateinit var path: String private lateinit var path: String
private var showFullscreen = false private var showFullscreen = false
@ -53,7 +61,8 @@ class FullScreenImageActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) { return if (item.itemId == android.R.id.home) {
onBackPressed() // onBackPressed()
onBackPressedDispatcher.addCallback(this, callback)
true true
} else if (item.itemId == R.id.share) { } else if (item.itemId == R.id.share) {
val shareUri = FileProvider.getUriForFile( val shareUri = FileProvider.getUriForFile(

View file

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

View file

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

View file

@ -30,6 +30,7 @@ import android.os.Bundle
import android.provider.ContactsContract import android.provider.ContactsContract
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import androidx.activity.OnBackPressedCallback
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner
@ -74,6 +75,12 @@ import javax.inject.Inject
class MainActivity : BaseActivity(), ActionBarProvider { class MainActivity : BaseActivity(), ActionBarProvider {
lateinit var binding: ActivityMainBinding lateinit var binding: ActivityMainBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -355,7 +362,8 @@ class MainActivity : BaseActivity(), ActionBarProvider {
override fun onBackPressed() { override fun onBackPressed() {
if (!router!!.handleBack()) { 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 javax.inject.Inject;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.OptIn; import androidx.annotation.OptIn;
@ -76,7 +77,6 @@ import static com.nextcloud.talk.utils.Mimetype.IMAGE_JPEG;
@AutoInjector(NextcloudTalkApplication.class) @AutoInjector(NextcloudTalkApplication.class)
public class TakePhotoActivity extends AppCompatActivity { public class TakePhotoActivity extends AppCompatActivity {
private static final String TAG = TakePhotoActivity.class.getSimpleName(); private static final String TAG = TakePhotoActivity.class.getSimpleName();
private static final float MAX_SCALE = 6.0f; private static final float MAX_SCALE = 6.0f;
@ -223,20 +223,23 @@ public class TakePhotoActivity extends AppCompatActivity {
}, ContextCompat.getMainExecutor(this)); }, ContextCompat.getMainExecutor(this));
} }
@Override private OnBackPressedCallback callback = new OnBackPressedCallback(true) {
public void onBackPressed() { @Override
Uri uri = (Uri) binding.photoPreview.getTag(); public void handleOnBackPressed() {
Uri uri = (Uri) binding.photoPreview.getTag();
if (uri != null) { if (uri != null) {
File photoFile = new File(uri.getPath()); File photoFile = new File(uri.getPath());
if (!photoFile.delete()) { if (!photoFile.delete()) {
Log.w(TAG, "Error deleting temp camera image"); Log.w(TAG, "Error deleting temp camera image");
}
binding.photoPreview.setTag(null);
} }
binding.photoPreview.setTag(null);
}
super.onBackPressed(); finish();
} }
};
private void showCameraElements() { private void showCameraElements() {
binding.send.setVisibility(View.GONE); binding.send.setVisibility(View.GONE);

View file

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

View file

@ -5,10 +5,12 @@
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Tim Krüger * @author Tim Krüger
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2022-2023 Marcel Hibbe (dev@mhibbe.de) * Copyright (C) 2022-2023 Marcel Hibbe (dev@mhibbe.de)
* Copyright (C) 2021-2022 Tim Krüger <t@timkrueger.me> * Copyright (C) 2021-2022 Tim Krüger <t@timkrueger.me>
* Copyright (C) 2021 Andy Scherzinger (info@andy-scherzinger.de) * Copyright (C) 2021 Andy Scherzinger (info@andy-scherzinger.de)
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com> * 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 * 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 * 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.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat import androidx.appcompat.widget.SwitchCompat
import androidx.work.Data import androidx.work.Data
@ -107,6 +110,13 @@ class ConversationInfoActivity :
private lateinit var binding: ActivityConversationInfoBinding private lateinit var binding: ActivityConversationInfoBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -193,7 +203,7 @@ class ConversationInfoActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.conversationInfoToolbar) setSupportActionBar(binding.conversationInfoToolbar)
binding.conversationInfoToolbar.setNavigationOnClickListener { binding.conversationInfoToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.addCallback(this, callback)
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -2,7 +2,9 @@
* Nextcloud Talk application * Nextcloud Talk application
* *
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2023 Marcel Hibbe (dev@mhibbe.de) * 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 * 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 * 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.MenuItem
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.core.net.toFile import androidx.core.net.toFile
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import autodagger.AutoInjector import autodagger.AutoInjector
@ -69,6 +72,12 @@ class ConversationInfoEditActivity :
private lateinit var binding: ActivityConversationInfoEditBinding private lateinit var binding: ActivityConversationInfoEditBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -149,7 +158,7 @@ class ConversationInfoEditActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.conversationInfoEditToolbar) setSupportActionBar(binding.conversationInfoEditToolbar)
binding.conversationInfoEditToolbar.setNavigationOnClickListener { binding.conversationInfoEditToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.addCallback(this, callback)
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -5,10 +5,12 @@
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Mario Danic * @author Mario Danic
* @author Ezhil Shanmugham
* Copyright (C) 2022 Álvaro Brey <alvaro.brey@nextcloud.com> * Copyright (C) 2022 Álvaro Brey <alvaro.brey@nextcloud.com>
* Copyright (C) 2022 Andy Scherzinger (info@andy-scherzinger.de) * Copyright (C) 2022 Andy Scherzinger (info@andy-scherzinger.de)
* Copyright (C) 2022 Marcel Hibbe (dev@mhibbe.de) * Copyright (C) 2022 Marcel Hibbe (dev@mhibbe.de)
* Copyright (C) 2017-2020 Mario Danic (mario@lovelyhq.com) * 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 * 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 * 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.EditorInfo
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat import androidx.core.view.MenuItemCompat
@ -143,6 +146,12 @@ class ConversationsListActivity :
private lateinit var binding: ControllerConversationsRvBinding private lateinit var binding: ControllerConversationsRvBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject @Inject
lateinit var userManager: UserManager lateinit var userManager: UserManager
@ -244,7 +253,7 @@ class ConversationsListActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.conversationListToolbar) setSupportActionBar(binding.conversationListToolbar)
binding.conversationListToolbar.setNavigationOnClickListener { binding.conversationListToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.addCallback(this, callback)
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
@ -1358,13 +1367,24 @@ class ConversationsListActivity :
showErrorDialog() 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() finishAffinity()
} }
companion object { companion object {
const val TAG = "ConvListController" const val TAG = "ConvListController"
const val UNREAD_BUBBLE_DELAY = 2500 const val UNREAD_BUBBLE_DELAY = 2500

View file

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

View file

@ -2,7 +2,9 @@
* Nextcloud Talk application * Nextcloud Talk application
* *
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de> * 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 * 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 * it under the terms of the GNU General Public License as published by

View file

@ -2,8 +2,10 @@
* Nextcloud Talk application * Nextcloud Talk application
* *
* @author Álvaro Brey * @author Álvaro Brey
* @author Ezhil Shanmugham
* Copyright (C) 2022 Álvaro Brey * Copyright (C) 2022 Álvaro Brey
* Copyright (C) 2022 Nextcloud GmbH * 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 * 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 * it under the terms of the GNU General Public License as published by

View file

@ -4,9 +4,11 @@
* @author Tobias Kaminsky * @author Tobias Kaminsky
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Tim Krüger * @author Tim Krüger
* @author Ezhil Shanmugham
* Copyright (C) 2022 Tim Krüger <t@timkrueger.me> * Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de> * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2021 Tobias Kaminsky <tobias.kaminsky@nextcloud.com> * 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 * 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 * 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.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.net.toFile import androidx.core.net.toFile
@ -86,6 +89,13 @@ import javax.inject.Inject
class ProfileActivity : BaseActivity() { class ProfileActivity : BaseActivity() {
private lateinit var binding: ActivityProfileBinding private lateinit var binding: ActivityProfileBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -185,7 +195,7 @@ class ProfileActivity : BaseActivity() {
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.profileToolbar) setSupportActionBar(binding.profileToolbar)
binding.profileToolbar.setNavigationOnClickListener { binding.profileToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.addCallback(this, callback)
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -3,8 +3,10 @@
* *
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Álvaro Brey * @author Álvaro Brey
* @author Ezhil Shanmugham
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de> * Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2022 Álvaro Brey <alvaro.brey@nextcloud.com> * 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 * 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 * 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.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
@ -192,10 +195,18 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
} }
override fun onBackPressed() { override fun onBackPressed() {
setResult(Activity.RESULT_CANCELED) val callback = object : OnBackPressedCallback(true) {
super.onBackPressed() override fun handleOnBackPressed() {
setResult(Activity.RESULT_CANCELED)
finish()
}
}
onBackPressedDispatcher.addCallback(this, callback)
callback.handleOnBackPressed()
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
refreshCurrentPath() refreshCurrentPath()

View file

@ -4,9 +4,11 @@
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Mario Danic * @author Mario Danic
* @author Tim Krüger * @author Tim Krüger
* @author Ezhil Shanmugham
* Copyright (C) 2021 Tim Krüger <t@timkrueger.me> * Copyright (C) 2021 Tim Krüger <t@timkrueger.me>
* Copyright (C) 2021-2022 Andy Scherzinger <info@andy-scherzinger.de> * Copyright (C) 2021-2022 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017 Mario Danic (mario@lovelyhq.com) * 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 * 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 * 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.EditText
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
@ -107,6 +110,12 @@ import javax.inject.Inject
class SettingsActivity : BaseActivity() { class SettingsActivity : BaseActivity() {
private lateinit var binding: ActivitySettingsBinding private lateinit var binding: ActivitySettingsBinding
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -246,7 +255,7 @@ class SettingsActivity : BaseActivity() {
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.settingsToolbar) setSupportActionBar(binding.settingsToolbar)
binding.settingsToolbar.setNavigationOnClickListener { binding.settingsToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.addCallback(this, callback)
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)

View file

@ -4,9 +4,11 @@
* @author Tim Krüger * @author Tim Krüger
* @author Álvaro Brey * @author Álvaro Brey
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Ezhil Shanmugham
* Copyright (C) 2023 Marcel Hibbe <dev@mhibbe.de> * Copyright (C) 2023 Marcel Hibbe <dev@mhibbe.de>
* Copyright (C) 2022 Álvaro Brey * Copyright (C) 2022 Álvaro Brey
* Copyright (C) 2022 Tim Krüger <t@timkrueger.me> * 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 * 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 * 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.util.Log
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
@ -53,6 +56,13 @@ import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class) @AutoInjector(NextcloudTalkApplication::class)
class SharedItemsActivity : AppCompatActivity() { class SharedItemsActivity : AppCompatActivity() {
private val callback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
@Inject @Inject
lateinit var viewModelFactory: ViewModelProvider.Factory lateinit var viewModelFactory: ViewModelProvider.Factory
@ -246,7 +256,7 @@ class SharedItemsActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) { return if (item.itemId == android.R.id.home) {
onBackPressed() onBackPressedDispatcher.addCallback(this, callback)
true true
} else { } else {
super.onOptionsItemSelected(item) super.onOptionsItemSelected(item)