Merge pull request #13575 from nextcloud/bugfix/use-activity-when-fragment-added

BugFix - Use Activity When Fragment Added
This commit is contained in:
Alper Öztürk 2024-09-19 11:57:10 +02:00 committed by GitHub
commit 7dadbc74c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View file

@ -0,0 +1,18 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.utils.extensions
import androidx.fragment.app.Fragment
inline fun <reified T : Any> Fragment.typedActivity(): T? {
return if (isAdded && activity != null && activity is T) {
activity as T
} else {
null
}
}

View file

@ -27,6 +27,7 @@ import com.nextcloud.client.account.CurrentAccountProvider
import com.nextcloud.client.di.Injectable import com.nextcloud.client.di.Injectable
import com.nextcloud.client.network.ConnectivityService import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.utils.extensions.getParcelableArgument import com.nextcloud.utils.extensions.getParcelableArgument
import com.nextcloud.utils.extensions.typedActivity
import com.nextcloud.utils.fileNameValidator.FileNameValidator import com.nextcloud.utils.fileNameValidator.FileNameValidator
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.databinding.EditBoxDialogBinding import com.owncloud.android.databinding.EditBoxDialogBinding
@ -185,7 +186,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
val path = parentFolder?.decryptedRemotePath + newFolderName + OCFile.PATH_SEPARATOR val path = parentFolder?.decryptedRemotePath + newFolderName + OCFile.PATH_SEPARATOR
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
if (connectivityService.isNetworkAndServerAvailable()) { if (connectivityService.isNetworkAndServerAvailable()) {
(requireActivity() as ComponentsGetter).fileOperationsHelper.createFolder(path) typedActivity<ComponentsGetter>()?.fileOperationsHelper?.createFolder(path)
} else { } else {
Log_OC.d(TAG, "Network not available, creating offline operation") Log_OC.d(TAG, "Network not available, creating offline operation")
fileDataStorageManager.addCreateFolderOfflineOperation( fileDataStorageManager.addCreateFolderOfflineOperation(
@ -196,8 +197,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
) )
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
val fileDisplayActivity = requireActivity() as? FileDisplayActivity (requireActivity() as? FileDisplayActivity)?.syncAndUpdateFolder(true)
fileDisplayActivity?.syncAndUpdateFolder(true)
} }
} }
} }