View code: added pretty print option

pull/214/head
M66B 1 year ago
parent 16400443f7
commit fe11ac32c6

@ -72,6 +72,7 @@ public class ActivityCode extends ActivityBase {
private boolean sanitize = false; private boolean sanitize = false;
private boolean lines = false; private boolean lines = false;
private boolean links = false; private boolean links = false;
private boolean pretty = true;
private String searching = null; private String searching = null;
private static final int REQUEST_SAVE = 1; private static final int REQUEST_SAVE = 1;
@ -85,6 +86,7 @@ public class ActivityCode extends ActivityBase {
sanitize = savedInstanceState.getBoolean("fair:sanitize"); sanitize = savedInstanceState.getBoolean("fair:sanitize");
lines = savedInstanceState.getBoolean("fair:lines"); lines = savedInstanceState.getBoolean("fair:lines");
links = savedInstanceState.getBoolean("fair:links"); links = savedInstanceState.getBoolean("fair:links");
pretty = savedInstanceState.getBoolean("fair:pretty");
searching = savedInstanceState.getString("fair:searching"); searching = savedInstanceState.getString("fair:searching");
} }
@ -159,6 +161,7 @@ public class ActivityCode extends ActivityBase {
outState.putBoolean("fair:sanitize", sanitize); outState.putBoolean("fair:sanitize", sanitize);
outState.putBoolean("fair:lines", lines); outState.putBoolean("fair:lines", lines);
outState.putBoolean("fair:links", links); outState.putBoolean("fair:links", links);
outState.putBoolean("fair:pretty", pretty);
outState.putString("fair:searching", searching); outState.putString("fair:searching", searching);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -227,7 +230,7 @@ public class ActivityCode extends ActivityBase {
menu.findItem(R.id.menu_lines).setChecked(lines); menu.findItem(R.id.menu_lines).setChecked(lines);
menu.findItem(R.id.menu_links).setChecked(links); menu.findItem(R.id.menu_links).setChecked(links);
menu.findItem(R.id.menu_check_html).setVisible(BuildConfig.DEBUG || debug); menu.findItem(R.id.menu_pretty).setChecked(pretty);
return super.onPrepareOptionsMenu(menu); return super.onPrepareOptionsMenu(menu);
} }
@ -258,6 +261,11 @@ public class ActivityCode extends ActivityBase {
item.setChecked(links); item.setChecked(links);
load(); load();
return true; return true;
} else if (itemId == R.id.menu_pretty) {
pretty = !pretty;
item.setChecked(pretty);
load();
return true;
} else if (itemId == R.id.menu_check_html) { } else if (itemId == R.id.menu_check_html) {
checkHtml(); checkHtml();
return true; return true;
@ -303,6 +311,7 @@ public class ActivityCode extends ActivityBase {
args.putLong("id", id); args.putLong("id", id);
args.putCharSequence("selected", selected); args.putCharSequence("selected", selected);
args.putBoolean("sanitize", sanitize); args.putBoolean("sanitize", sanitize);
args.putBoolean("pretty", pretty);
new SimpleTask<String>() { new SimpleTask<String>() {
@Override @Override
@ -320,6 +329,7 @@ public class ActivityCode extends ActivityBase {
long id = args.getLong("id"); long id = args.getLong("id");
CharSequence selected = args.getCharSequence("selected"); CharSequence selected = args.getCharSequence("selected");
boolean sanitize = args.getBoolean("sanitize"); boolean sanitize = args.getBoolean("sanitize");
boolean pretty = args.getBoolean("pretty");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
@ -354,8 +364,8 @@ public class ActivityCode extends ActivityBase {
} }
d.outputSettings() d.outputSettings()
.prettyPrint(true) .prettyPrint(pretty)
.outline(true) .outline(pretty)
.indentAmount(1); .indentAmount(1);
if (selected == null) if (selected == null)
@ -421,6 +431,10 @@ public class ActivityCode extends ActivityBase {
@Override @Override
protected void onExecuted(Bundle args, ParseErrorList errors) { protected void onExecuted(Bundle args, ParseErrorList errors) {
lines = true;
pretty = false;
load();
SpannableStringBuilderEx ssb = new SpannableStringBuilderEx(); SpannableStringBuilderEx ssb = new SpannableStringBuilderEx();
ssb.append("Errors: ") ssb.append("Errors: ")
.append(Integer.toString(errors.size())) .append(Integer.toString(errors.size()))

@ -23,13 +23,19 @@
<item <item
android:id="@+id/menu_lines" android:id="@+id/menu_lines"
android:checkable="true" android:checkable="true"
android:title="@string/title_legend_line_numbers" android:title="@string/title_code_line_numbers"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item
android:id="@+id/menu_links" android:id="@+id/menu_links"
android:checkable="true" android:checkable="true"
android:title="@string/title_legend_enable_links" android:title="@string/title_code_enable_links"
app:showAsAction="never" />
<item
android:id="@+id/menu_pretty"
android:checkable="true"
android:title="@string/title_code_pretty"
app:showAsAction="never" /> app:showAsAction="never" />
<item <item

@ -2031,6 +2031,10 @@
<string name="title_rule_alarm_title">Alarm</string> <string name="title_rule_alarm_title">Alarm</string>
<string name="title_rule_alarm_stop">Stop</string> <string name="title_rule_alarm_stop">Stop</string>
<string name="title_code_line_numbers">Show line numbers</string>
<string name="title_code_enable_links">Enable links</string>
<string name="title_code_pretty">Pretty print</string>
<string name="title_legend_section_synchronize">Synchronize</string> <string name="title_legend_section_synchronize">Synchronize</string>
<string name="title_legend_section_folders">Folders</string> <string name="title_legend_section_folders">Folders</string>
<string name="title_legend_section_messages">Messages</string> <string name="title_legend_section_messages">Messages</string>
@ -2138,8 +2142,6 @@
<string name="title_legend_show_amp">Show AMP variant</string> <string name="title_legend_show_amp">Show AMP variant</string>
<string name="title_legend_show_full">Show original message</string> <string name="title_legend_show_full">Show original message</string>
<string name="title_legend_show_reformatted">Show reformatted message</string> <string name="title_legend_show_reformatted">Show reformatted message</string>
<string name="title_legend_line_numbers">Show line numbers</string>
<string name="title_legend_enable_links">Enable links</string>
<string name="title_legend_edit">Edit</string> <string name="title_legend_edit">Edit</string>
<string name="title_legend_default_color">Default color</string> <string name="title_legend_default_color">Default color</string>
<string name="title_legend_close_hint">Close hint</string> <string name="title_legend_close_hint">Close hint</string>

Loading…
Cancel
Save