termux-app
98 строк · 3.7 Кб
1package com.termux.shared.models;2
3import com.termux.shared.markdown.MarkdownUtils;4import com.termux.shared.android.AndroidUtils;5
6import java.io.Serializable;7
8/**
9* An object that stored info for {@link com.termux.shared.activities.ReportActivity}.
10*/
11public class ReportInfo implements Serializable {12
13/** The user action that was being processed for which the report was generated. */14public final String userAction;15/** The internal app component that sent the report. */16public final String sender;17/** The report title. */18public final String reportTitle;19/** The timestamp for the report. */20public final String reportTimestamp;21
22/** The markdown report text prefix. Will not be part of copy and share operations, etc. */23public String reportStringPrefix;24/** The markdown report text. */25public String reportString;26/** The markdown report text suffix. Will not be part of copy and share operations, etc. */27public String reportStringSuffix;28
29/** If set to {@code true}, then report header info will be added to the report when markdown is30* generated. */
31public boolean addReportInfoHeaderToMarkdown = false;32
33/** The label for the report file to save if user selects menu_item_save_report_to_file. */34public String reportSaveFileLabel;35/** The path for the report file to save if user selects menu_item_save_report_to_file. */36public String reportSaveFilePath;37
38public ReportInfo(String userAction, String sender, String reportTitle) {39this.userAction = userAction;40this.sender = sender;41this.reportTitle = reportTitle;42this.reportTimestamp = AndroidUtils.getCurrentMilliSecondUTCTimeStamp();43}44
45public void setReportStringPrefix(String reportStringPrefix) {46this.reportStringPrefix = reportStringPrefix;47}48
49public void setReportString(String reportString) {50this.reportString = reportString;51}52
53public void setReportStringSuffix(String reportStringSuffix) {54this.reportStringSuffix = reportStringSuffix;55}56
57public void setAddReportInfoHeaderToMarkdown(boolean addReportInfoHeaderToMarkdown) {58this.addReportInfoHeaderToMarkdown = addReportInfoHeaderToMarkdown;59}60
61public void setReportSaveFileLabelAndPath(String reportSaveFileLabel, String reportSaveFilePath) {62setReportSaveFileLabel(reportSaveFileLabel);63setReportSaveFilePath(reportSaveFilePath);64}65
66public void setReportSaveFileLabel(String reportSaveFileLabel) {67this.reportSaveFileLabel = reportSaveFileLabel;68}69
70public void setReportSaveFilePath(String reportSaveFilePath) {71this.reportSaveFilePath = reportSaveFilePath;72}73
74/**75* Get a markdown {@link String} for {@link ReportInfo}.
76*
77* @param reportInfo The {@link ReportInfo} to convert.
78* @return Returns the markdown {@link String}.
79*/
80public static String getReportInfoMarkdownString(final ReportInfo reportInfo) {81if (reportInfo == null) return "null";82
83StringBuilder markdownString = new StringBuilder();84
85if (reportInfo.addReportInfoHeaderToMarkdown) {86markdownString.append("## Report Info\n\n");87markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("User Action", reportInfo.userAction, "-"));88markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Sender", reportInfo.sender, "-"));89markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Report Timestamp", reportInfo.reportTimestamp, "-"));90markdownString.append("\n##\n\n");91}92
93markdownString.append(reportInfo.reportString);94
95return markdownString.toString();96}97
98}
99