mirror of
https://github.com/nextcloud/android.git
synced 2024-12-22 08:44:34 +03:00
fix back button behaviour
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
84ec717a57
commit
a501c81bae
2 changed files with 18 additions and 9 deletions
|
@ -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 -> {
|
||||||
|
|
|
@ -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());
|
||||||
|
|
Loading…
Reference in a new issue