diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eb7413092..9cdafe4f5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,7 +26,6 @@ android:configChanges="orientation|screenSize" android:icon="@mipmap/ic_launcher_bubbles" android:label="@string/app_name" - android:hardwareAccelerated="false" android:largeHeap="true" android:roundIcon="@mipmap/ic_launcher_bubbles_round" android:supportsRtl="true" diff --git a/app/src/main/java/app/fedilab/android/helper/CustomQuoteSpan.java b/app/src/main/java/app/fedilab/android/helper/CustomQuoteSpan.java new file mode 100644 index 000000000..fdc55b5ac --- /dev/null +++ b/app/src/main/java/app/fedilab/android/helper/CustomQuoteSpan.java @@ -0,0 +1,54 @@ +package app.fedilab.android.helper; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.text.Layout; +import android.text.style.LeadingMarginSpan; +import android.text.style.LineBackgroundSpan; + +import org.jetbrains.annotations.NotNull; + +/** + * Original work from @heath-borders: https://stackoverflow.com/a/29114976/3197259 + */ +public class CustomQuoteSpan implements LeadingMarginSpan, LineBackgroundSpan { + private final int backgroundColor; + private final int stripeColor; + private final float stripeWidth; + private final float gap; + + public CustomQuoteSpan(int backgroundColor, int stripeColor, float stripeWidth, float gap) { + this.backgroundColor = backgroundColor; + this.stripeColor = stripeColor; + this.stripeWidth = stripeWidth; + this.gap = gap; + } + + @Override + public int getLeadingMargin(boolean first) { + return (int) (stripeWidth + gap); + } + + @Override + public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, + CharSequence text, int start, int end, boolean first, Layout layout) { + Paint.Style style = p.getStyle(); + int paintColor = p.getColor(); + + p.setStyle(Paint.Style.FILL); + p.setColor(stripeColor); + + c.drawRect(x, top, x + dir * stripeWidth, bottom, p); + + p.setStyle(style); + p.setColor(paintColor); + } + + @Override + public void drawBackground(@NotNull Canvas c, @NotNull Paint p, int left, int right, int top, int baseline, int bottom, @NotNull CharSequence text, int start, int end, int lnum) { + int paintColor = p.getColor(); + p.setColor(backgroundColor); + c.drawRect(left, top, right, bottom, p); + p.setColor(paintColor); + } +} diff --git a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java index a652790c7..ffdc9320c 100644 --- a/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/SpannableHelper.java @@ -36,6 +36,7 @@ import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextPaint; import android.text.style.ClickableSpan; +import android.text.style.QuoteSpan; import android.text.style.URLSpan; import android.util.Patterns; import android.view.LayoutInflater; @@ -44,6 +45,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; import androidx.preference.PreferenceManager; import com.bumptech.glide.Glide; @@ -90,6 +92,8 @@ public class SpannableHelper { if (text == null) { return null; } + text = text.replaceAll("(>(.*))<\\s?br\\s?/?>", "
$2"); + text = text.replaceAll("(>(.*))<\\s?/p\\s?/?>", "
$2"); Pattern imgPattern = Pattern.compile("]*src=\"([^\"]+)\"[^>]*>"); Matcher matcherImg = imgPattern.matcher(text); HashMap