Fixed loading inline images

pull/147/head
M66B 6 years ago
parent 4646e4f048
commit c91fabe18e

@ -87,11 +87,7 @@ public abstract class DB extends RoomDatabase {
public static synchronized DB getInstance(Context context) { public static synchronized DB getInstance(Context context) {
if (sInstance == null) { if (sInstance == null) {
sInstance = migrate(context, Room sInstance = migrate(context, getBuilder(context));
.databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME)
.openHelperFactory(new RequerySQLiteOpenHelperFactory())
.setQueryExecutor(executor)
.setJournalMode(JournalMode.WRITE_AHEAD_LOGGING));
Log.i("sqlite version=" + exec(sInstance, "SELECT sqlite_version() AS sqlite_version")); Log.i("sqlite version=" + exec(sInstance, "SELECT sqlite_version() AS sqlite_version"));
Log.i("sqlite sync=" + exec(sInstance, "PRAGMA synchronous")); Log.i("sqlite sync=" + exec(sInstance, "PRAGMA synchronous"));
@ -101,6 +97,18 @@ public abstract class DB extends RoomDatabase {
return sInstance; return sInstance;
} }
public static synchronized DB getInstanceMainThread(Context context) {
return migrate(context, getBuilder(context).allowMainThreadQueries());
}
private static RoomDatabase.Builder getBuilder(Context context) {
return Room
.databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME)
.openHelperFactory(new RequerySQLiteOpenHelperFactory())
.setQueryExecutor(executor)
.setJournalMode(JournalMode.WRITE_AHEAD_LOGGING);
}
private static String exec(DB db, String command) { private static String exec(DB db, String command) {
Cursor cursor = null; Cursor cursor = null;
try { try {

@ -1628,7 +1628,7 @@ public class FragmentCompose extends FragmentEx {
new SimpleTask<EntityMessage>() { new SimpleTask<EntityMessage>() {
@Override @Override
protected EntityMessage onExecute(Context context, Bundle args) throws Throwable { protected EntityMessage onExecute(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -1647,7 +1647,8 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
protected void onExecuted(Bundle args, EntityMessage draft) { protected void onExecuted(Bundle args, EntityMessage draft) {
showDraft(draft); if (draft != null && state == State.NONE)
showDraft(draft);
} }
@Override @Override
@ -1990,7 +1991,7 @@ public class FragmentCompose extends FragmentEx {
@Override @Override
public Drawable getDrawable(String source) { public Drawable getDrawable(String source) {
if (source != null && source.startsWith("cid:")) { if (source != null && source.startsWith("cid:")) {
DB db = DB.getInstance(getContext()); DB db = DB.getInstanceMainThread(getContext());
String cid = "<" + source.substring(4) + ">"; String cid = "<" + source.substring(4) + ">";
EntityAttachment attachment = db.attachment().getAttachment(working, cid); EntityAttachment attachment = db.attachment().getAttachment(working, cid);
if (attachment != null) { if (attachment != null) {

Loading…
Cancel
Save