Clean up MarkdownPresenter Kotlin changes

This commit is contained in:
Billy Brawner 2019-08-15 18:44:17 -05:00 committed by William Brawner
parent a927851a30
commit 04e8bb1c03
2 changed files with 12 additions and 28 deletions

View file

@ -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()
}

View file

@ -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;