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


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

@ -1,5 +1,24 @@
package eu.faircode.email; 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.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
@ -10,6 +29,11 @@ import androidx.loader.app.LoaderManager;
import androidx.loader.content.AsyncTaskLoader; import androidx.loader.content.AsyncTaskLoader;
import androidx.loader.content.Loader; 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> { public abstract class SimpleLoader<T> {
private Context context; private Context context;
private LoaderManager manager; private LoaderManager manager;
@ -27,6 +51,7 @@ public abstract class SimpleLoader<T> {
} }
public T onLoad(Bundle args) throws Throwable { public T onLoad(Bundle args) throws Throwable {
// Be careful not to access members in outer scopes
return null; return null;
} }
@ -36,6 +61,10 @@ public abstract class SimpleLoader<T> {
public void onException(Bundle args, Throwable ex) { public void onException(Bundle args, Throwable ex) {
} }
protected Context getContext() {
return context;
}
private static class CommonLoader extends AsyncTaskLoader<Result> { private static class CommonLoader extends AsyncTaskLoader<Result> {
Bundle args; Bundle args;
SimpleLoader loader; SimpleLoader loader;


Loading…
Cancel
Save