Skip to content

Commit

Permalink
Use Activity When Fragment Added
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Sep 16, 2024
1 parent 8320c12 commit 4af24f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Alper Ozturk <[email protected]>
* 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 4af24f1

Please sign in to comment.