|
@@ -1,4 +1,4 @@
|
|
|
-/**
|
|
|
+/*
|
|
|
* ownCloud Android client application
|
|
|
*
|
|
|
* @author David A. Velasco
|
|
@@ -23,16 +23,21 @@ 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.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager.LayoutParams;
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.google.common.collect.Sets;
|
|
|
import com.nextcloud.client.di.Injectable;
|
|
|
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.files.FileUtils;
|
|
|
import com.owncloud.android.ui.activity.ComponentsGetter;
|
|
@@ -41,6 +46,9 @@ import com.owncloud.android.utils.theme.ThemeButtonUtils;
|
|
|
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
|
|
import com.owncloud.android.utils.theme.ThemeTextInputUtils;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
@@ -62,8 +70,10 @@ public class CreateFolderDialogFragment
|
|
|
@Inject ThemeColorUtils themeColorUtils;
|
|
|
@Inject ThemeButtonUtils themeButtonUtils;
|
|
|
@Inject ThemeTextInputUtils themeTextInputUtils;
|
|
|
+ @Inject FileDataStorageManager fileDataStorageManager;
|
|
|
|
|
|
private OCFile mParentFolder;
|
|
|
+ private Button positiveButton;
|
|
|
|
|
|
/**
|
|
|
* Public factory method to create new CreateFolderDialogFragment instances.
|
|
@@ -86,15 +96,18 @@ public class CreateFolderDialogFragment
|
|
|
|
|
|
AlertDialog alertDialog = (AlertDialog) getDialog();
|
|
|
|
|
|
- themeButtonUtils.themeBorderlessButton(themeColorUtils,
|
|
|
- alertDialog.getButton(AlertDialog.BUTTON_POSITIVE),
|
|
|
- alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
|
|
|
+ if (alertDialog != null) {
|
|
|
+ positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
|
|
+
|
|
|
+ themeButtonUtils.themeBorderlessButton(themeColorUtils,
|
|
|
+ positiveButton,
|
|
|
+ alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@NonNull
|
|
|
@Override
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
- int primaryColor = themeColorUtils.primaryColor(getActivity());
|
|
|
mParentFolder = getArguments().getParcelable(ARG_PARENT_FOLDER);
|
|
|
|
|
|
// Inflate the layout for the dialog
|
|
@@ -105,14 +118,66 @@ public class CreateFolderDialogFragment
|
|
|
// Setup layout
|
|
|
binding.userInput.setText("");
|
|
|
binding.userInput.requestFocus();
|
|
|
- themeTextInputUtils.colorTextInput(binding.userInputContainer, binding.userInput, primaryColor);
|
|
|
+ themeTextInputUtils.colorTextInput(binding.userInputContainer,
|
|
|
+ binding.userInput,
|
|
|
+ themeColorUtils.primaryColor(getActivity()),
|
|
|
+ themeColorUtils.primaryAccentColor(getActivity()));
|
|
|
+
|
|
|
+ OCFile parentFolder = requireArguments().getParcelable(ARG_PARENT_FOLDER);
|
|
|
+ List<OCFile> folderContent = fileDataStorageManager.getFolderContent(parentFolder, false);
|
|
|
+ Set<String> fileNames = Sets.newHashSetWithExpectedSize(folderContent.size());
|
|
|
+
|
|
|
+ for (OCFile file : folderContent) {
|
|
|
+ fileNames.add(file.getFileName());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Add TextChangedListener to handle showing/hiding the input warning message
|
|
|
+ binding.userInput.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable s) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!TextUtils.isEmpty(newFileName) && newFileName.charAt(0) == '.') {
|
|
|
+ binding.userInputContainer.setError(getText(R.string.hidden_file_name_warning));
|
|
|
+ } else if (TextUtils.isEmpty(newFileName)) {
|
|
|
+ binding.userInputContainer.setError(getString(R.string.filename_empty));
|
|
|
+ positiveButton.setEnabled(false);
|
|
|
+ } else if (!FileUtils.isValidName(newFileName)) {
|
|
|
+ binding.userInputContainer.setError(getString(R.string.filename_forbidden_charaters_from_server));
|
|
|
+ positiveButton.setEnabled(false);
|
|
|
+ } else if (fileNames.contains(newFileName)) {
|
|
|
+ binding.userInputContainer.setError(getText(R.string.file_already_exists));
|
|
|
+ positiveButton.setEnabled(false);
|
|
|
+ } else if (binding.userInputContainer.getError() != null) {
|
|
|
+ binding.userInputContainer.setError(null);
|
|
|
+ // Called to remove extra padding
|
|
|
+ binding.userInputContainer.setErrorEnabled(false);
|
|
|
+ positiveButton.setEnabled(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
// Build the dialog
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
|
|
builder.setView(view)
|
|
|
- .setPositiveButton(R.string.folder_confirm_create, this)
|
|
|
- .setNeutralButton(R.string.common_cancel, this)
|
|
|
- .setTitle(R.string.uploader_info_dirname);
|
|
|
+ .setPositiveButton(R.string.folder_confirm_create, this)
|
|
|
+ .setNeutralButton(R.string.common_cancel, this)
|
|
|
+ .setTitle(R.string.uploader_info_dirname);
|
|
|
AlertDialog d = builder.create();
|
|
|
|
|
|
Window window = d.getWindow();
|