mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Handle generated html that exceeds the maximum text length. Also improve rendering.
This commit is contained in:
committed by
akwizgran
parent
07f85b14ec
commit
1c1c6096b5
@@ -18,6 +18,7 @@ import org.briarproject.briar.api.blog.BlogPostHeader;
|
||||
import org.briarproject.nullsafety.NotNullByDefault;
|
||||
|
||||
import androidx.annotation.UiThread;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -106,7 +107,9 @@ class BlogPostViewHolder extends RecyclerView.ViewHolder {
|
||||
}
|
||||
|
||||
// post text
|
||||
Spanned postText = getSpanned(item.getText());
|
||||
String rawText = item.getText() != null ? item.getText() : "";
|
||||
Spanned postText = item.isRssFeed() ? getSpanned(rawText) :
|
||||
HtmlCompat.fromHtml(rawText, HtmlCompat.FROM_HTML_MODE_COMPACT);
|
||||
if (fullText) {
|
||||
text.setText(postText);
|
||||
text.setTextIsSelectable(true);
|
||||
|
||||
@@ -2,17 +2,19 @@ package org.briarproject.briar.android.blog;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.briarproject.bramble.api.FormatException;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.identity.IdentityManager;
|
||||
import org.briarproject.bramble.api.identity.LocalAuthor;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
@@ -24,6 +26,7 @@ import org.briarproject.briar.api.attachment.AttachmentHeader;
|
||||
import org.briarproject.briar.api.blog.BlogManager;
|
||||
import org.briarproject.briar.api.blog.BlogPost;
|
||||
import org.briarproject.briar.api.blog.BlogPostFactory;
|
||||
import org.briarproject.briar.util.HtmlUtils;
|
||||
import org.briarproject.nullsafety.MethodsNotNullByDefault;
|
||||
import org.briarproject.nullsafety.ParametersNotNullByDefault;
|
||||
|
||||
@@ -34,11 +37,13 @@ import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_SHORT;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.bramble.util.LogUtils.logException;
|
||||
import static org.briarproject.bramble.util.StringUtils.isNullOrEmpty;
|
||||
@@ -121,15 +126,24 @@ public class WriteBlogPostActivity extends BriarActivity
|
||||
List<AttachmentHeader> headers, long expectedAutoDeleteTimer) {
|
||||
if (isNullOrEmpty(text)) throw new AssertionError();
|
||||
|
||||
SpannableStringBuilder ssb = SpannableStringBuilder.valueOf(text);
|
||||
Linkify.addLinks(ssb, Linkify.WEB_URLS);
|
||||
String html = HtmlUtils.clean(
|
||||
HtmlCompat.toHtml(ssb,
|
||||
HtmlCompat.TO_HTML_PARAGRAPH_LINES_INDIVIDUAL),
|
||||
HtmlUtils.ARTICLE);
|
||||
|
||||
int textLength = StringUtils.toUtf8(html).length;
|
||||
if (textLength > MAX_BLOG_POST_TEXT_LENGTH) {
|
||||
Snackbar.make(input, R.string.text_too_long, LENGTH_SHORT).show();
|
||||
return new MutableLiveData<>(null);
|
||||
}
|
||||
|
||||
// hide publish button, show progress bar
|
||||
input.hideSoftKeyboard();
|
||||
input.setVisibility(GONE);
|
||||
progressBar.setVisibility(VISIBLE);
|
||||
|
||||
SpannableStringBuilder ssb = SpannableStringBuilder.valueOf(text);
|
||||
Linkify.addLinks(ssb, Linkify.WEB_URLS);
|
||||
String html = Html.toHtml(ssb);
|
||||
|
||||
storePost(html);
|
||||
return new MutableLiveData<>(SENT);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user