fix back button behaviour

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-17 17:11:29 +01:00 committed by Alper Öztürk
parent 84ec717a57
commit a501c81bae
2 changed files with 18 additions and 9 deletions

View file

@ -10,6 +10,7 @@ package com.nextcloud.ui.composeActivity
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
@ -55,6 +56,8 @@ class ComposeActivity : DrawerActivity() {
openDrawer() openDrawer()
} }
handleOnBackPressed()
binding.composeView.setContent { binding.composeView.setContent {
MaterialTheme( MaterialTheme(
colorScheme = viewThemeUtils.getColorScheme(this), colorScheme = viewThemeUtils.getColorScheme(this),
@ -65,6 +68,19 @@ class ComposeActivity : DrawerActivity() {
} }
} }
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
}
}
private fun handleOnBackPressed() {
onBackPressedDispatcher.addCallback(
this,
onBackPressedCallback
)
}
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 -> {

View file

@ -255,14 +255,7 @@ public abstract class DrawerActivity extends ToolbarActivity
@SuppressFBWarnings("RV") @SuppressFBWarnings("RV")
private void handleBottomNavigationViewClicks() { private void handleBottomNavigationViewClicks() {
bottomNavigationView.setOnItemSelectedListener(menuItem -> { bottomNavigationView.setOnItemSelectedListener(menuItem -> {
int previousMenuItemId = menuItemId; menuItemId = menuItem.getItemId();
int newMenuItemId = menuItem.getItemId();
if (previousMenuItemId == newMenuItemId) {
return false;
}
menuItemId = newMenuItemId;
if (menuItemId == R.id.nav_all_files) { if (menuItemId == R.id.nav_all_files) {
showFiles(false,false); showFiles(false,false);
@ -271,7 +264,7 @@ public abstract class DrawerActivity extends ToolbarActivity
} }
} else if (menuItemId == R.id.nav_favorites) { } else if (menuItemId == R.id.nav_favorites) {
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH), menuItemId); handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH), menuItemId);
} else if (menuItemId == R.id.nav_assistant) { } else if (menuItemId == R.id.nav_assistant && !(this instanceof ComposeActivity)) {
startComposeActivity(ComposeDestination.AssistantScreen, R.string.assistant_screen_top_bar_title); startComposeActivity(ComposeDestination.AssistantScreen, R.string.assistant_screen_top_bar_title);
} else if (menuItemId == R.id.nav_gallery) { } else if (menuItemId == R.id.nav_gallery) {
startPhotoSearch(menuItem.getItemId()); startPhotoSearch(menuItem.getItemId());