Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 58810e2c authored by Martin Brabham's avatar Martin Brabham Committed by Matt Garnes
Browse files

Add character limit for name input dialog.

Change-Id: I75539bbe90dbc278b360e1246c5218101d77abf7
(cherry picked from commit d34dfc68)
(cherry picked from commit 1ca38c45)
parent 860ef9fb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
    android:imeOptions="actionDone|flagNoFullscreen"
    android:scrollHorizontally="true"
    android:selectAllOnFocus="true"
    android:maxLength="255"
    android:inputType="textNoSuggestions">
    <requestFocus />
  </EditText>
+2 −0
Original line number Diff line number Diff line
@@ -507,6 +507,8 @@
    <string name="input_name_dialog_message_empty_name">The name cannot be empty.</string>
    <!-- Enter Name Dialog - Message - Invalid name -->
    <string name="input_name_dialog_message_invalid_path_name">Invalid name. The characters \'<xliff:g id="invalid_characters">%1$s</xliff:g>\' are not allowed.</string>
    <!-- Enter Name Dialog - Message - Invalid name length -->
    <string name="input_name_dialog_message_invalid_name_length">File name is too long, please consider something 255 characters or less.</string>
    <!-- Enter Name Dialog - Message - Invalid name -->
    <string name="input_name_dialog_message_invalid_name">Invalid name. The names \'.\' and \'..\' are not allowed.</string>
    <!-- Enter Name Dialog - Message - Name exists -->
+18 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
@@ -43,6 +44,8 @@ import java.util.List;
public class InputNameDialog
    implements TextWatcher, DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {

    private static final int FILENAME_CHAR_LIMIT = 255;

    private final Context mContext;
    /**
     * @hide
@@ -249,21 +252,31 @@ public class InputNameDialog
     * @hide
     */
    void checkName(String name) {

        //The name is empty
        if (name.length() == 0) {
        if (TextUtils.isEmpty(name)) {
            setMsg(
                InputNameDialog.this.mContext.getString(
                      R.string.input_name_dialog_message_empty_name), false);
            return;
        }

        // Too long
        if (name.length() > FILENAME_CHAR_LIMIT) {
            setMsg(InputNameDialog.this.mContext.getString(
                    R.string.input_name_dialog_message_invalid_name_length), false);
            return;
        }

        // The path is invalid
        if (name.indexOf(File.separator) != -1) {
        if (name.contains(File.separator)) {
            setMsg(
                InputNameDialog.this.mContext.getString(
                      R.string.input_name_dialog_message_invalid_path_name,
                      File.separator), false);
            return;
        }

        // No allow . or ..
        if (name.compareTo(FileHelper.CURRENT_DIRECTORY) == 0 ||
                name.compareTo(FileHelper.PARENT_DIRECTORY) == 0) {
@@ -272,11 +285,13 @@ public class InputNameDialog
                        R.string.input_name_dialog_message_invalid_name), false);
            return;
        }

        // The same name
        if (this.mFso != null && !this.mAllowFsoName && name.compareTo(this.mFso.getName()) == 0) {
            setMsg(null, false);
            return;
        }

        // Name exists
        if (FileHelper.isNameExists(this.mFiles, name)) {
            setMsg(
@@ -287,6 +302,7 @@ public class InputNameDialog

        //Valid name
        setMsg(null, true);

    }

    /**