Browse Source

Simple loader fixes

main
M66B 6 years ago
parent
commit
30f963b05f
2 changed files with 32 additions and 3 deletions
  1. +3
    -3
      app/src/main/java/eu/faircode/email/ActivityView.java
  2. +29
    -0
      app/src/main/java/eu/faircode/email/SimpleLoader.java

+ 3
- 3
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -184,9 +184,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
new SimpleLoader<Long>() {
@Override
public Long onLoad(Bundle args) throws Throwable {
File file = new File(getCacheDir(), "crash.log");
File file = new File(getContext().getCacheDir(), "crash.log");
if (file.exists()) {
DB db = DB.getInstance(ActivityView.this);
DB db = DB.getInstance(getContext());
EntityFolder drafts = db.folder().getPrimaryDrafts();
if (drafts != null) {
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");
@ -352,7 +352,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override
public Object onLoad(Bundle args) {
long time = args.getLong("time");
DaoAccount dao = DB.getInstance(ActivityView.this).account();
DaoAccount dao = DB.getInstance(getContext()).account();
for (EntityAccount account : dao.getAccounts(true)) {
account.seen_until = time;
dao.updateAccount(account);


+ 29
- 0
app/src/main/java/eu/faircode/email/SimpleLoader.java View File

@ -1,5 +1,24 @@
package eu.faircode.email;
/*
This file is part of Safe email.
Safe email is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NetGuard is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
@ -10,6 +29,11 @@ import androidx.loader.app.LoaderManager;
import androidx.loader.content.AsyncTaskLoader;
import androidx.loader.content.Loader;
//
// This simple loader is simple to use, but it is also simple to cause bugs that can easily lead to crashes
// Make sure to not access any member in any outer scope from onLoad
//
public abstract class SimpleLoader<T> {
private Context context;
private LoaderManager manager;
@ -27,6 +51,7 @@ public abstract class SimpleLoader<T> {
}
public T onLoad(Bundle args) throws Throwable {
// Be careful not to access members in outer scopes
return null;
}
@ -36,6 +61,10 @@ public abstract class SimpleLoader<T> {
public void onException(Bundle args, Throwable ex) {
}
protected Context getContext() {
return context;
}
private static class CommonLoader extends AsyncTaskLoader<Result> {
Bundle args;
SimpleLoader loader;


Loading…
Cancel
Save