Sistemata UI del log esportato via Mail
This commit is contained in:
parent
35f1495ebc
commit
69b88b1f6d
@ -14,7 +14,6 @@ import java.util.List;
|
||||
import it.integry.barcode_base_android_library.interfaces.BarcodeReaderInterface;
|
||||
import it.integry.barcode_base_android_library.model.BarcodeSetting;
|
||||
import it.integry.honeywellscannerlibrary.HoneyWellBarcodeReader;
|
||||
import it.integry.integrywmsnative.core.utility.UtilityLogger;
|
||||
import it.integry.integrywmsnative.gest.settings.MainSettingsFragment;
|
||||
import it.integry.keyobardemulatorscannerlibrary.KeyboardEmulatorBarcodeReader;
|
||||
import it.integry.pointmobilescannerlibrary.PointMobileBarcodeReader;
|
||||
@ -136,12 +135,12 @@ public class BarcodeManager {
|
||||
|
||||
public static void disable() {
|
||||
mEnabled = false;
|
||||
UtilityLogger.trace("Barcode reader disabled");
|
||||
// UtilityLogger.info("Barcode reader disabled");
|
||||
}
|
||||
|
||||
public static void enable() {
|
||||
mEnabled = true;
|
||||
UtilityLogger.trace("Barcode reader enabled");
|
||||
// UtilityLogger.info("Barcode reader enabled");
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
|
||||
@ -7,10 +7,6 @@ import it.integry.integrywmsnative.BuildConfig;
|
||||
|
||||
public class UtilityLogger {
|
||||
|
||||
public static void trace(String message) {
|
||||
Logger.d(message, getPreviousStackTraceElement());
|
||||
}
|
||||
|
||||
public static void info(String message) {
|
||||
Logger.i(message);
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.util.Base64;
|
||||
import android.util.Base64OutputStream;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -20,11 +19,13 @@ import androidx.preference.PreferenceFragmentCompat;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.harrysoft.androidbluetoothserial.BluetoothManager;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -50,6 +51,10 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
||||
public SystemRESTConsumer systemRESTConsumer;
|
||||
@Inject
|
||||
public DialogProgressView mCurrentProgress;
|
||||
@Inject
|
||||
public ExecutorService executorService;
|
||||
|
||||
|
||||
private boolean progressOpened;
|
||||
|
||||
private final ArrayList<Runnable> onPreDestroyList = new ArrayList<>();
|
||||
@ -214,49 +219,49 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
||||
DialogYesNoView.newInstance("Esportazione log", "Vuoi inviare il log degli eventi al supporto?", result -> {
|
||||
this.openProgress();
|
||||
|
||||
File yourFile = appContext.getLogFilePath();
|
||||
var files = yourFile.listFiles();
|
||||
executorService.execute(() -> {
|
||||
|
||||
var fileToShare = Stream.of(files)
|
||||
.sortBy(x -> -1 * x.lastModified())
|
||||
.findFirstOrElse(null);
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(fileToShare);
|
||||
|
||||
byte[] buffer = new byte[fis.available()];//specify the size to allow
|
||||
int bytesRead;
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
Base64OutputStream output64 = new Base64OutputStream(output, Base64.DEFAULT);
|
||||
File yourFile = appContext.getLogFilePath();
|
||||
var files = yourFile.listFiles();
|
||||
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
output64.write(buffer, 0, bytesRead);
|
||||
var fileToShare = Stream.of(files)
|
||||
.sortBy(x -> -1 * x.lastModified())
|
||||
.findFirstOrElse(null);
|
||||
try {
|
||||
var htmlContent = createAppLogAttachment(fileToShare);
|
||||
|
||||
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
|
||||
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
||||
|
||||
var attachment = new MailAttachmentDTO()
|
||||
.setFileName("wms_log.html")
|
||||
.setFileb64Content(base64);
|
||||
|
||||
var mailRequest = new MailRequestDTO()
|
||||
.setTo("developer@integry.it")
|
||||
.setMsgText("Questo è una mail che contiene il log del WMS")
|
||||
.setSubject("U vuemmeess")
|
||||
.setAttachments(new ArrayList<>());
|
||||
|
||||
mailRequest.getAttachments().add(attachment);
|
||||
|
||||
systemRESTConsumer.sendMail(mailRequest, this::closeProgress, ex -> {
|
||||
this.closeProgress();
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
DialogSimpleMessageView
|
||||
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
});
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
DialogSimpleMessageView
|
||||
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
});
|
||||
}
|
||||
|
||||
output64.close();
|
||||
|
||||
var attachment = new MailAttachmentDTO()
|
||||
.setFileName("wms_log.log")
|
||||
.setFileb64Content(output.toString());
|
||||
|
||||
var mailRequest = new MailRequestDTO()
|
||||
.setTo("developer@integry.it")
|
||||
.setMsgText("Questo è una mail che contiene il log del WMS")
|
||||
.setSubject("U vuemmeess")
|
||||
.setAttachments(new ArrayList<>());
|
||||
|
||||
mailRequest.getAttachments().add(attachment);
|
||||
|
||||
systemRESTConsumer.sendMail(mailRequest, this::closeProgress, ex -> {
|
||||
this.closeProgress();
|
||||
DialogSimpleMessageView
|
||||
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
DialogSimpleMessageView
|
||||
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||
}
|
||||
});
|
||||
})
|
||||
.show(getParentFragmentManager(), "tag");
|
||||
}
|
||||
@ -279,4 +284,90 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String createAppLogAttachment(File logFile) {
|
||||
//Read text from file
|
||||
StringBuilder text = new StringBuilder();
|
||||
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new FileReader(logFile));
|
||||
String line;
|
||||
|
||||
while ((line = br.readLine()) != null) {
|
||||
text.append(line);
|
||||
text.append('\n');
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
//You'll need to add proper error handling here
|
||||
}
|
||||
|
||||
StringBuilder htmlContent = new StringBuilder("<html lang=\"en\" style=\"font-family: Helvetica;\">\n" +
|
||||
"<head>\n" +
|
||||
" <title>WMS Log</title>\n" +
|
||||
"\n" +
|
||||
" <style>\n" +
|
||||
" .level-badge {\n" +
|
||||
" border-radius: 2px;\n" +
|
||||
" padding: 0.25em 0.5rem;\n" +
|
||||
" text-transform: uppercase;\n" +
|
||||
" font-weight: 770;\n" +
|
||||
" font-size: 12px;\n" +
|
||||
" letter-spacing: .3px;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" .level-badge.trace {\n" +
|
||||
" background-color: #a6a6a6;\n" +
|
||||
" color: #ffffff;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" .level-badge.debug {\n" +
|
||||
" background-color: #b3e5fc;\n" +
|
||||
" color: #23547b;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" .level-badge.info {\n" +
|
||||
" background-color: #c8e6c9;\n" +
|
||||
" color: #256029;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" .level-badge.warn {\n" +
|
||||
" background: #feedaf;\n" +
|
||||
" color: #8a5340;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" .level-badge.error, .level-badge.fatal {\n" +
|
||||
" background-color: #ffcdd2;\n" +
|
||||
" color: #c63737;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" .message {\n" +
|
||||
" white-space: pre-wrap;\n" +
|
||||
" }\n" +
|
||||
" </style>\n" +
|
||||
"</head>\n" +
|
||||
"\n" +
|
||||
"<body>");
|
||||
|
||||
String[] lines = text.toString().split("\n");
|
||||
|
||||
for (String line : lines) {
|
||||
String datetime = line.substring(14, 37);
|
||||
String tmp = line.substring(38);
|
||||
String logLevel = tmp.substring(0, tmp.indexOf(","));
|
||||
tmp = tmp.substring(logLevel.length() + 1);
|
||||
String title = tmp.substring(0, tmp.indexOf(","));
|
||||
String message = tmp.substring(title.length() + 1);
|
||||
|
||||
htmlContent.append("<span style=\"font-size: 0.7em;\">").append(datetime).append("</span><br />");
|
||||
htmlContent.append("<div><span class=\"level-badge ").append(logLevel.toLowerCase()).append("\">").append(logLevel).append("</span> <span>").append(title).append("</span></div>");
|
||||
htmlContent.append("<code class=\"message\">").append(message).append("</code>");
|
||||
htmlContent.append("<hr/>");
|
||||
}
|
||||
|
||||
htmlContent.append("\n" + "<script type=\"text/javascript\">\n" + " document.querySelectorAll(\".message\").forEach(el => el.innerHTML = el.innerHTML.replaceAll(/at it\\.integry.*?(?:<br>)/g, '<b>$&</b>'));\n" + "</script>\n" + "</body>\n" + "</html>");
|
||||
|
||||
return htmlContent.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user