Added hidden file warning message to the rename file dialog. Resolves #7722

Signed-off-by: William Plefka <wplefka2@illinois.edu>
Signed-off-by: Liam P <89549210+liam-p-23@users.noreply.github.com>
This commit is contained in:
William Plefka 2021-11-07 20:27:19 -05:00 committed by Liam P
parent 169d6a0aae
commit 8d5d7cccc8
3 changed files with 56 additions and 8 deletions

View file

@ -29,7 +29,9 @@ package com.owncloud.android.ui.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
@ -55,7 +57,7 @@ import androidx.fragment.app.DialogFragment;
* Triggers the rename operation when name is confirmed. * Triggers the rename operation when name is confirmed.
*/ */
public class RenameFileDialogFragment public class RenameFileDialogFragment
extends DialogFragment implements DialogInterface.OnClickListener { extends DialogFragment implements DialogInterface.OnClickListener {
private static final String ARG_TARGET_FILE = "TARGET_FILE"; private static final String ARG_TARGET_FILE = "TARGET_FILE";
@ -107,12 +109,40 @@ public class RenameFileDialogFragment
ThemeTextInputUtils.colorTextInput(binding.userInputContainer, ThemeTextInputUtils.colorTextInput(binding.userInputContainer,
binding.userInput, binding.userInput,
ThemeColorUtils.primaryColor(getActivity())); ThemeColorUtils.primaryColor(getActivity()));
int selectionStart = 0;
int extensionStart = mTargetFile.isFolder() ? -1 : currentName.lastIndexOf('.'); binding.userInput.setSelection(0, getSelectionEndIndex(currentName));
int selectionEnd = extensionStart >= 0 ? extensionStart : currentName.length();
binding.userInput.setSelection(Math.min(selectionStart, selectionEnd), Math.max(selectionStart, selectionEnd));
binding.userInput.requestFocus(); binding.userInput.requestFocus();
// Add TextChangedListener to the user input EditText
binding.inputWarningMessage.setText(R.string.hidden_file_name_warning);
binding.userInput.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@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) &&
TextUtils.isEmpty(newFileName.substring(0, getSelectionEndIndex(newFileName))) ) {
binding.inputWarningMessage.setVisibility(View.VISIBLE);
}
else if(binding.inputWarningMessage.getVisibility() == View.VISIBLE) {
binding.inputWarningMessage.setVisibility(View.GONE);
}
}
});
// Build the dialog // Build the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
builder.setView(view) builder.setView(view)
@ -129,6 +159,14 @@ public class RenameFileDialogFragment
return d; return d;
} }
/**
* Calculate the end index of the actual file name (i.e. without the extension)
**/
private int getSelectionEndIndex(String fileName) {
int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf('.');
return extensionStart >= 0 ? extensionStart : fileName.length();
}
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -146,7 +184,6 @@ public class RenameFileDialogFragment
if (!FileUtils.isValidName(newFileName)) { if (!FileUtils.isValidName(newFileName)) {
DisplayUtils.showSnackMessage(requireActivity(), R.string.filename_forbidden_charaters_from_server); DisplayUtils.showSnackMessage(requireActivity(), R.string.filename_forbidden_charaters_from_server);
return; return;
} }
@ -159,4 +196,4 @@ public class RenameFileDialogFragment
super.onDestroyView(); super.onDestroyView();
binding = null; binding = null;
} }
} }

View file

@ -21,7 +21,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="@dimen/standard_padding"> android:padding="@dimen/standard_padding"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/user_input_container" android:id="@+id/user_input_container"
@ -43,4 +44,13 @@
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/input_warning_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/list_item_lastmod_and_filesize_text"
android:textSize="@dimen/two_line_secondary_text_size"
android:visibility="gone"/>
</LinearLayout> </LinearLayout>

View file

@ -779,6 +779,7 @@
<string name="file_rename">Rename</string> <string name="file_rename">Rename</string>
<string name="fab_label">Add or upload</string> <string name="fab_label">Add or upload</string>
<string name="account_creation_failed">Account creation failed</string> <string name="account_creation_failed">Account creation failed</string>
<string name="hidden_file_name_warning">Name will result in a hidden file</string>
<string name="single_sign_on_request_token" formatted="true">Allow %1$s to access your Nextcloud account %2$s?</string> <string name="single_sign_on_request_token" formatted="true">Allow %1$s to access your Nextcloud account %2$s?</string>
<string name="permission_deny">Deny</string> <string name="permission_deny">Deny</string>
<string name="permission_allow">Allow</string> <string name="permission_allow">Allow</string>