mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
rebase to master
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
cb7c47ea54
commit
8c2750a4c1
1 changed files with 32 additions and 7 deletions
|
@ -19,22 +19,28 @@ import android.view.View
|
|||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.common.collect.Sets
|
||||
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.fileNameValidator.FileNameValidator
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.databinding.EditBoxDialogBinding
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.lib.resources.status.OCCapability
|
||||
import com.owncloud.android.ui.activity.ComponentsGetter
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.KeyboardUtils
|
||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
|
@ -55,9 +61,12 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
|
|||
lateinit var keyboardUtils: KeyboardUtils
|
||||
|
||||
@Inject
|
||||
lateinit var currentAccount: CurrentAccountProvider
|
||||
lateinit var connectivityService: ConnectivityService
|
||||
|
||||
private var mParentFolder: OCFile? = null
|
||||
@Inject
|
||||
lateinit var accountProvider: CurrentAccountProvider
|
||||
|
||||
private var parentFolder: OCFile? = null
|
||||
private var positiveButton: MaterialButton? = null
|
||||
|
||||
private lateinit var binding: EditBoxDialogBinding
|
||||
|
@ -92,7 +101,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
|
|||
|
||||
@Suppress("EmptyFunctionBlock")
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
mParentFolder = arguments?.getParcelableArgument(ARG_PARENT_FOLDER, OCFile::class.java)
|
||||
parentFolder = arguments?.getParcelableArgument(ARG_PARENT_FOLDER, OCFile::class.java)
|
||||
|
||||
val inflater = requireActivity().layoutInflater
|
||||
binding = EditBoxDialogBinding.inflate(inflater, null, false)
|
||||
|
@ -121,7 +130,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
|
|||
return builder.create()
|
||||
}
|
||||
|
||||
private fun getOCCapability(): OCCapability = fileDataStorageManager.getCapability(currentAccount.user.accountName)
|
||||
private fun getOCCapability(): OCCapability = fileDataStorageManager.getCapability(accountProvider.user.accountName)
|
||||
|
||||
private fun checkFileNameAfterEachType(fileNames: MutableSet<String>) {
|
||||
val newFileName = binding.userInput.text?.toString()?.trim() ?: ""
|
||||
|
@ -173,14 +182,30 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList
|
|||
return
|
||||
}
|
||||
|
||||
val path = mParentFolder?.decryptedRemotePath + newFolderName + OCFile.PATH_SEPARATOR
|
||||
if (requireActivity() is ComponentsGetter) {
|
||||
(requireActivity() as ComponentsGetter).fileOperationsHelper.createFolder(path)
|
||||
val path = parentFolder?.decryptedRemotePath + newFolderName + OCFile.PATH_SEPARATOR
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
if (connectivityService.isNetworkAndServerAvailable()) {
|
||||
(requireActivity() as ComponentsGetter).fileOperationsHelper.createFolder(path)
|
||||
} else {
|
||||
Log_OC.d(TAG, "Network not available, creating offline operation")
|
||||
fileDataStorageManager.addCreateFolderOfflineOperation(
|
||||
path,
|
||||
newFolderName,
|
||||
parentFolder?.offlineOperationParentPath,
|
||||
parentFolder?.fileId
|
||||
)
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
val fileDisplayActivity = requireActivity() as? FileDisplayActivity
|
||||
fileDisplayActivity?.syncAndUpdateFolder(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "CreateFolderDialogFragment"
|
||||
private const val ARG_PARENT_FOLDER = "PARENT_FOLDER"
|
||||
const val CREATE_FOLDER_FRAGMENT = "CREATE_FOLDER_FRAGMENT"
|
||||
|
||||
|
|
Loading…
Reference in a new issue