Procházet zdrojové kódy

Convert to Kotlin

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk před 1 rokem
rodič
revize
5c6439f111

+ 6 - 1
app/src/main/java/com/nextcloud/utils/fileNameValidator/FileNameValidator.kt

@@ -48,7 +48,10 @@ object FileNameValidator {
         }
 
         if (capability.forbiddenFilenames.isTrue &&
-            (reservedWindowsNames.contains(name.uppercase()) || reservedWindowsNames.contains(name.removeFileExtension().uppercase()))
+            (
+                reservedWindowsNames.contains(name.uppercase()) ||
+                    reservedWindowsNames.contains(name.removeFileExtension().uppercase())
+                )
         ) {
             return context.getString(R.string.file_name_validator_error_reserved_names)
         }
@@ -60,6 +63,7 @@ object FileNameValidator {
         return null
     }
 
+    @Suppress("ReturnCount")
     fun checkPath(folderPath: String, filePaths: List<String>, capability: OCCapability, context: Context): Boolean {
         val folderPaths = folderPath.split("/", "\\")
 
@@ -78,6 +82,7 @@ object FileNameValidator {
         return true
     }
 
+    @Suppress("ReturnCount")
     private fun checkInvalidCharacters(name: String, capability: OCCapability, context: Context): String? {
         if (capability.forbiddenFilenameCharacters.isFalse) return null
 

+ 1 - 0
app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt

@@ -154,6 +154,7 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
         listener?.conflictDecisionMade(decision)
     }
 
+    @Suppress("ReturnCount")
     override fun onStart() {
         super.onStart()
         if (account == null) {

+ 0 - 1
app/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.kt

@@ -462,7 +462,6 @@ open class FolderPickerActivity :
                 Handler(Looper.getMainLooper()).postDelayed({
                     setResult(RESULT_CANCELED, resultData)
                     finish()
-
                 }, 1000L)
                 return
             }

+ 134 - 150
app/src/main/java/com/owncloud/android/ui/dialog/RenameFileDialogFragment.kt

@@ -8,214 +8,198 @@
  * SPDX-FileCopyrightText: 2014 David A. Velasco <dvelasco@solidgear.es>
  * SPDX-License-Identifier: GPL-2.0-only AND (AGPL-3.0-or-later OR GPL-2.0-only)
  */
-package com.owncloud.android.ui.dialog;
-
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.LayoutInflater;
-import android.view.View;
-
-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.utils.extensions.BundleExtensionsKt;
-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.resources.status.OCCapability;
-import com.owncloud.android.ui.activity.ComponentsGetter;
-import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.KeyboardUtils;
-import com.owncloud.android.utils.theme.ViewThemeUtils;
-
-import java.util.List;
-import java.util.Set;
-
-import javax.inject.Inject;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AlertDialog;
-import androidx.fragment.app.DialogFragment;
+package com.owncloud.android.ui.dialog
+
+import android.app.Dialog
+import android.content.DialogInterface
+import android.os.Bundle
+import android.text.Editable
+import android.text.TextWatcher
+import android.view.View
+import androidx.appcompat.app.AlertDialog
+import androidx.fragment.app.DialogFragment
+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.utils.extensions.getParcelableArgument
+import com.nextcloud.utils.fileNameValidator.FileNameValidator.isFileHidden
+import com.nextcloud.utils.fileNameValidator.FileNameValidator.isValid
+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.resources.status.OCCapability
+import com.owncloud.android.ui.activity.ComponentsGetter
+import com.owncloud.android.utils.DisplayUtils
+import com.owncloud.android.utils.KeyboardUtils
+import com.owncloud.android.utils.theme.ViewThemeUtils
+import javax.inject.Inject
 
 /**
- *  Dialog to input a new name for an {@link OCFile} being renamed.
- *  Triggers the rename operation.
+ * Dialog to input a new name for an [OCFile] being renamed.
+ * Triggers the rename operation.
  */
-public class RenameFileDialogFragment
-    extends DialogFragment implements DialogInterface.OnClickListener, TextWatcher, Injectable {
+class RenameFileDialogFragment : DialogFragment(), DialogInterface.OnClickListener, TextWatcher, Injectable {
+    @Inject
+    lateinit var viewThemeUtils: ViewThemeUtils
 
-    private static final String ARG_TARGET_FILE = "TARGET_FILE";
-    private static final String ARG_PARENT_FOLDER = "PARENT_FOLDER";
+    @Inject
+    lateinit var fileDataStorageManager: FileDataStorageManager
 
-    @Inject ViewThemeUtils viewThemeUtils;
-    @Inject FileDataStorageManager fileDataStorageManager;
-    @Inject KeyboardUtils keyboardUtils;
-    @Inject CurrentAccountProvider currentAccount;
+    @Inject
+    lateinit var keyboardUtils: KeyboardUtils
 
-    private EditBoxDialogBinding binding;
-    private OCFile mTargetFile;
-    private MaterialButton positiveButton;
-    private Set<String> fileNames;
+    @Inject
+    lateinit var currentAccount: CurrentAccountProvider
 
-    /**
-     * Public factory method to create new RenameFileDialogFragment instances.
-     *
-     * @param file File to rename.
-     * @return Dialog ready to show.
-     */
-    public static RenameFileDialogFragment newInstance(OCFile file, OCFile parentFolder) {
-        RenameFileDialogFragment frag = new RenameFileDialogFragment();
-        Bundle args = new Bundle();
-        args.putParcelable(ARG_TARGET_FILE, file);
-        args.putParcelable(ARG_PARENT_FOLDER, parentFolder);
-        frag.setArguments(args);
-        return frag;
-    }
+    private lateinit var binding: EditBoxDialogBinding
+    private var mTargetFile: OCFile? = null
+    private var positiveButton: MaterialButton? = null
+    private var fileNames: MutableSet<String>? = null
 
-    @Override
-    public void onStart() {
-        super.onStart();
-        initAlertDialog();
+    override fun onStart() {
+        super.onStart()
+        initAlertDialog()
     }
 
-    @Override
-    public void onResume() {
-        super.onResume();
-        keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.userInput);
+    override fun onResume() {
+        super.onResume()
+        keyboardUtils.showKeyboardForEditText(requireDialog().window, binding.userInput)
     }
 
-    @NonNull
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        mTargetFile = BundleExtensionsKt.getParcelableArgument(requireArguments(), ARG_TARGET_FILE, OCFile.class);
-
-        // Inflate the layout for the dialog
-        LayoutInflater inflater = requireActivity().getLayoutInflater();
-        binding = EditBoxDialogBinding.inflate(inflater, null, false);
-        View view = binding.getRoot();
-
-        // Setup layout
-        String currentName = mTargetFile.getFileName();
-        binding.userInput.setText(currentName);
-        viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer);
-        int extensionStart = mTargetFile.isFolder() ? -1 : currentName.lastIndexOf('.');
-        int selectionEnd = extensionStart >= 0 ? extensionStart : currentName.length();
-        binding.userInput.setSelection(0, selectionEnd);
-
-        OCFile parentFolder = BundleExtensionsKt.getParcelableArgument(getArguments(), ARG_PARENT_FOLDER, OCFile.class);
-        List<OCFile> folderContent = fileDataStorageManager.getFolderContent(parentFolder, false);
-        fileNames = Sets.newHashSetWithExpectedSize(folderContent.size());
-
-        for (OCFile file : folderContent) {
-            fileNames.add(file.getFileName());
+    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+        mTargetFile = requireArguments().getParcelableArgument(ARG_TARGET_FILE, OCFile::class.java)
+
+        val inflater = requireActivity().layoutInflater
+        binding = EditBoxDialogBinding.inflate(inflater, null, false)
+
+        val currentName = mTargetFile?.fileName
+        binding.userInput.setText(currentName)
+        viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer)
+        val extensionStart = if (mTargetFile?.isFolder == true) -1 else currentName?.lastIndexOf('.')
+        val selectionEnd = if ((extensionStart ?: -1) >= 0) extensionStart else currentName?.length
+        if (selectionEnd != null) {
+            binding.userInput.setSelection(0, selectionEnd)
         }
 
-        // Add TextChangedListener to handle showing/hiding the input warning message
-        binding.userInput.addTextChangedListener(this);
+        val parentFolder = arguments.getParcelableArgument(ARG_PARENT_FOLDER, OCFile::class.java)
+        val folderContent = fileDataStorageManager.getFolderContent(parentFolder, false)
+        fileNames = Sets.newHashSetWithExpectedSize(folderContent.size)
 
-        // Build the dialog
-        MaterialAlertDialogBuilder builder = buildMaterialAlertDialog(view);
+        for (file in folderContent) {
+            fileNames?.add(file.fileName)
+        }
+
+        binding.userInput.addTextChangedListener(this)
 
-        viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.userInputContainer.getContext(), builder);
+        val builder = buildMaterialAlertDialog(binding.root)
 
-        return builder.create();
+        viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.userInputContainer.context, builder)
+
+        return builder.create()
     }
 
-    private MaterialAlertDialogBuilder buildMaterialAlertDialog(View view) {
-        MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireActivity());
+    private fun buildMaterialAlertDialog(view: View): MaterialAlertDialogBuilder {
+        val builder = MaterialAlertDialogBuilder(requireActivity())
 
         builder
             .setView(view)
             .setPositiveButton(R.string.file_rename, this)
             .setNegativeButton(R.string.common_cancel, this)
-            .setTitle(R.string.rename_dialog_title);
+            .setTitle(R.string.rename_dialog_title)
 
-        return builder;
+        return builder
     }
 
-    private void initAlertDialog() {
-        AlertDialog alertDialog = (AlertDialog) getDialog();
+    private fun initAlertDialog() {
+        val alertDialog = dialog as AlertDialog?
 
         if (alertDialog != null) {
-            positiveButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
-            MaterialButton negativeButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
+            positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton
+            val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as MaterialButton
 
-            viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton);
-            viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton);
+            positiveButton?.let {
+                viewThemeUtils.material.colorMaterialButtonPrimaryTonal(it)
+            }
+            viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton)
         }
     }
 
