Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -675,42 +675,29 @@ class FileDisplayActivity :
// endregion

private fun onOpenFileIntent(intent: Intent) {
val file = getFileFromIntent(intent)
if (file == null) {
val file = getFileFromIntent(intent) ?: run {
Log_OC.e(TAG, "Can't open file intent, file is null")
return
}

val currentFragment = leftFragment

if (currentFragment == null) {
Log_OC.e(TAG, "Can't open file intent, left fragment is null")
return
// Ensure we have the correct fragment type
if (leftFragment !is OCFileListFragment || leftFragment is GalleryFragment) {
Log_OC.w(
TAG,
"Invalid fragment (${leftFragment?.let { it::class.simpleName } ?: "null"}). " +
"Replacing."
)
setLeftFragment(OCFileListFragment(), false)
}

val fileListFragment: OCFileListFragment = when {
currentFragment is OCFileListFragment && currentFragment !is GalleryFragment -> {
currentFragment
}

else -> {
Log_OC.w(
TAG,
"Left fragment is not a valid OCFileListFragment " +
"(was ${currentFragment::class.simpleName}). " +
"Replacing with OCFileListFragment."
)
val newFragment = OCFileListFragment()
setLeftFragment(newFragment, false)
// Ensure fragment is attached before interaction
Handler(Looper.getMainLooper()).post {
(supportFragmentManager.findFragmentByTag(TAG_LIST_OF_FILES) as? OCFileListFragment)?.let { fragment ->
leftFragment = fragment
setupHomeSearchToolbarWithSortAndListButtons()
newFragment
fragment.onItemClicked(file)
}
}

// Post to main thread to ensure fragment is fully attached before interacting
Handler(Looper.getMainLooper()).post {
fileListFragment.onItemClicked(file)
}
}

private fun setLeftFragment(fragment: Fragment?, showSortListGroup: Boolean) {
Expand Down
Loading