mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 21:55:48 +03:00
Handling empty state for rich document dialog.
This commit is contained in:
parent
def58c412f
commit
4f690d1e51
2 changed files with 27 additions and 25 deletions
|
@ -86,6 +86,8 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
|
|||
private static final String DOT = ".";
|
||||
public static final int SINGLE_TEMPLATE = 1;
|
||||
|
||||
private Set<String> fileNames;
|
||||
|
||||
@Inject CurrentAccountProvider currentAccount;
|
||||
@Inject ClientFactory clientFactory;
|
||||
@Inject ViewThemeUtils viewThemeUtils;
|
||||
|
@ -156,7 +158,7 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
|
|||
|
||||
parentFolder = arguments.getParcelable(ARG_PARENT_FOLDER);
|
||||
List<OCFile> folderContent = fileDataStorageManager.getFolderContent(parentFolder, false);
|
||||
Set<String> fileNames = Sets.newHashSetWithExpectedSize(folderContent.size());
|
||||
fileNames = Sets.newHashSetWithExpectedSize(folderContent.size());
|
||||
|
||||
for (OCFile file : folderContent) {
|
||||
fileNames.add(file.getFileName());
|
||||
|
@ -188,31 +190,14 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* When user enters an already taken file name, a message is shown. Otherwise, the
|
||||
* message is ensured to be hidden.
|
||||
*/
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
String newFileName = "";
|
||||
if (binding.filename.getText() != null) {
|
||||
newFileName = binding.filename.getText().toString().trim();
|
||||
}
|
||||
|
||||
if (fileNames.contains(newFileName)) {
|
||||
binding.filenameContainer.setError(getText(R.string.file_already_exists));
|
||||
positiveButton.setEnabled(false);
|
||||
} else if (binding.filenameContainer.getError() != null) {
|
||||
binding.filenameContainer.setError(null);
|
||||
// Called to remove extra padding
|
||||
binding.filenameContainer.setErrorEnabled(false);
|
||||
positiveButton.setEnabled(true);
|
||||
}
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
checkEnablingCreateButton();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -297,11 +282,28 @@ public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment im
|
|||
}
|
||||
|
||||
private void checkEnablingCreateButton() {
|
||||
Template selectedTemplate = adapter.getSelectedTemplate();
|
||||
String name = Objects.requireNonNull(binding.filename.getText()).toString();
|
||||
if (positiveButton != null) {
|
||||
Template selectedTemplate = adapter.getSelectedTemplate();
|
||||
String name = Objects.requireNonNull(binding.filename.getText()).toString();
|
||||
boolean isNameJustExtension = selectedTemplate != null && name.equalsIgnoreCase(
|
||||
DOT + selectedTemplate.getExtension());
|
||||
boolean isNameEmpty = name.isEmpty() || isNameJustExtension;
|
||||
boolean state = selectedTemplate != null && !isNameEmpty && !fileNames.contains(name);
|
||||
|
||||
positiveButton.setEnabled(selectedTemplate != null && !name.isEmpty() &&
|
||||
!name.equalsIgnoreCase(DOT + selectedTemplate.getExtension()));
|
||||
positiveButton.setEnabled(selectedTemplate != null && !name.isEmpty() &&
|
||||
!name.equalsIgnoreCase(DOT + selectedTemplate.getExtension()));
|
||||
positiveButton.setEnabled(state);
|
||||
positiveButton.setClickable(state);
|
||||
binding.filenameContainer.setErrorEnabled(!state);
|
||||
|
||||
if (!state) {
|
||||
if (isNameEmpty) {
|
||||
binding.filenameContainer.setError(getText(R.string.filename_empty));
|
||||
} else {
|
||||
binding.filenameContainer.setError(getText(R.string.file_already_exists));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class CreateFileFromTemplateTask extends AsyncTask<Void, Void, String> {
|
||||
|
|
|
@ -327,7 +327,7 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
|
|||
val fragment = chooseTemplateDialogFragmentWeakReference.get()
|
||||
if (fragment != null && fragment.isAdded) {
|
||||
if (url.isEmpty()) {
|
||||
DisplayUtils.showSnackMessage(fragment.binding.list, "Error creating file from template")
|
||||
DisplayUtils.showSnackMessage(fragment.binding.list, R.string.error_creating_file_from_template)
|
||||
} else {
|
||||
val editorWebView = Intent(MainApp.getAppContext(), TextEditorWebView::class.java)
|
||||
editorWebView.putExtra(ExternalSiteWebView.EXTRA_TITLE, "Text")
|
||||
|
|
Loading…
Reference in a new issue