if (!mainFragmentViewModel.results) {
adapter.toggleChecked(false, mainFragmentViewModel.currentPath)
- } else adapter.toggleChecked(false)
+ } else {
+ adapter.toggleChecked(false)
+ }
mainActivity
.updateViews(
ColorDrawable(
if (MainActivity.currentTab == 1) {
mainFragmentViewModel.primaryTwoColor
- } else mainFragmentViewModel.primaryColor
+ } else {
+ mainFragmentViewModel.primaryColor
+ }
)
)
}
diff --git a/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java b/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java
index 7a927ec5c1..ccccf7e37c 100644
--- a/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java
+++ b/app/src/main/java/com/amaze/filemanager/utils/MainActivityHelper.java
@@ -213,37 +213,7 @@ public void mkfile(final OpenMode openMode, final String path, final MainFragmen
ma);
dialog.dismiss();
},
- (text) -> {
- boolean isValidFilename = FileProperties.isValidFilename(text);
-
- // The redundant equalsIgnoreCase() is needed since ".txt" itself does not end with .txt
- // (i.e. recommended as ".txt.txt"
- if (text.length() > 0) {
- if (!isValidFilename || text.startsWith(" ")) {
- return new WarnableTextInputValidator.ReturnState(
- WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.invalid_name);
- } else {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
- if (text.startsWith(".")
- && !prefs.getBoolean(PreferencesConstants.PREFERENCE_SHOW_HIDDENFILES, false)) {
- return new WarnableTextInputValidator.ReturnState(
- WarnableTextInputValidator.ReturnState.STATE_WARNING,
- R.string.create_hidden_file_warn);
- } else if (!text.toLowerCase()
- .endsWith(
- AppConstants.NEW_FILE_DELIMITER.concat(
- AppConstants.NEW_FILE_EXTENSION_TXT))) {
- return new WarnableTextInputValidator.ReturnState(
- WarnableTextInputValidator.ReturnState.STATE_WARNING,
- R.string.create_file_suggest_txt_extension);
- }
- }
- } else {
- return new WarnableTextInputValidator.ReturnState(
- WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.field_empty);
- }
- return new WarnableTextInputValidator.ReturnState();
- });
+ new FilenameValidator());
}
private void mk(
@@ -826,4 +796,52 @@ public static void addSearchFragment(
fragment.setArguments(args);
fragmentManager.beginTransaction().add(fragment, MainActivity.TAG_ASYNC_HELPER).commit();
}
+
+ public static class FilenameValidator implements WarnableTextInputValidator.OnTextValidate {
+
+ private boolean recommendTxtExtension;
+
+ public FilenameValidator() {
+ this(true);
+ }
+
+ public FilenameValidator(boolean recommendTxtExtension) {
+ this.recommendTxtExtension = recommendTxtExtension;
+ }
+
+ @Override
+ public WarnableTextInputValidator.ReturnState isTextValid(String text) {
+ boolean isValidFilename = FileProperties.isValidFilename(text);
+
+ // The redundant equalsIgnoreCase() is needed since ".txt" itself does not end with .txt
+ // (i.e. recommended as ".txt.txt"
+ if (text.length() > 0) {
+ if (!isValidFilename || text.startsWith(" ")) {
+ return new WarnableTextInputValidator.ReturnState(
+ WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.invalid_name);
+ } else {
+ SharedPreferences prefs =
+ PreferenceManager.getDefaultSharedPreferences(AppConfig.getInstance());
+ if (text.startsWith(".")
+ && !prefs.getBoolean(PreferencesConstants.PREFERENCE_SHOW_HIDDENFILES, false)) {
+ return new WarnableTextInputValidator.ReturnState(
+ WarnableTextInputValidator.ReturnState.STATE_WARNING,
+ R.string.create_hidden_file_warn);
+ } else if (recommendTxtExtension
+ && !text.toLowerCase()
+ .endsWith(
+ AppConstants.NEW_FILE_DELIMITER.concat(
+ AppConstants.NEW_FILE_EXTENSION_TXT))) {
+ return new WarnableTextInputValidator.ReturnState(
+ WarnableTextInputValidator.ReturnState.STATE_WARNING,
+ R.string.create_file_suggest_txt_extension);
+ }
+ }
+ } else {
+ return new WarnableTextInputValidator.ReturnState(
+ WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.field_empty);
+ }
+ return new WarnableTextInputValidator.ReturnState();
+ }
+ }
}
diff --git a/app/src/main/java/com/amaze/filemanager/utils/Utils.java b/app/src/main/java/com/amaze/filemanager/utils/Utils.java
index ea6a951fcd..c778ad65d8 100644
--- a/app/src/main/java/com/amaze/filemanager/utils/Utils.java
+++ b/app/src/main/java/com/amaze/filemanager/utils/Utils.java
@@ -239,18 +239,25 @@ private static String sanitizeInputOnce(String input) {
.replaceAll(INPUT_INTENT_BLACKLIST_COLON, "");
}
- /** Returns uri associated to specific basefile */
+ public static Uri getUriForLocalFile(@NonNull Context context, @NonNull File localFile) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ return FileProvider.getUriForFile(context, context.getPackageName(), localFile);
+ } else {
+ return Uri.fromFile(localFile);
+ }
+ }
+
+ /**
+ * Returns uri associated to specific basefile
+ *
+ * FIXME: what if the basefile's path is not local path?
+ */
public static Uri getUriForBaseFile(
@NonNull Context context, @NonNull HybridFileParcelable baseFile) {
switch (baseFile.getMode()) {
case FILE:
case ROOT:
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- return FileProvider.getUriForFile(
- context, context.getPackageName(), new File(baseFile.getPath()));
- } else {
- return Uri.fromFile(new File(baseFile.getPath()));
- }
+ return getUriForLocalFile(context, new File(baseFile.getPath()));
case OTG:
return OTGUtil.getDocumentFile(baseFile.getPath(), context, true).getUri();
case SMB: