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 { interface MarkdownPresenter {
var fileName: String var fileName: String
var markdown: String var markdown: String
fun loadMarkdown(fileName: String, `in`: InputStream)
fun loadFromUri(context: Context, fileUri: Uri) fun loadFromUri(context: Context, fileUri: Uri)
fun loadMarkdown(fileName: String, `in`: InputStream, listener: FileLoadedListener, fun loadMarkdown(
replaceCurrentFile: Boolean) fileName: String,
`in`: InputStream,
listener: FileLoadedListener? = null,
replaceCurrentFile: Boolean = true
)
fun newFile(newName: String) fun newFile(newName: String)
fun setEditView(editView: MarkdownEditView) fun setEditView(editView: MarkdownEditView)
fun setPreviewView(previewView: MarkdownPreviewView) fun setPreviewView(previewView: MarkdownPreviewView)
fun saveMarkdown(listener: MarkdownSavedListener, name: String, outputStream: OutputStream) fun saveMarkdown(listener: MarkdownSavedListener, name: String, outputStream: OutputStream)
fun onMarkdownEdited() fun onMarkdownEdited(markdown: String? = null)
fun onMarkdownEdited(markdown: String) fun generateHTML(markdown: String? = null): String
fun generateHTML(): String
fun generateHTML(markdown: String): String
interface FileLoadedListener { interface FileLoadedListener {
fun onSuccess(markdown: String) fun onSuccess(markdown: String)
fun onError() 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 @Override
public void loadMarkdown( public void loadMarkdown(
final String fileName, final String fileName,
@ -62,7 +57,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
currentEditView.onFileLoaded(true); currentEditView.onFileLoaded(true);
currentEditView.setTitle(fileName); currentEditView.setTitle(fileName);
currentEditView.setMarkdown(this.file.getContent()); currentEditView.setMarkdown(this.file.getContent());
onMarkdownEdited(); onMarkdownEdited(null);
} }
} }
} }
@ -91,7 +86,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
@Override @Override
public void setEditView(MarkdownEditView editView) { public void setEditView(MarkdownEditView editView) {
this.editView = editView; this.editView = editView;
onMarkdownEdited(); onMarkdownEdited(null);
} }
@Override @Override
@ -126,16 +121,11 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
Runnable generateMarkdown = () -> { Runnable generateMarkdown = () -> {
MarkdownPreviewView currentPreviewView = previewView; MarkdownPreviewView currentPreviewView = previewView;
if (currentPreviewView != null) if (currentPreviewView != null)
currentPreviewView.updatePreview(generateHTML()); currentPreviewView.updatePreview(generateHTML(null));
}; };
fileHandler.post(generateMarkdown); fileHandler.post(generateMarkdown);
} }
@Override
public String generateHTML() {
return generateHTML(getMarkdown());
}
@Override @Override
public String generateHTML(String markdown) { public String generateHTML(String markdown) {
AndDown andDown = new AndDown(); AndDown andDown = new AndDown();
@ -145,11 +135,6 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
return andDown.markdownToHtml(markdown, HOEDOWN_FLAGS, 0); return andDown.markdownToHtml(markdown, HOEDOWN_FLAGS, 0);
} }
@Override
public void onMarkdownEdited() {
onMarkdownEdited(getMarkdown());
}
@Override @Override
public String getFileName() { public String getFileName() {
synchronized (fileLock) { synchronized (fileLock) {
@ -200,7 +185,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
if (fileName == null) { if (fileName == null) {
fileName = "Untitled.md"; fileName = "Untitled.md";
} }
loadMarkdown(fileName, in); loadMarkdown(fileName, in, null, true);
} catch (Exception e) { } catch (Exception e) {
errorHandler.reportException(e); errorHandler.reportException(e);
MarkdownEditView currentEditView = editView; MarkdownEditView currentEditView = editView;