Sistemata UI del log esportato via Mail
This commit is contained in:
@@ -14,7 +14,6 @@ import java.util.List;
|
|||||||
import it.integry.barcode_base_android_library.interfaces.BarcodeReaderInterface;
|
import it.integry.barcode_base_android_library.interfaces.BarcodeReaderInterface;
|
||||||
import it.integry.barcode_base_android_library.model.BarcodeSetting;
|
import it.integry.barcode_base_android_library.model.BarcodeSetting;
|
||||||
import it.integry.honeywellscannerlibrary.HoneyWellBarcodeReader;
|
import it.integry.honeywellscannerlibrary.HoneyWellBarcodeReader;
|
||||||
import it.integry.integrywmsnative.core.utility.UtilityLogger;
|
|
||||||
import it.integry.integrywmsnative.gest.settings.MainSettingsFragment;
|
import it.integry.integrywmsnative.gest.settings.MainSettingsFragment;
|
||||||
import it.integry.keyobardemulatorscannerlibrary.KeyboardEmulatorBarcodeReader;
|
import it.integry.keyobardemulatorscannerlibrary.KeyboardEmulatorBarcodeReader;
|
||||||
import it.integry.pointmobilescannerlibrary.PointMobileBarcodeReader;
|
import it.integry.pointmobilescannerlibrary.PointMobileBarcodeReader;
|
||||||
@@ -136,12 +135,12 @@ public class BarcodeManager {
|
|||||||
|
|
||||||
public static void disable() {
|
public static void disable() {
|
||||||
mEnabled = false;
|
mEnabled = false;
|
||||||
UtilityLogger.trace("Barcode reader disabled");
|
// UtilityLogger.info("Barcode reader disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enable() {
|
public static void enable() {
|
||||||
mEnabled = true;
|
mEnabled = true;
|
||||||
UtilityLogger.trace("Barcode reader enabled");
|
// UtilityLogger.info("Barcode reader enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEnabled() {
|
public static boolean isEnabled() {
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ import it.integry.integrywmsnative.BuildConfig;
|
|||||||
|
|
||||||
public class UtilityLogger {
|
public class UtilityLogger {
|
||||||
|
|
||||||
public static void trace(String message) {
|
|
||||||
Logger.d(message, getPreviousStackTraceElement());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void info(String message) {
|
public static void info(String message) {
|
||||||
Logger.i(message);
|
Logger.i(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import android.os.Bundle;
|
|||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Base64OutputStream;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -20,11 +19,13 @@ import androidx.preference.PreferenceFragmentCompat;
|
|||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
import com.harrysoft.androidbluetoothserial.BluetoothManager;
|
import com.harrysoft.androidbluetoothserial.BluetoothManager;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@@ -50,6 +51,10 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
|||||||
public SystemRESTConsumer systemRESTConsumer;
|
public SystemRESTConsumer systemRESTConsumer;
|
||||||
@Inject
|
@Inject
|
||||||
public DialogProgressView mCurrentProgress;
|
public DialogProgressView mCurrentProgress;
|
||||||
|
@Inject
|
||||||
|
public ExecutorService executorService;
|
||||||
|
|
||||||
|
|
||||||
private boolean progressOpened;
|
private boolean progressOpened;
|
||||||
|
|
||||||
private final ArrayList<Runnable> onPreDestroyList = new ArrayList<>();
|
private final ArrayList<Runnable> onPreDestroyList = new ArrayList<>();
|
||||||
@@ -214,6 +219,9 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
|||||||
DialogYesNoView.newInstance("Esportazione log", "Vuoi inviare il log degli eventi al supporto?", result -> {
|
DialogYesNoView.newInstance("Esportazione log", "Vuoi inviare il log degli eventi al supporto?", result -> {
|
||||||
this.openProgress();
|
this.openProgress();
|
||||||
|
|
||||||
|
executorService.execute(() -> {
|
||||||
|
|
||||||
|
|
||||||
File yourFile = appContext.getLogFilePath();
|
File yourFile = appContext.getLogFilePath();
|
||||||
var files = yourFile.listFiles();
|
var files = yourFile.listFiles();
|
||||||
|
|
||||||
@@ -221,22 +229,14 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
|||||||
.sortBy(x -> -1 * x.lastModified())
|
.sortBy(x -> -1 * x.lastModified())
|
||||||
.findFirstOrElse(null);
|
.findFirstOrElse(null);
|
||||||
try {
|
try {
|
||||||
FileInputStream fis = new FileInputStream(fileToShare);
|
var htmlContent = createAppLogAttachment(fileToShare);
|
||||||
|
|
||||||
byte[] buffer = new byte[fis.available()];//specify the size to allow
|
byte[] buffer = htmlContent.getBytes();//specify the size to allow.
|
||||||
int bytesRead;
|
String base64 = Base64.encodeToString(buffer, Base64.NO_WRAP);
|
||||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
||||||
Base64OutputStream output64 = new Base64OutputStream(output, Base64.DEFAULT);
|
|
||||||
|
|
||||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
|
||||||
output64.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
output64.close();
|
|
||||||
|
|
||||||
var attachment = new MailAttachmentDTO()
|
var attachment = new MailAttachmentDTO()
|
||||||
.setFileName("wms_log.log")
|
.setFileName("wms_log.html")
|
||||||
.setFileb64Content(output.toString());
|
.setFileb64Content(base64);
|
||||||
|
|
||||||
var mailRequest = new MailRequestDTO()
|
var mailRequest = new MailRequestDTO()
|
||||||
.setTo("developer@integry.it")
|
.setTo("developer@integry.it")
|
||||||
@@ -248,15 +248,20 @@ public class MainSettingsFragment extends PreferenceFragmentCompat implements IT
|
|||||||
|
|
||||||
systemRESTConsumer.sendMail(mailRequest, this::closeProgress, ex -> {
|
systemRESTConsumer.sendMail(mailRequest, this::closeProgress, ex -> {
|
||||||
this.closeProgress();
|
this.closeProgress();
|
||||||
|
requireActivity().runOnUiThread(() -> {
|
||||||
DialogSimpleMessageView
|
DialogSimpleMessageView
|
||||||
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
||||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
requireActivity().runOnUiThread(() -> {
|
||||||
DialogSimpleMessageView
|
DialogSimpleMessageView
|
||||||
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
.makeErrorDialog(new SpannableString(Html.fromHtml(ex.getMessage())), null, null)
|
||||||
.show(requireActivity().getSupportFragmentManager(), "tag");
|
.show(requireActivity().getSupportFragmentManager(), "tag");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.show(getParentFragmentManager(), "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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user