Skip to content

Commit c6ca05e

Browse files
committed
simplify
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent ba19d09 commit c6ca05e

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -675,35 +675,28 @@ class FileDisplayActivity :
675675
// endregion
676676

677677
private fun onOpenFileIntent(intent: Intent) {
678-
val file = getFileFromIntent(intent)
679-
if (file == null) {
678+
val file = getFileFromIntent(intent) ?: run {
680679
Log_OC.e(TAG, "Can't open file intent, file is null")
681680
return
682681
}
683682

684-
val currentFragment = leftFragment
685-
686-
if (currentFragment !is OCFileListFragment || currentFragment is GalleryFragment) {
687-
val name = if (currentFragment == null) {
688-
"null"
689-
} else {
690-
currentFragment::class.simpleName
691-
}
692-
683+
// Ensure we have the correct fragment type
684+
if (leftFragment !is OCFileListFragment || leftFragment is GalleryFragment) {
693685
Log_OC.w(
694686
TAG,
695-
"Left fragment is not a valid OCFileListFragment (was $name). " +
696-
"Replacing with OCFileListFragment."
687+
"Invalid fragment (${leftFragment?.let { it::class.simpleName } ?: "null"}). " +
688+
"Replacing."
697689
)
698-
val newFragment = OCFileListFragment()
699-
setLeftFragment(newFragment, false)
690+
setLeftFragment(OCFileListFragment(), false)
700691
}
701692

702-
// Post to main thread to ensure fragment is fully attached before interacting
693+
// Ensure fragment is attached before interaction
703694
Handler(Looper.getMainLooper()).post {
704-
leftFragment = supportFragmentManager.findFragmentByTag(TAG_LIST_OF_FILES)
705-
setupHomeSearchToolbarWithSortAndListButtons()
706-
(leftFragment as OCFileListFragment).onItemClicked(file)
695+
(supportFragmentManager.findFragmentByTag(TAG_LIST_OF_FILES) as? OCFileListFragment)?.let { fragment ->
696+
leftFragment = fragment
697+
setupHomeSearchToolbarWithSortAndListButtons()
698+
fragment.onItemClicked(file)
699+
}
707700
}
708701
}
709702

0 commit comments

Comments
 (0)