Prevent crash

pull/153/head
M66B 6 years ago
parent 2bfee5ff6e
commit 5bb959448c

@ -2431,13 +2431,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override @Override
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE); try {
String jobName = context.getString(R.string.app_name); PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
if (!TextUtils.isEmpty(data.message.subject)) String jobName = context.getString(R.string.app_name);
jobName += " - " + data.message.subject; if (!TextUtils.isEmpty(data.message.subject))
PrintDocumentAdapter adapter = printWebView.createPrintDocumentAdapter(jobName); jobName += " - " + data.message.subject;
printManager.print(jobName, adapter, new PrintAttributes.Builder().build()); PrintDocumentAdapter adapter = printWebView.createPrintDocumentAdapter(jobName);
printWebView = null; printManager.print(jobName, adapter, new PrintAttributes.Builder().build());
} catch (Throwable ex) {
Log.e(ex);
} finally {
printWebView = null;
}
} }
}); });
@ -2557,6 +2562,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_share).setEnabled(data.message.content); popupMenu.getMenu().findItem(R.id.menu_share).setEnabled(data.message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setEnabled(hasWebView && data.message.content); popupMenu.getMenu().findItem(R.id.menu_print).setEnabled(hasWebView && data.message.content);
popupMenu.getMenu().findItem(R.id.menu_print).setVisible(Helper.canPrint(context));
popupMenu.getMenu().findItem(R.id.menu_show_headers).setChecked(show_headers); popupMenu.getMenu().findItem(R.id.menu_show_headers).setChecked(show_headers);
popupMenu.getMenu().findItem(R.id.menu_show_headers).setEnabled(data.message.uid != null); popupMenu.getMenu().findItem(R.id.menu_show_headers).setEnabled(data.message.uid != null);

@ -1035,6 +1035,11 @@ public class Helper {
return false; return false;
} }
static boolean canPrint(Context context) {
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature("android.software.print");
}
public static String getFingerprint(Context context) { public static String getFingerprint(Context context) {
try { try {
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();

Loading…
Cancel
Save