Browse Source

Use loader for debug info

main
M66B 6 years ago
parent
commit
c6ca47bd4f
3 changed files with 45 additions and 33 deletions
  1. +1
    -0
      app/src/main/java/eu/faircode/email/ActivityView.java
  2. +43
    -32
      app/src/main/java/eu/faircode/email/FragmentAbout.java
  3. +1
    -1
      app/src/main/java/eu/faircode/email/SimpleLoader.java

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

@ -73,6 +73,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
static final int LOADER_MESSAGE_MOVE = 9;
static final int LOADER_MESSAGE_ARCHIVE = 10;
static final int LOADER_SEEN_UNTIL = 11;
static final int LOADER_DEBUG_INFO = 12;
static final int REQUEST_VIEW = 1;
static final int REQUEST_UNSEEN = 2;


+ 43
- 32
app/src/main/java/eu/faircode/email/FragmentAbout.java View File

@ -21,13 +21,14 @@ package eu.faircode.email;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -49,45 +50,55 @@ public class FragmentAbout extends FragmentEx {
View view = inflater.inflate(R.layout.fragment_about, container, false);
TextView tvVersion = view.findViewById(R.id.tvVersion);
Button btnDebugInfo = view.findViewById(R.id.btnDebugInfo);
final Button btnDebugInfo = view.findViewById(R.id.btnDebugInfo);
tvVersion.setText(getString(R.string.title_version, BuildConfig.VERSION_NAME));
btnDebugInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
executor.submit(new Runnable() {
btnDebugInfo.setEnabled(false);
new SimpleLoader() {
@Override
public void run() {
try {
DB db = DB.getInstance(getContext());
EntityFolder drafts = db.folder().getPrimaryDrafts();
if (drafts != null) {
StringBuilder info = Helper.getDebugInfo();
info.insert(0, getString(R.string.title_debug_info_remark) + "\n\n\n\n");
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");
EntityMessage draft = new EntityMessage();
draft.account = drafts.account;
draft.folder = drafts.id;
draft.to = new Address[]{to};
draft.subject = BuildConfig.APPLICATION_ID + " debug info";
draft.body = "<pre>" + info.toString().replaceAll("\\r?\\n", "<br />") + "</pre>";
draft.received = new Date().getTime();
draft.seen = false;
draft.ui_seen = false;
draft.ui_hide = false;
draft.id = db.message().insertMessage(draft);
startActivity(new Intent(getContext(), ActivityCompose.class)
.putExtra("id", draft.id));
}
} catch (Throwable ex) {
Log.w(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
}
public Object onLoad(Bundle args) throws UnsupportedEncodingException {
DB db = DB.getInstance(getContext());
EntityFolder drafts = db.folder().getPrimaryDrafts();
if (drafts == null)
throw new IllegalArgumentException(getString(R.string.title_no_drafts));
StringBuilder info = Helper.getDebugInfo();
info.insert(0, getString(R.string.title_debug_info_remark) + "\n\n\n\n");
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");
EntityMessage draft = new EntityMessage();
draft.account = drafts.account;
draft.folder = drafts.id;
draft.to = new Address[]{to};
draft.subject = BuildConfig.APPLICATION_ID + " debug info";
draft.body = "<pre>" + info.toString().replaceAll("\\r?\\n", "<br />") + "</pre>";
draft.received = new Date().getTime();
draft.seen = false;
draft.ui_seen = false;
draft.ui_hide = false;
draft.id = db.message().insertMessage(draft);
return draft.id;
}
});
@Override
public void onLoaded(Bundle args, Result result) {
btnDebugInfo.setEnabled(true);
if (result.ex == null) {
long id = (Long) result.data;
startActivity(new Intent(getContext(), ActivityCompose.class)
.putExtra("id", id));
} else
Toast.makeText(getContext(), executor.toString(), Toast.LENGTH_LONG).show();
}
}.load(FragmentAbout.this, ActivityView.LOADER_DEBUG_INFO, new Bundle());
}
});


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

@ -26,7 +26,7 @@ public abstract class SimpleLoader {
manager.restartLoader(id, args, callbacks).forceLoad();
}
public Object onLoad(Bundle args) {
public Object onLoad(Bundle args) throws Throwable {
return null;
}


Loading…
Cancel
Save