mirror of
https://github.com/nextcloud/android.git
synced 2024-11-25 06:35:48 +03:00
Merge pull request #13575 from nextcloud/bugfix/use-activity-when-fragment-added
BugFix - Use Activity When Fragment Added
This commit is contained in:
commit
7dadbc74c4
2 changed files with 21 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ import com.nextcloud.client.account.CurrentAccountProvider
|
|||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.client.network.ConnectivityService
|
||||
import com.nextcloud.utils.extensions.getParcelableArgument
|
||||
import com.nextcloud.utils.extensions.typedActivity
|
||||
import com.nextcloud.utils.fileNameValidator.FileNameValidator
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.databinding.EditBoxDialogBinding
|
||||
|
@ -185,7 +186,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
|
|||
val path = parentFolder?.decryptedRemotePath + newFolderName + OCFile.PATH_SEPARATOR
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
if (connectivityService.isNetworkAndServerAvailable()) {
|
||||
(requireActivity() as ComponentsGetter).fileOperationsHelper.createFolder(path)
|
||||
typedActivity<ComponentsGetter>()?.fileOperationsHelper?.createFolder(path)
|
||||
} else {
|
||||
Log_OC.d(TAG, "Network not available, creating offline operation")
|
||||
fileDataStorageManager.addCreateFolderOfflineOperation(
|
||||
|
@ -196,8 +197,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
|
|||
)
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
val fileDisplayActivity = requireActivity() as? FileDisplayActivity
|
||||
fileDisplayActivity?.syncAndUpdateFolder(true)
|
||||
(requireActivity() as? FileDisplayActivity)?.syncAndUpdateFolder(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue