Skip to content

Commit 39f58f3

Browse files
Merge pull request #17321 from nextcloud/fix/fda-commit-fragment
fix(file-display-activity): commit fragment
2 parents 08e0f43 + 00ccbf9 commit 39f58f3

1 file changed

Lines changed: 18 additions & 38 deletions

File tree

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

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -714,17 +714,7 @@ class FileDisplayActivity :
714714
}
715715

716716
prepareFragmentBeforeCommit(showSortListGroup)
717-
commitFragment(
718-
fragment,
719-
object : CompletionCallback {
720-
override fun onComplete(isFragmentCommitted: Boolean) {
721-
Log_OC.d(
722-
TAG,
723-
"Left fragment committed: $isFragmentCommitted"
724-
)
725-
}
726-
}
727-
)
717+
commitFragment(fragment)
728718
}
729719

730720
private fun prepareFragmentBeforeCommit(showSortListGroup: Boolean) {
@@ -737,17 +727,21 @@ class FileDisplayActivity :
737727
showSortListGroup(showSortListGroup)
738728
}
739729

740-
private fun commitFragment(fragment: Fragment, callback: CompletionCallback) {
730+
private fun commitFragment(fragment: Fragment): Boolean {
741731
val fragmentManager = supportFragmentManager
742-
if (this.isActive() && !fragmentManager.isDestroyed) {
743-
val transaction = fragmentManager.beginTransaction()
744-
transaction.addToBackStack(null)
745-
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES)
746-
transaction.commit()
747-
callback.onComplete(true)
748-
} else {
749-
callback.onComplete(false)
732+
if (!isActive() || fragmentManager.isDestroyed || fragmentManager.isStateSaved) {
733+
Log_OC.d(TAG, "${fragment.javaClass.simpleName} not committed, skipping")
734+
return false
750735
}
736+
737+
fragmentManager.beginTransaction()
738+
.addToBackStack(null)
739+
.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES)
740+
.commit()
741+
742+
Log_OC.d(TAG, "${fragment.javaClass.simpleName} committed, pending transaction")
743+
744+
return true
751745
}
752746

753747
private fun getOCFileListFragmentFromFile(transaction: TransactionInterface) {
@@ -767,24 +761,10 @@ class FileDisplayActivity :
767761
val fm = supportFragmentManager
768762
if (!fm.isStateSaved && !fm.isDestroyed) {
769763
prepareFragmentBeforeCommit(true)
770-
commitFragment(
771-
listOfFiles,
772-
object : CompletionCallback {
773-
override fun onComplete(value: Boolean) {
774-
if (value) {
775-
Log_OC.d(TAG, "OCFileListFragment committed, executing pending transaction")
776-
fm.executePendingTransactions()
777-
transaction.onOCFileListFragmentComplete(listOfFiles)
778-
} else {
779-
Log_OC.d(
780-
TAG,
781-
"OCFileListFragment not committed, skipping executing " +
782-
"pending transaction"
783-
)
784-
}
785-
}
786-
}
787-
)
764+
if (commitFragment(listOfFiles)) {
765+
fm.executePendingTransactions()
766+
transaction.onOCFileListFragmentComplete(listOfFiles)
767+
}
788768
}
789769
}
790770
}

0 commit comments

Comments
 (0)