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);
*/
}
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();
}
Aggregations