Skip to content

Commit

Permalink
Merge pull request #12927 from nextcloud/bugfix/null-pointer-fix-file…
Browse files Browse the repository at this point in the history
…name-on-template-dialog

Use getFileNameText for nullable field
  • Loading branch information
AndyScherzinger authored Apr 30, 2024
2 parents 051754d + f84acd5 commit a4f01de
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import javax.inject.Inject;
Expand Down Expand Up @@ -245,9 +244,20 @@ public void setTemplateList(List<Template> templateList) {
adapter.notifyDataSetChanged();
}

private String getFileNameText() {
String result = "";
Editable text = binding.filename.getText();

if (text != null) {
result = text.toString();
}

return result;
}

@Override
public void onClick(View v) {
String name = binding.filename.getText().toString();
String name = getFileNameText();
String path = parentFolder.getRemotePath() + name;

Template selectedTemplate = adapter.getSelectedTemplate();
Expand Down Expand Up @@ -275,12 +285,13 @@ private void onTemplateChosen(Template template) {
}

private void prefillFilenameIfEmpty(Template template) {
String name = binding.filename.getText().toString();
String name = getFileNameText();

if (name.isEmpty() || name.equalsIgnoreCase(DOT + template.getExtension())) {
binding.filename.setText(String.format("%s.%s", template.getName(), template.getExtension()));
}

final int dotIndex = binding.filename.getText().toString().lastIndexOf('.');
final int dotIndex = getFileNameText().lastIndexOf('.');
if (dotIndex >= 0) {
binding.filename.setSelection(dotIndex);
}
Expand All @@ -289,7 +300,7 @@ private void prefillFilenameIfEmpty(Template template) {
private void checkEnablingCreateButton() {
if (positiveButton != null) {
Template selectedTemplate = adapter.getSelectedTemplate();
String name = Objects.requireNonNull(binding.filename.getText()).toString();
String name = getFileNameText();
boolean isNameJustExtension = selectedTemplate != null && name.equalsIgnoreCase(
DOT + selectedTemplate.getExtension());
boolean isNameEmpty = name.isEmpty() || isNameJustExtension;
Expand Down

0 comments on commit a4f01de

Please sign in to comment.