Skip to content

Commit e616228

Browse files
Merge pull request #16811 from nextcloud/fix/noid/openFileFromeHomescreen
Fix: open file from homescreen when app is closed
2 parents f96bab9 + c6ca05e commit e616228

1 file changed

Lines changed: 14 additions & 27 deletions

File tree

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

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -678,42 +678,29 @@ class FileDisplayActivity :
678678
// endregion
679679

680680
private fun onOpenFileIntent(intent: Intent) {
681-
val file = getFileFromIntent(intent)
682-
if (file == null) {
681+
val file = getFileFromIntent(intent) ?: run {
683682
Log_OC.e(TAG, "Can't open file intent, file is null")
684683
return
685684
}
686685

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

694-
val fileListFragment: OCFileListFragment = when {
695-
currentFragment is OCFileListFragment && currentFragment !is GalleryFragment -> {
696-
currentFragment
697-
}
698-
699-
else -> {
700-
Log_OC.w(
701-
TAG,
702-
"Left fragment is not a valid OCFileListFragment " +
703-
"(was ${currentFragment::class.simpleName}). " +
704-
"Replacing with OCFileListFragment."
705-
)
706-
val newFragment = OCFileListFragment()
707-
setLeftFragment(newFragment, false)
696+
// Ensure fragment is attached before interaction
697+
Handler(Looper.getMainLooper()).post {
698+
(supportFragmentManager.findFragmentByTag(TAG_LIST_OF_FILES) as? OCFileListFragment)?.let { fragment ->
699+
leftFragment = fragment
708700
setupHomeSearchToolbarWithSortAndListButtons()
709-
newFragment
701+
fragment.onItemClicked(file)
710702
}
711703
}
712-
713-
// Post to main thread to ensure fragment is fully attached before interacting
714-
Handler(Looper.getMainLooper()).post {
715-
fileListFragment.onItemClicked(file)
716-
}
717704
}
718705

719706
private fun setLeftFragment(fragment: Fragment?, showSortListGroup: Boolean) {

0 commit comments

Comments
 (0)