-    private OCCapability getOCCapability() {
-        return fileDataStorageManager.getCapability(currentAccount.getUser().getAccountName());
-    }
+    private val oCCapability: OCCapability
+        get() = fileDataStorageManager.getCapability(currentAccount.user.accountName)
 
-    @Override
-    public void onClick(DialogInterface dialog, int which) {
+    override fun onClick(dialog: DialogInterface, which: Int) {
         if (which == AlertDialog.BUTTON_POSITIVE) {
-            String newFileName = "";
+            var newFileName = ""
 
-            if (binding.userInput.getText() != null) {
-                newFileName = binding.userInput.getText().toString().trim();
+            if (binding.userInput.text != null) {
+                newFileName = binding.userInput.text.toString().trim { it <= ' ' }
             }
 
-            String errorMessage = FileNameValidator.INSTANCE.isValid(newFileName, getOCCapability(), requireContext(), null);
+            val errorMessage = isValid(newFileName, oCCapability, requireContext(), null)
             if (errorMessage != null) {
-                DisplayUtils.showSnackMessage(requireActivity(), errorMessage);
-                return;
+                DisplayUtils.showSnackMessage(requireActivity(), errorMessage)
+                return
             }
 
-            if (requireActivity() instanceof ComponentsGetter componentsGetter) {
-                componentsGetter.getFileOperationsHelper().renameFile(mTargetFile, newFileName);
+            if (requireActivity() is ComponentsGetter) {
+                val componentsGetter = requireActivity() as ComponentsGetter
+                componentsGetter.getFileOperationsHelper().renameFile(mTargetFile, newFileName)
             }
         }
     }
 
-    @Override
-    public void onDestroyView() {
-        super.onDestroyView();
-        binding = null;
-    }
-
-    @Override
-    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
-    }
+    override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit
 
     /**
      * When user enters a hidden file name, the 'hidden file' message is shown.
      * Otherwise, the message is ensured to be hidden.
      */
-    @Override
-    public void onTextChanged(CharSequence s, int start, int before, int count) {
-        String newFileName = "";
-        if (binding.userInput.getText() != null) {
-            newFileName = binding.userInput.getText().toString().trim();
+    override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
+        var newFileName = ""
+        if (binding.userInput.text != null) {
+            newFileName = binding.userInput.text.toString().trim { it <= ' ' }
         }
 
-        String errorMessage = FileNameValidator.INSTANCE.isValid(newFileName, getOCCapability(), requireContext(), fileNames);
+        val errorMessage = isValid(newFileName, oCCapability, requireContext(), fileNames)
 
-        if (FileNameValidator.INSTANCE.isFileHidden(newFileName)) {
-            binding.userInputContainer.setError(getText(R.string.hidden_file_name_warning));
+        if (isFileHidden(newFileName)) {
+            binding.userInputContainer.error = getText(R.string.hidden_file_name_warning)
         } else if (errorMessage != null) {
-            binding.userInputContainer.setError(errorMessage);
-            positiveButton.setEnabled(false);
-        } else if (binding.userInputContainer.getError() != null) {
-            binding.userInputContainer.setError(null);
+            binding.userInputContainer.error = errorMessage
+            positiveButton?.isEnabled = false
+        } else if (binding.userInputContainer.error != null) {
+            binding.userInputContainer.error = null
             // Called to remove extra padding
-            binding.userInputContainer.setErrorEnabled(false);
-            positiveButton.setEnabled(true);
+            binding.userInputContainer.isErrorEnabled = false
+            positiveButton?.isEnabled = true
         }
     }
 
-    @Override
-    public void afterTextChanged(Editable s) {
+    override fun afterTextChanged(s: Editable) = Unit
+
+    companion object {
+        private const val ARG_TARGET_FILE = "TARGET_FILE"
+        private const val ARG_PARENT_FOLDER = "PARENT_FOLDER"
+
+        /**
+         * Public factory method to create new RenameFileDialogFragment instances.
+         *
+         * @param file File to rename.
+         * @return Dialog ready to show.
+         */
+        @JvmStatic
+        fun newInstance(file: OCFile?, parentFolder: OCFile?): RenameFileDialogFragment {
+            val bundle = Bundle().apply {
+                putParcelable(ARG_TARGET_FILE, file)
+                putParcelable(ARG_PARENT_FOLDER, parentFolder)
+            }
 
+            return RenameFileDialogFragment().apply {
+                arguments = bundle
+            }
+        }
     }
 }

+ 81 - 87
app/src/main/java/com/owncloud/android/ui/dialog/RenamePublicShareDialogFragment.kt

@@ -5,122 +5,116 @@
  * SPDX-FileCopyrightText: 2020 Nextcloud GmbH
  * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
  */
-package com.owncloud.android.ui.dialog;
-
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-
-import com.google.android.material.button.MaterialButton;
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-import com.nextcloud.client.di.Injectable;
-import com.nextcloud.utils.extensions.BundleExtensionsKt;
-import com.owncloud.android.R;
-import com.owncloud.android.databinding.EditBoxDialogBinding;
-import com.owncloud.android.lib.resources.shares.OCShare;
-import com.owncloud.android.ui.activity.ComponentsGetter;
-import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.KeyboardUtils;
-import com.owncloud.android.utils.theme.ViewThemeUtils;
-
-import javax.inject.Inject;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AlertDialog;
-import androidx.fragment.app.DialogFragment;
+package com.owncloud.android.ui.dialog
+
+import android.app.Dialog
+import android.content.DialogInterface
+import android.os.Bundle
+import android.text.TextUtils
+import android.view.View
+import androidx.appcompat.app.AlertDialog
+import androidx.fragment.app.DialogFragment
+import com.google.android.material.button.MaterialButton
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import com.nextcloud.client.di.Injectable
+import com.nextcloud.utils.extensions.getParcelableArgument
+import com.owncloud.android.R
+import com.owncloud.android.databinding.EditBoxDialogBinding
+import com.owncloud.android.lib.resources.shares.OCShare
+import com.owncloud.android.ui.activity.ComponentsGetter
+import com.owncloud.android.utils.DisplayUtils
+import com.owncloud.android.utils.KeyboardUtils
+import com.owncloud.android.utils.theme.ViewThemeUtils
+import javax.inject.Inject
 
 /**
  * Dialog to rename a public share.
  */
-public class RenamePublicShareDialogFragment
-    extends DialogFragment implements DialogInterface.OnClickListener, Injectable {
+class RenamePublicShareDialogFragment : DialogFragment(), DialogInterface.OnClickListener, Injectable {
+    @Inject
+    lateinit var viewThemeUtils: ViewThemeUtils
 
-    private static final String ARG_PUBLIC_SHARE = "PUBLIC_SHARE";
+    @Inject
+    lateinit var keyboardUtils: KeyboardUtils
 
-    @Inject ViewThemeUtils viewThemeUtils;
-    @Inject KeyboardUtils keyboardUtils;
+    private lateinit var binding: EditBoxDialogBinding
+    private var publicShare: OCShare? = null
 
-    private EditBoxDialogBinding binding;
-    private OCShare publicShare;
+    override fun onStart() {
+        super.onStart()
 
-    public static RenamePublicShareDialogFragment newInstance(OCShare share) {
-        RenamePublicShareDialogFragment frag = new RenamePublicShareDialogFragment();
-        Bundle args = new Bundle();
-        args.putParcelable(ARG_PUBLIC_SHARE, share);
-        frag.setArguments(args);
-        return frag;
-    }
+        val alertDialog = dialog as AlertDialog? ?: return
 
-    @Override
-    public void onStart() {
-        super.onStart();
+        val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE) as? MaterialButton
+        val negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE) as? MaterialButton
 
-        AlertDialog alertDialog = (AlertDialog) getDialog();
+        positiveButton?.let {
+            viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton)
+        }
 
-        if (alertDialog != null) {
-            MaterialButton positiveButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
-            MaterialButton negativeButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
-            viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton);
-            viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton);
+        negativeButton?.let {
+            viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton)
         }
     }
 
-    @Override
-    public void onResume() {
-        super.onResume();
-        keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.userInput);
+    override fun onResume() {
+        super.onResume()
+        keyboardUtils.showKeyboardForEditText(requireDialog().window, binding.userInput)
     }
 
-    @NonNull
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        publicShare = BundleExtensionsKt.getParcelableArgument(requireArguments(), ARG_PUBLIC_SHARE, OCShare.class);
+    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+        publicShare = requireArguments().getParcelableArgument(ARG_PUBLIC_SHARE, OCShare::class.java)
 
-        // Inflate the layout for the dialog
-        LayoutInflater inflater = requireActivity().getLayoutInflater();
-        binding = EditBoxDialogBinding.inflate(inflater, null, false);
-        View view = binding.getRoot();
+        val inflater = requireActivity().layoutInflater
+        binding = EditBoxDialogBinding.inflate(inflater, null, false)
+        val view: View = binding.root
 
-        // Setup layout
-        viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer);
-        binding.userInput.setText(publicShare.getLabel());
+        viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer)
+        binding.userInput.setText(publicShare?.label)
 
