Fixed NullPointerException on setMarkdown call and fixed file name not loading correctly for file:: URIs
This commit is contained in:
parent
f3a6359a4f
commit
b0490105b3
1 changed files with 14 additions and 12 deletions
|
@ -4,10 +4,8 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.commonsware.cwac.anddown.AndDown;
|
||||
import com.wbrawner.simplemarkdown.R;
|
||||
import com.wbrawner.simplemarkdown.model.MarkdownFile;
|
||||
import com.wbrawner.simplemarkdown.view.MarkdownEditView;
|
||||
import com.wbrawner.simplemarkdown.view.MarkdownPreviewView;
|
||||
|
@ -60,6 +58,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
|
|||
Runnable fileLoader = () -> {
|
||||
int result = file.load(in);
|
||||
if (result == MarkdownFile.SUCCESS) {
|
||||
if (editView != null)
|
||||
editView.setMarkdown(getMarkdown());
|
||||
onMarkdownEdited();
|
||||
} else {
|
||||
|
@ -160,6 +159,7 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
|
|||
try {
|
||||
InputStream in =
|
||||
context.getContentResolver().openInputStream(fileUri);
|
||||
if (fileUri.getScheme().equals("content")) {
|
||||
Cursor retCur = context.getContentResolver()
|
||||
.query(fileUri, null, null, null, null);
|
||||
if (retCur != null) {
|
||||
|
@ -168,10 +168,12 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
|
|||
retCur.moveToFirst();
|
||||
setFileName(retCur.getString(nameIndex));
|
||||
}
|
||||
} else if (fileUri.getScheme().equals("file")) {
|
||||
setFileName(fileUri.getLastPathSegment());
|
||||
}
|
||||
loadMarkdown(in);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(context, R.string.file_load_error, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
editView.showFileLoadeddError(MarkdownFile.READ_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue