Skip to content

Commit 74e9900

Browse files
committed
fix back press from file details
Signed-off-by: alperozturk <[email protected]>
1 parent 1e0db99 commit 74e9900

File tree

2 files changed

+63
-38
lines changed

2 files changed

+63
-38
lines changed

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,53 +1161,71 @@ class FileDisplayActivity :
11611161
this,
11621162
object : OnBackPressedCallback(true) {
11631163
override fun handleOnBackPressed() {
1164-
when {
1165-
isSearchOpen() -> {
1166-
isEnabled = false
1167-
resetSearchAction()
1168-
}
1164+
handleBackPressImpl(before = {
1165+
isEnabled = false
1166+
}, after = {
1167+
isEnabled = true
1168+
})
1169+
}
1170+
}
1171+
)
1172+
}
11691173

1170-
isDrawerOpen -> {
1171-
isEnabled = false
1172-
onBackPressedDispatcher.onBackPressed()
1173-
}
1174+
private fun handleBackPressImpl(before: () -> Unit = {}, after: () -> Unit = {}) {
1175+
when {
1176+
isSearchOpen() -> {
1177+
before()
1178+
resetSearchAction()
1179+
after()
1180+
}
11741181

1175-
leftFragment is OCFileListFragment -> {
1176-
val fragment = leftFragment as OCFileListFragment
1177-
1178-
when {
1179-
// root
1180-
isRoot(getCurrentDir()) -> {
1181-
if (fragment.shouldNavigateBackToAllFiles()) {
1182-
navigateToAllFiles()
1183-
} else {
1184-
finish()
1185-
}
1186-
}
1187-
1188-
// Normal folder navigation (go up) also works for shared tab
1189-
else -> {
1190-
browseUp(fragment)
1191-
}
1192-
}
1193-
}
1182+
isDrawerOpen -> {
1183+
before()
1184+
onBackPressedDispatcher.onBackPressed()
1185+
after()
1186+
}
11941187

1195-
else -> {
1196-
isEnabled = false
1197-
popBack()
1198-
}
1199-
}
1188+
leftFragment is OCFileListFragment -> {
1189+
before()
1190+
handleOCFileListFragmentBackPress()
1191+
after()
1192+
}
1193+
1194+
else -> {
1195+
before()
1196+
popBack()
1197+
after()
1198+
}
1199+
}
1200+
}
1201+
1202+
private fun handleOCFileListFragmentBackPress() {
1203+
val fragment = leftFragment as OCFileListFragment
1204+
1205+
when {
1206+
// root
1207+
isRoot(getCurrentDir()) -> {
1208+
if (fragment.shouldNavigateBackToAllFiles()) {
1209+
navigateToAllFiles()
1210+
} else {
1211+
finish()
12001212
}
12011213
}
1202-
)
1214+
1215+
// Normal folder navigation (go up) also works for shared tab
1216+
else -> {
1217+
browseUp(fragment)
1218+
}
1219+
}
12031220
}
12041221

12051222
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
12061223
android.R.id.home -> {
12071224
when {
12081225
shouldOpenDrawer() -> openDrawer()
1209-
isSearchOpen() -> resetSearchAction()
1210-
else -> onBackPressedDispatcher.onBackPressed()
1226+
else -> {
1227+
handleBackPressImpl()
1228+
}
12111229
}
12121230
true
12131231
}

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,19 @@ public void onCreate(Bundle savedInstanceState) {
253253

254254
@Override
255255
public void onResume() {
256-
if (getActivity() == null) {
256+
// Don't handle search events if we're coming back from back stack
257+
// The fragment has already been properly restored in onCreate/onActivityCreated
258+
if (mFile != null) {
259+
super.onResume();
257260
return;
258261
}
259262

260-
Intent intent = getActivity().getIntent();
263+
final var activity = getActivity();
264+
if (activity == null) {
265+
return;
266+
}
261267

268+
final Intent intent = activity.getIntent();
262269
if (IntentExtensionsKt.getParcelableArgument(intent, SEARCH_EVENT, SearchEvent.class) != null) {
263270
searchEvent = IntentExtensionsKt.getParcelableArgument(intent, SEARCH_EVENT, SearchEvent.class);
264271
}

0 commit comments

Comments
 (0)