Marked translated text

pull/199/head
M66B 4 years ago
parent 52d1d26b60
commit d9969a94d5

@ -305,7 +305,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private static final int MAX_RECIPIENTS_COMPACT = 3;
private static final int MAX_RECIPIENTS_NORMAL = 7;
private static final int MAX_QUOTE_LEVEL = 3;
private static final int MAX_TRANSLATE = 1000; // characters
// https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml
private static final List<String> IMAP_KEYWORDS_BLACKLIST = Collections.unmodifiableList(Arrays.asList(
@ -6677,20 +6676,24 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
long id = args.getLong("id");
File file = EntityMessage.getFile(context, id);
Document d = JsoupEx.parse(file);
String html = Helper.readText(file);
Document d = HtmlHelper.sanitizeCompose(context, html, false);
d.select("blockquote").remove();
return HtmlHelper.getText(context, d.html());
SpannableStringBuilder ssb = HtmlHelper.fromDocument(context, d, null, null);
return ssb.toString()
.replace("\uFFFC", "") // Object replacement character
.replaceAll("\n\\s+\n", "\n")
.replaceAll("\n+", "\n\n");
}
@Override
protected void onExecuted(Bundle args, String text) {
tvText.setText(text);
tvText.setMovementMethod(new ArrowKeyMovementMethod() {
private boolean running = false;
tvText.setMovementMethod(new ArrowKeyMovementMethod() {
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP && !running)
if (event.getAction() == MotionEvent.ACTION_UP)
translate(widget, buffer, event);
return super.onTouchEvent(widget, buffer, event);
}
@ -6703,7 +6706,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
start--;
int end = off;
while (end < buffer.length() && buffer.charAt(end) != '\n')
while (end < buffer.length() && buffer.charAt(end - 1) != '\n')
end++;
if (end <= start)
@ -6713,21 +6716,20 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (spans != null && spans.length > 0)
return;
final StyleSpan mark = new StyleSpan(Typeface.ITALIC);
buffer.setSpan(mark, start, end, 0);
Bundle args = new Bundle();
args.putInt("start", start);
args.putInt("end", end);
args.putString("text", buffer.subSequence(start, end).toString());
new SimpleTask<DeepL.Translation>() {
@Override
protected void onPreExecute(Bundle args) {
running = true;
pbWait.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Bundle args) {
running = false;
pbWait.setVisibility(View.GONE);
}
@ -6740,11 +6742,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@Override
protected void onExecuted(Bundle args, DeepL.Translation translation) {
int start = args.getInt("start");
int end = args.getInt("end");
SpannableStringBuilder ssb = new SpannableStringBuilder(buffer);
SpannableStringBuilder ssb = new SpannableStringBuilder(tvText.getText());
int start = ssb.getSpanStart(mark);
int end = ssb.getSpanEnd(mark);
ssb.removeSpan(mark);
ssb = ssb.replace(start, end, translation.translated_text);
ssb.setSpan(new StyleSpan(Typeface.ITALIC), start, start + translation.translated_text.length(), 0);
ssb.setSpan(new StyleSpan(Typeface.ITALIC),
start, start + translation.translated_text.length(), 0);
tvText.setText(ssb);
}
@ -6765,7 +6769,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setView(view)
.setPositiveButton(android.R.string.ok, null);
.setPositiveButton(android.R.string.cancel, null);
return builder.create();
}

@ -16,7 +16,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/etKeyword"
android:text="@string/title_translate"
android:text="@string/title_translate_tap"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

@ -1127,6 +1127,7 @@
<string name="title_translating">Translating &#8230;</string>
<string name="title_translate_small">Use a small font for the source text</string>
<string name="title_translate_usage">Usage: %1$s / %2$s (%3$d %%)</string>
<string name="title_translate_tap">Tap the text to be translated</string>
<string name="title_edit_plain_text">Edit as plain text</string>
<string name="title_edit_formatted_text">Edit as reformatted text</string>
<string name="title_select_certificate">Select public key</string>

Loading…
Cancel
Save