Search in sources :

Example 1 with ThemedActivity

use of com.amaze.filemanager.ui.activities.superclasses.ThemedActivity in project AmazeFileManager by TeamAmaze.

the class GeneralDialogCreation method showPropertiesDialog.

private static void showPropertiesDialog(@NonNull final HybridFileParcelable baseFile, @NonNull ThemedActivity themedActivity, @Nullable MainFragment mainFragment, @Nullable final String permissions, boolean isRoot, @NonNull AppTheme appTheme, boolean forStorage) {
    final ExecutorService executor = Executors.newFixedThreadPool(3);
    final Context c = themedActivity.getApplicationContext();
    int accentColor = themedActivity.getAccent();
    long last = baseFile.getDate();
    final String date = Utils.getDate(themedActivity, last), items = c.getString(R.string.calculating), name = baseFile.getName(c), parent = baseFile.getReadablePath(baseFile.getParent(c));
    File nomediaFile = baseFile.isDirectory() ? new File(baseFile.getPath() + "/" + FileUtils.NOMEDIA_FILE) : null;
    MaterialDialog.Builder builder = new MaterialDialog.Builder(themedActivity);
    builder.title(c.getString(R.string.properties));
    builder.theme(appTheme.getMaterialDialogTheme());
    View v = themedActivity.getLayoutInflater().inflate(R.layout.properties_dialog, null);
    TextView itemsText = v.findViewById(R.id.t7);
    CheckBox nomediaCheckBox = v.findViewById(R.id.nomediacheckbox);
    /*View setup*/
    {
        TextView mNameTitle = v.findViewById(R.id.title_name);
        mNameTitle.setTextColor(accentColor);
        TextView mDateTitle = v.findViewById(R.id.title_date);
        mDateTitle.setTextColor(accentColor);
        TextView mSizeTitle = v.findViewById(R.id.title_size);
        mSizeTitle.setTextColor(accentColor);
        TextView mLocationTitle = v.findViewById(R.id.title_location);
        mLocationTitle.setTextColor(accentColor);
        TextView md5Title = v.findViewById(R.id.title_md5);
        md5Title.setTextColor(accentColor);
        TextView sha256Title = v.findViewById(R.id.title_sha256);
        sha256Title.setTextColor(accentColor);
        ((TextView) v.findViewById(R.id.t5)).setText(name);
        ((TextView) v.findViewById(R.id.t6)).setText(parent);
        itemsText.setText(items);
        ((TextView) v.findViewById(R.id.t8)).setText(date);
        if (baseFile.isDirectory() && baseFile.isLocal()) {
            nomediaCheckBox.setVisibility(View.VISIBLE);
            if (nomediaFile != null) {
                nomediaCheckBox.setChecked(nomediaFile.exists());
            }
        }
        LinearLayout mNameLinearLayout = v.findViewById(R.id.properties_dialog_name);
        LinearLayout mLocationLinearLayout = v.findViewById(R.id.properties_dialog_location);
        LinearLayout mSizeLinearLayout = v.findViewById(R.id.properties_dialog_size);
        LinearLayout mDateLinearLayout = v.findViewById(R.id.properties_dialog_date);
        // setting click listeners for long press
        mNameLinearLayout.setOnLongClickListener(v1 -> {
            FileUtils.copyToClipboard(c, name);
            Toast.makeText(c, c.getString(R.string.name) + " " + c.getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
        mLocationLinearLayout.setOnLongClickListener(v12 -> {
            FileUtils.copyToClipboard(c, parent);
            Toast.makeText(c, c.getString(R.string.location) + " " + c.getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
        mSizeLinearLayout.setOnLongClickListener(v13 -> {
            FileUtils.copyToClipboard(c, items);
            Toast.makeText(c, c.getString(R.string.size) + " " + c.getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
        mDateLinearLayout.setOnLongClickListener(v14 -> {
            FileUtils.copyToClipboard(c, date);
            Toast.makeText(c, c.getString(R.string.date) + " " + c.getString(R.string.properties_copied_clipboard), Toast.LENGTH_SHORT).show();
            return false;
        });
    }
    CountItemsOrAndSizeTask countItemsOrAndSizeTask = new CountItemsOrAndSizeTask(c, itemsText, baseFile, forStorage);
    countItemsOrAndSizeTask.executeOnExecutor(executor);
    GenerateHashesTask hashGen = new GenerateHashesTask(baseFile, c, v);
    hashGen.executeOnExecutor(executor);
    /*Chart creation and data loading*/
    {
        boolean isRightToLeft = c.getResources().getBoolean(R.bool.is_right_to_left);
        boolean isDarkTheme = appTheme.getMaterialDialogTheme() == Theme.DARK;
        PieChart chart = v.findViewById(R.id.chart);
        chart.setTouchEnabled(false);
        chart.setDrawEntryLabels(false);
        chart.setDescription(null);
        chart.setNoDataText(c.getString(R.string.loading));
        chart.setRotationAngle(!isRightToLeft ? 0f : 180f);
        chart.setHoleColor(Color.TRANSPARENT);
        chart.setCenterTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
        chart.getLegend().setEnabled(true);
        chart.getLegend().setForm(Legend.LegendForm.CIRCLE);
        chart.getLegend().setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        chart.getLegend().setTypeface(Typeface.create("sans-serif-medium", Typeface.NORMAL));
        chart.getLegend().setTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
        chart.animateY(1000);
        if (forStorage) {
            final String[] LEGENDS = new String[] { c.getString(R.string.used), c.getString(R.string.free) };
            final int[] COLORS = { Utils.getColor(c, R.color.piechart_red), Utils.getColor(c, R.color.piechart_green) };
            long totalSpace = baseFile.getTotal(c), freeSpace = baseFile.getUsableSpace(), usedSpace = totalSpace - freeSpace;
            List<PieEntry> entries = new ArrayList<>();
            entries.add(new PieEntry(usedSpace, LEGENDS[0]));
            entries.add(new PieEntry(freeSpace, LEGENDS[1]));
            PieDataSet set = new PieDataSet(entries, null);
            set.setColors(COLORS);
            set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
            set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
            set.setSliceSpace(5f);
            set.setAutomaticallyDisableSliceSpacing(true);
            set.setValueLinePart2Length(1.05f);
            set.setSelectionShift(0f);
            PieData pieData = new PieData(set);
            pieData.setValueFormatter(new SizeFormatter(c));
            pieData.setValueTextColor(isDarkTheme ? Color.WHITE : Color.BLACK);
            String totalSpaceFormatted = Formatter.formatFileSize(c, totalSpace);
            chart.setCenterText(new SpannableString(c.getString(R.string.total) + "\n" + totalSpaceFormatted));
            chart.setData(pieData);
        } else {
            LoadFolderSpaceDataTask loadFolderSpaceDataTask = new LoadFolderSpaceDataTask(c, appTheme, chart, baseFile);
            loadFolderSpaceDataTask.executeOnExecutor(executor);
        }
        chart.invalidate();
    }
    if (!forStorage && permissions != null && mainFragment != null) {
        AppCompatButton appCompatButton = v.findViewById(R.id.permissionsButton);
        appCompatButton.setAllCaps(true);
        final View permissionsTable = v.findViewById(R.id.permtable);
        final View button = v.findViewById(R.id.set);
        if (isRoot && permissions.length() > 6) {
            appCompatButton.setVisibility(View.VISIBLE);
            appCompatButton.setOnClickListener(v15 -> {
                if (permissionsTable.getVisibility() == View.GONE) {
                    permissionsTable.setVisibility(View.VISIBLE);
                    button.setVisibility(View.VISIBLE);
                    setPermissionsDialog(permissionsTable, button, baseFile, permissions, c, mainFragment);
                } else {
                    button.setVisibility(View.GONE);
                    permissionsTable.setVisibility(View.GONE);
                }
            });
        }
    }
    builder.customView(v, true);
    builder.positiveText(themedActivity.getString(R.string.ok));
    builder.positiveColor(accentColor);
    builder.dismissListener(dialog -> executor.shutdown());
    builder.onPositive((dialog, which) -> {
        if (baseFile.isDirectory() && nomediaFile != null) {
            if (nomediaCheckBox.isChecked()) {
                // checkbox is checked, create .nomedia
                try {
                    if (!nomediaFile.createNewFile()) {
                        // failed operation
                        Log.w(TAG, "'.nomedia' file creation in " + baseFile.getPath() + " failed!");
                    }
                } catch (IOException e) {
                    Log.e(TAG, "Error creating file", e);
                }
            } else {
                // checkbox is unchecked, delete .nomedia
                if (!nomediaFile.delete()) {
                    // failed operation
                    Log.w(TAG, "'.nomedia' file deletion in " + baseFile.getPath() + " failed!");
                }
            }
        }
    });
    MaterialDialog materialDialog = builder.build();
    materialDialog.show();
    materialDialog.getActionButton(DialogAction.NEGATIVE).setEnabled(false);
/*
    View bottomSheet = c.findViewById(R.id.design_bottom_sheet);
    BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
    bottomSheetBehavior.setPeekHeight(BottomSheetBehavior.STATE_DRAGGING);
    */
}
Also used : RequiresApi(androidx.annotation.RequiresApi) LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) FileProperties(com.amaze.filemanager.filesystem.FileProperties) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) SortHandler(com.amaze.filemanager.database.SortHandler) MDButton(com.afollestad.materialdialogs.internal.MDButton) CompressedHelper(com.amaze.filemanager.filesystem.compressed.CompressedHelper) GeneralSecurityException(java.security.GeneralSecurityException) RootHelper(com.amaze.filemanager.filesystem.RootHelper) CheckBox(android.widget.CheckBox) View(android.view.View) Button(android.widget.Button) DialogSigninWithGoogleBinding(com.amaze.filemanager.databinding.DialogSigninWithGoogleBinding) PieChart(com.github.mikephil.charting.charts.PieChart) Log(android.util.Log) PieData(com.github.mikephil.charting.data.PieData) LoadFolderSpaceDataTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFolderSpaceDataTask) M(android.os.Build.VERSION_CODES.M) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) AsyncTask(android.os.AsyncTask) Entry(com.github.mikephil.charting.data.Entry) Set(java.util.Set) InputType(android.text.InputType) ExtensionsKt(com.amaze.filemanager.ui.ExtensionsKt) FingerprintManager(android.hardware.fingerprint.FingerprintManager) FileUtils(com.amaze.filemanager.filesystem.files.FileUtils) AppCompatButton(androidx.appcompat.widget.AppCompatButton) Executors(java.util.concurrent.Executors) EncryptDecryptUtils(com.amaze.filemanager.filesystem.files.EncryptDecryptUtils) Objects(java.util.Objects) FileUtils.toHybridFileArrayList(com.amaze.filemanager.filesystem.files.FileUtils.toHybridFileArrayList) List(java.util.List) StringRes(androidx.annotation.StringRes) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) HiddenAdapter(com.amaze.filemanager.adapters.HiddenAdapter) PREFERENCE_SORTBY_ONLY_THIS(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SORTBY_ONLY_THIS) R(com.amaze.filemanager.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CountItemsOrAndSizeTask(com.amaze.filemanager.asynchronous.asynctasks.CountItemsOrAndSizeTask) AppTheme(com.amaze.filemanager.ui.theme.AppTheme) AppConfig(com.amaze.filemanager.application.AppConfig) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) Legend(com.github.mikephil.charting.components.Legend) TextWatcher(android.text.TextWatcher) Typeface(android.graphics.Typeface) Context(android.content.Context) TextInputEditText(com.google.android.material.textfield.TextInputEditText) IValueFormatter(com.github.mikephil.charting.formatter.IValueFormatter) HybridFile(com.amaze.filemanager.filesystem.HybridFile) FingerprintHandler(com.amaze.filemanager.utils.FingerprintHandler) Intent(android.content.Intent) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) Sort(com.amaze.filemanager.database.models.explorer.Sort) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WarnableTextInputLayout(com.amaze.filemanager.ui.views.WarnableTextInputLayout) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ShellNotRunningException(com.amaze.filemanager.file_operations.exceptions.ShellNotRunningException) PreferencesConstants(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants) DataUtils(com.amaze.filemanager.utils.DataUtils) Toast(android.widget.Toast) Build(android.os.Build) ExecutorService(java.util.concurrent.ExecutorService) Formatter(android.text.format.Formatter) GenerateHashesTask(com.amaze.filemanager.asynchronous.asynctasks.GenerateHashesTask) SpannableString(android.text.SpannableString) LayoutInflater(android.view.LayoutInflater) IOException(java.io.IOException) DialogAction(com.afollestad.materialdialogs.DialogAction) TextUtils(android.text.TextUtils) ChangeFilePermissionsCommand(com.amaze.filemanager.filesystem.root.ChangeFilePermissionsCommand) WarnableTextInputValidator(com.amaze.filemanager.ui.views.WarnableTextInputValidator) File(java.io.File) Theme(com.afollestad.materialdialogs.Theme) Color(android.graphics.Color) Utils(com.amaze.filemanager.utils.Utils) SharedPreferences(android.content.SharedPreferences) CryptUtil(com.amaze.filemanager.filesystem.files.CryptUtil) ViewPortHandler(com.github.mikephil.charting.utils.ViewPortHandler) EncryptService(com.amaze.filemanager.asynchronous.services.EncryptService) ThemedActivity(com.amaze.filemanager.ui.activities.superclasses.ThemedActivity) PreferenceManager(androidx.preference.PreferenceManager) PieEntry(com.github.mikephil.charting.data.PieEntry) Collections(java.util.Collections) EditText(android.widget.EditText) PieEntry(com.github.mikephil.charting.data.PieEntry) SpannableString(android.text.SpannableString) PieChart(com.github.mikephil.charting.charts.PieChart) PieDataSet(com.github.mikephil.charting.data.PieDataSet) TextView(android.widget.TextView) FileUtils.toHybridFileArrayList(com.amaze.filemanager.filesystem.files.FileUtils.toHybridFileArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Context(android.content.Context) GenerateHashesTask(com.amaze.filemanager.asynchronous.asynctasks.GenerateHashesTask) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) IOException(java.io.IOException) View(android.view.View) TextView(android.widget.TextView) CountItemsOrAndSizeTask(com.amaze.filemanager.asynchronous.asynctasks.CountItemsOrAndSizeTask) AppCompatButton(androidx.appcompat.widget.AppCompatButton) SpannableString(android.text.SpannableString) LoadFolderSpaceDataTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFolderSpaceDataTask) CheckBox(android.widget.CheckBox) ExecutorService(java.util.concurrent.ExecutorService) PieData(com.github.mikephil.charting.data.PieData) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Example 2 with ThemedActivity

use of com.amaze.filemanager.ui.activities.superclasses.ThemedActivity in project AmazeFileManager by TeamAmaze.

the class SmbConnectDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final boolean edit = getArguments().getBoolean("edit", false);
    final String path = getArguments().getString("path");
    final String name = getArguments().getString("name");
    context = getActivity();
    emptyAddress = getString(R.string.cant_be_empty, getString(R.string.ip));
    emptyName = getString(R.string.cant_be_empty, getString(R.string.connection_name));
    invalidDomain = getString(R.string.invalid, getString(R.string.domain));
    invalidUsername = getString(R.string.invalid, getString(R.string.username).toLowerCase());
    if (getActivity() instanceof SmbConnectionListener) {
        smbConnectionListener = (SmbConnectionListener) getActivity();
    }
    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    final MaterialDialog.Builder ba3 = new MaterialDialog.Builder(context);
    ba3.title((R.string.smb_connection));
    ba3.autoDismiss(false);
    final View v2 = getActivity().getLayoutInflater().inflate(R.layout.smb_dialog, null);
    final TextInputLayout connectionTIL = v2.findViewById(R.id.connectionTIL);
    final TextInputLayout ipTIL = v2.findViewById(R.id.ipTIL);
    final TextInputLayout domainTIL = v2.findViewById(R.id.domainTIL);
    final TextInputLayout usernameTIL = v2.findViewById(R.id.usernameTIL);
    final TextInputLayout passwordTIL = v2.findViewById(R.id.passwordTIL);
    final AppCompatEditText conName = v2.findViewById(R.id.connectionET);
    ExtensionsKt.makeRequired(connectionTIL);
    ExtensionsKt.makeRequired(ipTIL);
    ExtensionsKt.makeRequired(usernameTIL);
    ExtensionsKt.makeRequired(passwordTIL);
    conName.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (conName.getText().toString().length() == 0)
                connectionTIL.setError(emptyName);
            else
                connectionTIL.setError("");
        }
    });
    final AppCompatEditText ip = v2.findViewById(R.id.ipET);
    ip.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (ip.getText().toString().length() == 0)
                ipTIL.setError(emptyAddress);
            else
                ipTIL.setError("");
        }
    });
    final AppCompatEditText share = v2.findViewById(R.id.shareET);
    final AppCompatEditText domain = v2.findViewById(R.id.domainET);
    domain.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (domain.getText().toString().contains(";"))
                domainTIL.setError(invalidDomain);
            else
                domainTIL.setError("");
        }
    });
    final AppCompatEditText user = v2.findViewById(R.id.usernameET);
    user.addTextChangedListener(new SimpleTextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (user.getText().toString().contains(":"))
                usernameTIL.setError(invalidUsername);
            else
                usernameTIL.setError("");
        }
    });
    int accentColor = ((ThemedActivity) getActivity()).getAccent();
    final AppCompatEditText pass = v2.findViewById(R.id.passwordET);
    final AppCompatCheckBox chkSmbAnonymous = v2.findViewById(R.id.chkSmbAnonymous);
    final AppCompatCheckBox chkSmbDisableIpcSignature = v2.findViewById(R.id.chkSmbDisableIpcSignature);
    TextView help = v2.findViewById(R.id.wanthelp);
    EditTextColorStateUtil.setTint(context, conName, accentColor);
    EditTextColorStateUtil.setTint(context, user, accentColor);
    EditTextColorStateUtil.setTint(context, pass, accentColor);
    Utils.setTint(context, chkSmbAnonymous, accentColor);
    help.setOnClickListener(v -> {
        int accentColor1 = ((ThemedActivity) getActivity()).getAccent();
        GeneralDialogCreation.showSMBHelpDialog(context, accentColor1);
    });
    chkSmbAnonymous.setOnClickListener(view -> {
        if (chkSmbAnonymous.isChecked()) {
            user.setEnabled(false);
            pass.setEnabled(false);
        } else {
            user.setEnabled(true);
            pass.setEnabled(true);
        }
    });
    if (edit) {
        String userp = "";
        String passp = "";
        String ipp = "";
        String domainp = "";
        String sharep = "";
        conName.setText(name);
        try {
            URL a = new URL(path);
            String userinfo = a.getUserInfo();
            if (userinfo != null) {
                String inf = URLDecoder.decode(userinfo, "UTF-8");
                int domainDelim = !inf.contains(";") ? 0 : inf.indexOf(';');
                domainp = inf.substring(0, domainDelim);
                if (domainp != null && domainp.length() > 0)
                    inf = inf.substring(domainDelim + 1);
                userp = inf.substring(0, inf.indexOf(":"));
                passp = inf.substring(inf.indexOf(":") + 1, inf.length());
                domain.setText(domainp);
                user.setText(userp);
                pass.setText(passp);
            } else {
                chkSmbAnonymous.setChecked(true);
            }
            ipp = a.getHost();
            sharep = a.getPath().replaceFirst("/", "").replaceAll("/$", "");
            ip.setText(ipp);
            share.setText(sharep);
            UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(path);
            if (sanitizer.hasParameter(PARAM_DISABLE_IPC_SIGNING_CHECK)) {
                chkSmbDisableIpcSignature.setChecked(Boolean.parseBoolean(sanitizer.getValue(PARAM_DISABLE_IPC_SIGNING_CHECK)));
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    } else if (path != null && path.length() > 0) {
        conName.setText(name);
        ip.setText(path);
        user.requestFocus();
    } else {
        conName.setText(R.string.smb_connection);
        conName.requestFocus();
    }
    ba3.customView(v2, true);
    ba3.theme(utilsProvider.getAppTheme().getMaterialDialogTheme());
    ba3.neutralText(R.string.cancel);
    ba3.positiveText(R.string.create);
    if (edit)
        ba3.negativeText(R.string.delete);
    ba3.positiveColor(accentColor).negativeColor(accentColor).neutralColor(accentColor);
    ba3.onPositive((dialog, which) -> {
        String[] s;
        String ipa = ip.getText().toString();
        String con_nam = conName.getText().toString();
        String sDomain = domain.getText().toString();
        String sShare = share.getText().toString();
        String username = user.getText().toString();
        TextInputLayout firstInvalidField = null;
        if (con_nam == null || con_nam.length() == 0) {
            connectionTIL.setError(emptyName);
            firstInvalidField = connectionTIL;
        }
        if (ipa == null || ipa.length() == 0) {
            ipTIL.setError(emptyAddress);
            if (firstInvalidField == null)
                firstInvalidField = ipTIL;
        }
        if (sDomain.contains(";")) {
            domainTIL.setError(invalidDomain);
            if (firstInvalidField == null)
                firstInvalidField = domainTIL;
        }
        if (username.contains(":")) {
            usernameTIL.setError(invalidUsername);
            if (firstInvalidField == null)
                firstInvalidField = usernameTIL;
        }
        if (firstInvalidField != null) {
            firstInvalidField.requestFocus();
            return;
        }
        SmbFile smbFile;
        String domaind = domain.getText().toString();
        if (chkSmbAnonymous.isChecked())
            smbFile = createSMBPath(new String[] { ipa, "", "", domaind, sShare }, true, false);
        else {
            String useraw = user.getText().toString();
            String useru = useraw.replaceAll(" ", "\\ ");
            String passp = pass.getText().toString();
            smbFile = createSMBPath(new String[] { ipa, useru, passp, domaind, sShare }, false, false);
        }
        if (smbFile == null)
            return;
        StringBuilder extraParams = new StringBuilder();
        if (chkSmbDisableIpcSignature.isChecked())
            extraParams.append(PARAM_DISABLE_IPC_SIGNING_CHECK).append('=').append(true);
        try {
            s = new String[] { conName.getText().toString(), SmbUtil.getSmbEncryptedPath(getActivity(), smbFile.getPath()) };
        } catch (GeneralSecurityException | IOException e) {
            e.printStackTrace();
            Toast.makeText(getActivity(), getString(R.string.error), Toast.LENGTH_LONG).show();
            return;
        }
        if (smbConnectionListener != null) {
            // encrypted path means path with encrypted pass
            String qs = extraParams.length() > 0 ? extraParams.insert(0, '?').toString() : "";
            smbConnectionListener.addConnection(edit, s[0], smbFile.getPath() + qs, s[1] + qs, name, path);
        }
        dismiss();
    });
    ba3.onNegative((dialog, which) -> {
        if (smbConnectionListener != null) {
            smbConnectionListener.deleteConnection(name, path);
        }
        dismiss();
    });
    ba3.onNeutral((dialog, which) -> dismiss());
    return ba3.build();
}
Also used : MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) ThemedActivity(com.amaze.filemanager.ui.activities.superclasses.ThemedActivity) Editable(android.text.Editable) TextView(android.widget.TextView) TextInputLayout(com.google.android.material.textfield.TextInputLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) GeneralSecurityException(java.security.GeneralSecurityException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) View(android.view.View) TextView(android.widget.TextView) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) SmbFile(jcifs.smb.SmbFile) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) UrlQuerySanitizer(android.net.UrlQuerySanitizer)

Aggregations

SharedPreferences (android.content.SharedPreferences)2 View (android.view.View)2 TextView (android.widget.TextView)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 ThemedActivity (com.amaze.filemanager.ui.activities.superclasses.ThemedActivity)2 SimpleTextWatcher (com.amaze.filemanager.utils.SimpleTextWatcher)2 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Color (android.graphics.Color)1 Typeface (android.graphics.Typeface)1 FingerprintManager (android.hardware.fingerprint.FingerprintManager)1 Uri (android.net.Uri)1 UrlQuerySanitizer (android.net.UrlQuerySanitizer)1 AsyncTask (android.os.AsyncTask)1 Build (android.os.Build)1 M (android.os.Build.VERSION_CODES.M)1 Editable (android.text.Editable)1 InputType (android.text.InputType)1