diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index a3090aff..9cd51ee0 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -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; diff --git a/app/src/main/java/eu/faircode/email/FragmentAbout.java b/app/src/main/java/eu/faircode/email/FragmentAbout.java index 71fd5f5d..c7a1b1f8 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAbout.java +++ b/app/src/main/java/eu/faircode/email/FragmentAbout.java @@ -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 = "
" + info.toString().replaceAll("\\r?\\n", ""; - 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 = "
") + "
" + info.toString().replaceAll("\\r?\\n", ""; + 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()); } }); diff --git a/app/src/main/java/eu/faircode/email/SimpleLoader.java b/app/src/main/java/eu/faircode/email/SimpleLoader.java index 2a0632f1..52729432 100644 --- a/app/src/main/java/eu/faircode/email/SimpleLoader.java +++ b/app/src/main/java/eu/faircode/email/SimpleLoader.java @@ -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; }
") + "