Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.29] Fix State Loss Crash For SyncedFolderPreferencesDialogFragment #13102

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
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 @@ -151,7 +151,7 @@ class SyncedFoldersActivity :
lateinit var binding: SyncedFoldersLayoutBinding
lateinit var adapter: SyncedFolderAdapter

private var syncedFolderPreferencesDialogFragment: SyncedFolderPreferencesDialogFragment? = null
private var dialogFragment: SyncedFolderPreferencesDialogFragment? = null
private var path: String? = null
private var type = 0
private var loadJob: Job? = null
Expand Down Expand Up @@ -577,15 +577,26 @@ class SyncedFoldersActivity :
}

override fun onSyncFolderSettingsClick(section: Int, syncedFolderDisplayItem: SyncedFolderDisplayItem) {
val fm = supportFragmentManager
val ft = fm.beginTransaction()
ft.addToBackStack(null)
syncedFolderPreferencesDialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(
if (isFinishing || isDestroyed) {
Log_OC.d(TAG, "Activity destroyed or finished")
return
}

val fragmentTransaction = supportFragmentManager.beginTransaction().apply {
addToBackStack(null)
}

dialogFragment = SyncedFolderPreferencesDialogFragment.newInstance(
syncedFolderDisplayItem,
section
).also {
it.show(ft, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG)
)

if (dialogFragment?.isStateSaved == true) {
Log_OC.d(TAG, "SyncedFolderPreferencesDialogFragment state is saved cannot be shown")
return
}

dialogFragment?.show(fragmentTransaction, SYNCED_FOLDER_PREFERENCES_DIALOG_TAG)
}

override fun onVisibilityToggleClick(section: Int, syncedFolder: SyncedFolderDisplayItem) {
Expand Down Expand Up @@ -620,18 +631,18 @@ class SyncedFoldersActivity :

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_REMOTE_FOLDER &&
resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null
resultCode == RESULT_OK && dialogFragment != null
) {
val chosenFolder: OCFile? = FolderPickerActivity.EXTRA_FOLDER?.let {
data?.getParcelableArgument(it, OCFile::class.java)
}
syncedFolderPreferencesDialogFragment?.setRemoteFolderSummary(chosenFolder?.remotePath)
dialogFragment?.setRemoteFolderSummary(chosenFolder?.remotePath)
} else if (
requestCode == SyncedFolderPreferencesDialogFragment.REQUEST_CODE__SELECT_LOCAL_FOLDER &&
resultCode == RESULT_OK && syncedFolderPreferencesDialogFragment != null
resultCode == RESULT_OK && dialogFragment != null
) {
val localPath = data!!.getStringExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES)
syncedFolderPreferencesDialogFragment!!.setLocalFolderSummary(localPath)
dialogFragment!!.setLocalFolderSummary(localPath)
} else {
super.onActivityResult(requestCode, resultCode, data)
}
Expand Down Expand Up @@ -688,7 +699,7 @@ class SyncedFoldersActivity :

adapter.notifyItemChanged(adapter.getSectionHeaderIndex(syncedFolder.section))
}
syncedFolderPreferencesDialogFragment = null
dialogFragment = null
if (syncedFolder.isEnabled) {
showBatteryOptimizationInfo()
}
Expand Down Expand Up @@ -728,7 +739,7 @@ class SyncedFoldersActivity :
}

override fun onCancelSyncedFolderPreference() {
syncedFolderPreferencesDialogFragment = null
dialogFragment = null
}

override fun onDeleteSyncedFolderPreference(syncedFolder: SyncedFolderParcelable?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
override fun onSaveInstanceState(outState: Bundle) {
outState.putBoolean(BEHAVIOUR_DIALOG_STATE, behaviourDialogShown)
outState.putBoolean(NAME_COLLISION_POLICY_DIALOG_STATE, nameCollisionPolicyDialogShown)
super.onSaveInstanceState(outState)
}

override fun onViewStateRestored(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -523,14 +522,19 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
private const val alphaDisabled = 0.7f

@JvmStatic
fun newInstance(syncedFolder: SyncedFolderDisplayItem?, section: Int): SyncedFolderPreferencesDialogFragment {
requireNotNull(syncedFolder) { "SyncedFolder is mandatory but NULL!" }
val args = Bundle()
args.putParcelable(SYNCED_FOLDER_PARCELABLE, SyncedFolderParcelable(syncedFolder, section))
val dialogFragment = SyncedFolderPreferencesDialogFragment()
dialogFragment.arguments = args
dialogFragment.setStyle(STYLE_NORMAL, R.style.Theme_ownCloud_Dialog)
return dialogFragment
fun newInstance(syncedFolder: SyncedFolderDisplayItem?, section: Int): SyncedFolderPreferencesDialogFragment? {
if (syncedFolder == null) {
return null
}

val args = Bundle().apply {
putParcelable(SYNCED_FOLDER_PARCELABLE, SyncedFolderParcelable(syncedFolder, section))
}

return SyncedFolderPreferencesDialogFragment().apply {
arguments = args
setStyle(STYLE_NORMAL, R.style.Theme_ownCloud_Dialog)
}
}

/**
Expand Down
Loading