Merge pull request #3036 from nextcloud/issue-2961

Replace deprecated onBackPressed
This commit is contained in:
Andy Scherzinger 2023-05-24 16:23:08 +02:00 committed by GitHub
commit ac5ebb3e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 142 additions and 74 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.7.1'
implementation 'com.github.nextcloud.android-common:ui:0.10.0' implementation 'com.github.nextcloud.android-common:ui:0.10.0'

View File

@ -35,6 +35,8 @@ import android.view.WindowManager;
import com.nextcloud.talk.BuildConfig; import com.nextcloud.talk.BuildConfig;
import androidx.activity.OnBackPressedCallback;
public abstract class CallBaseActivity extends BaseActivity { public abstract class CallBaseActivity extends BaseActivity {
public static final String TAG = "CallBaseActivity"; public static final String TAG = "CallBaseActivity";
@ -43,6 +45,16 @@ public abstract class CallBaseActivity extends BaseActivity {
public Boolean isInPipMode = Boolean.FALSE; public Boolean isInPipMode = Boolean.FALSE;
long onCreateTime; long onCreateTime;
private OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
if (isPipModePossible()) {
enterPipMode();
}
}
};
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -58,6 +70,8 @@ public abstract class CallBaseActivity extends BaseActivity {
if (isGreaterEqualOreo() && isPipModePossible()) { if (isGreaterEqualOreo() && isPipModePossible()) {
mPictureInPictureParamsBuilder = new PictureInPictureParams.Builder(); mPictureInPictureParamsBuilder = new PictureInPictureParams.Builder();
} }
getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
} }
void hideNavigationIfNoPipAvailable(){ void hideNavigationIfNoPipAvailable(){
@ -101,13 +115,6 @@ public abstract class CallBaseActivity extends BaseActivity {
} }
} }
@Override
public void onBackPressed() {
if (isPipModePossible()) {
enterPipMode();
}
}
@Override @Override
protected void onUserLeaveHint() { protected void onUserLeaveHint() {
long onUserLeaveHintTime = System.currentTimeMillis(); long onUserLeaveHintTime = System.currentTimeMillis();

View File

@ -4,6 +4,8 @@
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Dariusz Olszewski * @author Dariusz Olszewski
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Ezhil Shanmugham
* Copyright (C) 2023 Ezhil Shanmugham <ezhil56x.contact@gmail.com>
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de> * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de> * Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
* Copyright (C) 2021 Dariusz Olszewski * Copyright (C) 2021 Dariusz Olszewski
@ -43,6 +45,7 @@ import java.io.File
class FullScreenImageActivity : AppCompatActivity() { class FullScreenImageActivity : AppCompatActivity() {
lateinit var binding: ActivityFullScreenImageBinding lateinit var binding: ActivityFullScreenImageBinding
private lateinit var path: String private lateinit var path: String
private var showFullscreen = false private var showFullscreen = false
@ -53,7 +56,7 @@ 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() onBackPressedDispatcher.onBackPressed()
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

@ -3,8 +3,10 @@
* *
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Ezhil Shanmugham
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de> * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* 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
@ -56,7 +58,7 @@ 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() onBackPressedDispatcher.onBackPressed()
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

@ -3,8 +3,10 @@
* *
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Ezhil Shanmugham
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de> * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* 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
@ -57,7 +59,7 @@ 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() onBackPressedDispatcher.onBackPressed()
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

@ -4,9 +4,11 @@
* @author Mario Danic * @author Mario Danic
* @author Andy Scherzinger * @author Andy Scherzinger
* @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) 2021 Andy Scherzinger (infoi@andy-scherzinger.de) * Copyright (C) 2021 Andy Scherzinger (infoi@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
@ -30,6 +32,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
@ -82,6 +85,14 @@ class MainActivity : BaseActivity(), ActionBarProvider {
private var router: Router? = null private var router: Router? = null
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (!router!!.handleBack()) {
finish()
}
}
}
@Suppress("Detekt.TooGenericExceptionCaught") @Suppress("Detekt.TooGenericExceptionCaught")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
Log.d(TAG, "onCreate: Activity: " + System.identityHashCode(this).toString()) Log.d(TAG, "onCreate: Activity: " + System.identityHashCode(this).toString())
@ -136,6 +147,8 @@ class MainActivity : BaseActivity(), ActionBarProvider {
} }
}) })
} }
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
} }
fun lockScreenIfConditionsApply() { fun lockScreenIfConditionsApply() {
@ -353,12 +366,6 @@ class MainActivity : BaseActivity(), ActionBarProvider {
} }
} }
override fun onBackPressed() {
if (!router!!.handleBack()) {
super.onBackPressed()
}
}
private fun logRouterBackStack(router: Router) { private fun logRouterBackStack(router: Router) {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
val backstack = router.backstack val backstack = router.backstack

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;
@ -95,6 +95,23 @@ public class TakePhotoActivity extends AppCompatActivity {
@Inject @Inject
ViewThemeUtils viewThemeUtils; 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 @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -221,21 +238,8 @@ public class TakePhotoActivity extends AppCompatActivity {
finish(); finish();
} }
}, ContextCompat.getMainExecutor(this)); }, ContextCompat.getMainExecutor(this));
}
@Override getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback);
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();
} }
private void showCameraElements() { private void showCameraElements() {

View File

@ -5,10 +5,12 @@
* @author Marcel Hibbe * @author Marcel Hibbe
* @author Andy Scherzinger * @author Andy Scherzinger
* @author Tim Krüger * @author Tim Krüger
* @author Ezhil Shanmugham
* 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) 2021-2022 Marcel Hibbe <dev@mhibbe.de> * Copyright (C) 2021-2022 Marcel Hibbe <dev@mhibbe.de>
* Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com> * Copyright (C) 2017-2019 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
@ -72,6 +74,7 @@ import android.widget.ImageView
import android.widget.PopupMenu import android.widget.PopupMenu
import android.widget.RelativeLayout import android.widget.RelativeLayout
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.view.ContextThemeWrapper import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -307,6 +310,14 @@ class ChatActivity :
private var videoURI: Uri? = null 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 var typingTimer: CountDownTimer? = null
val typingParticipants = HashMap<String, String>() val typingParticipants = HashMap<String, String>()
@ -360,6 +371,8 @@ class ChatActivity :
initAdapter() initAdapter()
binding.messagesListView.setAdapter(adapter) binding.messagesListView.setAdapter(adapter)
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
} }
override fun onNewIntent(intent: Intent) { override fun onNewIntent(intent: Intent) {
@ -612,7 +625,7 @@ class ChatActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.chatToolbar) setSupportActionBar(binding.chatToolbar)
binding.chatToolbar.setNavigationOnClickListener { binding.chatToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
@ -621,12 +634,6 @@ class ChatActivity :
viewThemeUtils.material.themeToolbar(binding.chatToolbar) viewThemeUtils.material.themeToolbar(binding.chatToolbar)
} }
override fun onBackPressed() {
val intent = Intent(this, ConversationsListActivity::class.java)
intent.putExtras(Bundle())
startActivity(intent)
}
private fun initAdapter() { private fun initAdapter() {
val senderId = if (!conversationUser!!.userId.equals("?")) { val senderId = if (!conversationUser!!.userId.equals("?")) {
"users/" + conversationUser!!.userId "users/" + conversationUser!!.userId

View File

@ -188,7 +188,7 @@ class ContactsActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.contactsToolbar) setSupportActionBar(binding.contactsToolbar)
binding.contactsToolbar.setNavigationOnClickListener { binding.contactsToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
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
@ -193,7 +195,7 @@ class ConversationInfoActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.conversationInfoToolbar) setSupportActionBar(binding.conversationInfoToolbar)
binding.conversationInfoToolbar.setNavigationOnClickListener { binding.conversationInfoToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
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
@ -149,7 +151,7 @@ class ConversationInfoEditActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.conversationInfoEditToolbar) setSupportActionBar(binding.conversationInfoEditToolbar)
binding.conversationInfoEditToolbar.setNavigationOnClickListener { binding.conversationInfoEditToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
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
@ -186,6 +189,13 @@ class ConversationsListActivity :
private var searchHelper: MessageSearchHelper? = null private var searchHelper: MessageSearchHelper? = null
private var searchViewDisposable: Disposable? = 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?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this) NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
@ -198,6 +208,8 @@ class ConversationsListActivity :
viewThemeUtils.material.themeSearchBarText(binding.searchText) viewThemeUtils.material.themeSearchBarText(binding.searchText)
forwardMessage = intent.getBooleanExtra(KEY_FORWARD_MSG_FLAG, false) forwardMessage = intent.getBooleanExtra(KEY_FORWARD_MSG_FLAG, false)
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
} }
override fun onResume() { override fun onResume() {
@ -244,7 +256,7 @@ class ConversationsListActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.conversationListToolbar) setSupportActionBar(binding.conversationListToolbar)
binding.conversationListToolbar.setNavigationOnClickListener { binding.conversationListToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
@ -1358,13 +1370,6 @@ 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.
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

@ -123,7 +123,7 @@ class GeocodingActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.geocodingToolbar) setSupportActionBar(binding.geocodingToolbar)
binding.geocodingToolbar.setNavigationOnClickListener { binding.geocodingToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
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
@ -39,6 +41,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
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.content.PermissionChecker import androidx.core.content.PermissionChecker
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
@ -115,6 +118,13 @@ class LocationPickerActivity :
var searchItem: MenuItem? = null var searchItem: MenuItem? = null
var searchView: SearchView? = null var searchView: SearchView? = null
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
setResult(Activity.RESULT_CANCELED)
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)
@ -135,6 +145,8 @@ class LocationPickerActivity :
setupSystemColors() setupSystemColors()
getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context)) getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context))
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
} }
override fun onStart() { override fun onStart() {
@ -175,7 +187,7 @@ class LocationPickerActivity :
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.locationPickerToolbar) setSupportActionBar(binding.locationPickerToolbar)
binding.locationPickerToolbar.setNavigationOnClickListener { binding.locationPickerToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)
@ -572,11 +584,6 @@ class LocationPickerActivity :
// empty // empty
} }
override fun onBackPressed() {
setResult(Activity.RESULT_CANCELED)
finish()
}
companion object { companion object {
private val TAG = LocationPickerActivity::class.java.simpleName private val TAG = LocationPickerActivity::class.java.simpleName
private const val REQUEST_PERMISSIONS_REQUEST_CODE = 1 private const val REQUEST_PERMISSIONS_REQUEST_CODE = 1

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
@ -29,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.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import autodagger.AutoInjector import autodagger.AutoInjector
@ -72,6 +75,13 @@ class MessageSearchActivity : BaseActivity() {
private var searchViewDisposable: Disposable? = null private var searchViewDisposable: Disposable? = null
private var adapter: FlexibleAdapter<AbstractFlexibleItem<*>>? = null private var adapter: FlexibleAdapter<AbstractFlexibleItem<*>>? = null
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
setResult(Activity.RESULT_CANCELED)
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)
@ -90,6 +100,8 @@ class MessageSearchActivity : BaseActivity() {
binding.swipeRefreshLayout.setOnRefreshListener { binding.swipeRefreshLayout.setOnRefreshListener {
viewModel.refresh(searchView.query?.toString()) viewModel.refresh(searchView.query?.toString())
} }
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
} }
private fun setupActionBar() { private fun setupActionBar() {
@ -210,7 +222,7 @@ class MessageSearchActivity : BaseActivity() {
} }
override fun onMenuItemActionCollapse(item: MenuItem): Boolean { override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
onBackPressed() onBackPressedDispatcher.onBackPressed()
return false return false
} }
}) })
@ -236,15 +248,10 @@ class MessageSearchActivity : BaseActivity() {
.subscribe { newText -> viewModel.onQueryTextChange(newText) } .subscribe { newText -> viewModel.onQueryTextChange(newText) }
} }
override fun onBackPressed() {
setResult(Activity.RESULT_CANCELED)
finish()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
onBackPressed() onBackPressedDispatcher.onBackPressed()
true true
} }
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)

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
@ -185,7 +187,7 @@ class ProfileActivity : BaseActivity() {
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.profileToolbar) setSupportActionBar(binding.profileToolbar)
binding.profileToolbar.setNavigationOnClickListener { binding.profileToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
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
@ -73,6 +76,13 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
private var filesSelectionDoneMenuItem: MenuItem? = null private var filesSelectionDoneMenuItem: MenuItem? = null
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
setResult(Activity.RESULT_CANCELED)
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)
@ -110,6 +120,8 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
binding.sortButton.setOnClickListener { changeSorting() } binding.sortButton.setOnClickListener { changeSorting() }
viewModel.loadItems() viewModel.loadItems()
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
} }
private fun initViewModel(mimeTypeSelectionFilter: String?) { private fun initViewModel(mimeTypeSelectionFilter: String?) {
@ -191,11 +203,6 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
return true return true
} }
override fun onBackPressed() {
setResult(Activity.RESULT_CANCELED)
super.onBackPressed()
}
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
refreshCurrentPath() refreshCurrentPath()
@ -213,7 +220,7 @@ class RemoteFileBrowserActivity : AppCompatActivity(), SelectionInterface, Swipe
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) { return when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
onBackPressed() onBackPressedDispatcher.onBackPressed()
true true
} }
R.id.files_selection_done -> { R.id.files_selection_done -> {

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
@ -246,7 +248,7 @@ class SettingsActivity : BaseActivity() {
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.settingsToolbar) setSupportActionBar(binding.settingsToolbar)
binding.settingsToolbar.setNavigationOnClickListener { binding.settingsToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
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
@ -246,7 +248,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.onBackPressed()
true true
} else { } else {
super.onOptionsItemSelected(item) super.onOptionsItemSelected(item)

View File

@ -127,7 +127,7 @@ class TranslateActivity : BaseActivity() {
private fun setupActionBar() { private fun setupActionBar() {
setSupportActionBar(binding.translationToolbar) setSupportActionBar(binding.translationToolbar)
binding.translationToolbar.setNavigationOnClickListener { binding.translationToolbar.setNavigationOnClickListener {
onBackPressed() onBackPressedDispatcher.onBackPressed()
} }
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true)