-        // Build the dialog
-        MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(view.getContext());
-        builder.setView(view)
+        val builder = MaterialAlertDialogBuilder(view.context)
+            .setView(view)
             .setPositiveButton(R.string.file_rename, this)
             .setNegativeButton(R.string.common_cancel, this)
-            .setTitle(R.string.public_share_name);
+            .setTitle(R.string.public_share_name)
 
-        viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.userInput.getContext(), builder);
+        viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.userInput.context, builder)
 
-        return builder.create();
+        return builder.create()
     }
 
-    @Override
-    public void onClick(DialogInterface dialog, int which) {
-        if (which == AlertDialog.BUTTON_POSITIVE) {
-            String newName = "";
-            if (binding.userInput.getText() != null) {
-                newName = binding.userInput.getText().toString().trim();
+    override fun onClick(dialog: DialogInterface, which: Int) {
+        when (which) {
+            AlertDialog.BUTTON_POSITIVE -> {
+                var newName = ""
+                if (binding.userInput.text != null) {
+                    newName = binding.userInput.text.toString().trim { it <= ' ' }
+                }
+
+                if (TextUtils.isEmpty(newName)) {
+                    DisplayUtils.showSnackMessage(requireActivity(), R.string.label_empty)
+                    return
+                }
+
+                (requireActivity() as ComponentsGetter).fileOperationsHelper.setLabelToPublicShare(
+                    publicShare,
+                    newName
+                )
             }
+        }
+    }
 
-            if (TextUtils.isEmpty(newName)) {
-                DisplayUtils.showSnackMessage(requireActivity(), R.string.label_empty);
-                return;
+    companion object {
+        private const val ARG_PUBLIC_SHARE = "PUBLIC_SHARE"
+
+        fun newInstance(share: OCShare?): RenamePublicShareDialogFragment {
+            val bundle = Bundle().apply {
+                putParcelable(ARG_PUBLIC_SHARE, share)
             }
 
-            ((ComponentsGetter) requireActivity()).getFileOperationsHelper().setLabelToPublicShare(publicShare,
-                                                                                                   newName);
+            return RenamePublicShareDialogFragment().apply {
+                arguments = bundle
+            }
         }
     }
-
-    @Override
-    public void onDestroyView() {
-        super.onDestroyView();
-        binding = null;
-    }
 }