diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenter.kt b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenter.kt index 0cffc0a..d621ecd 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenter.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenter.kt @@ -12,25 +12,24 @@ import java.io.OutputStream interface MarkdownPresenter { var fileName: String var markdown: String - fun loadMarkdown(fileName: String, `in`: InputStream) fun loadFromUri(context: Context, fileUri: Uri) - fun loadMarkdown(fileName: String, `in`: InputStream, listener: FileLoadedListener, - replaceCurrentFile: Boolean) + fun loadMarkdown( + fileName: String, + `in`: InputStream, + listener: FileLoadedListener? = null, + replaceCurrentFile: Boolean = true + ) fun newFile(newName: String) fun setEditView(editView: MarkdownEditView) fun setPreviewView(previewView: MarkdownPreviewView) - fun saveMarkdown(listener: MarkdownSavedListener, name: String, outputStream: OutputStream) - fun onMarkdownEdited() - fun onMarkdownEdited(markdown: String) - fun generateHTML(): String - fun generateHTML(markdown: String): String + fun onMarkdownEdited(markdown: String? = null) + fun generateHTML(markdown: String? = null): String interface FileLoadedListener { fun onSuccess(markdown: String) - fun onError() } diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java index f9059a1..c34796c 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java +++ b/app/src/main/java/com/wbrawner/simplemarkdown/presentation/MarkdownPresenterImpl.java @@ -35,11 +35,6 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { } } - @Override - public void loadMarkdown(final String fileName, final InputStream in) { - this.loadMarkdown(fileName, in, null, true); - } - @Override public void loadMarkdown( final String fileName, @@ -62,7 +57,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { currentEditView.onFileLoaded(true); currentEditView.setTitle(fileName); currentEditView.setMarkdown(this.file.getContent()); - onMarkdownEdited(); + onMarkdownEdited(null); } } } @@ -91,7 +86,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { @Override public void setEditView(MarkdownEditView editView) { this.editView = editView; - onMarkdownEdited(); + onMarkdownEdited(null); } @Override @@ -126,16 +121,11 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { Runnable generateMarkdown = () -> { MarkdownPreviewView currentPreviewView = previewView; if (currentPreviewView != null) - currentPreviewView.updatePreview(generateHTML()); + currentPreviewView.updatePreview(generateHTML(null)); }; fileHandler.post(generateMarkdown); } - @Override - public String generateHTML() { - return generateHTML(getMarkdown()); - } - @Override public String generateHTML(String markdown) { AndDown andDown = new AndDown(); @@ -145,11 +135,6 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { return andDown.markdownToHtml(markdown, HOEDOWN_FLAGS, 0); } - @Override - public void onMarkdownEdited() { - onMarkdownEdited(getMarkdown()); - } - @Override public String getFileName() { synchronized (fileLock) { @@ -200,7 +185,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter { if (fileName == null) { fileName = "Untitled.md"; } - loadMarkdown(fileName, in); + loadMarkdown(fileName, in, null, true); } catch (Exception e) { errorHandler.reportException(e); MarkdownEditView currentEditView = editView;