Commit 87390083 authored by Vladislav's avatar Vladislav

htmlTagHandler sshould be implemented

parent 51122052
......@@ -4,7 +4,9 @@ import android.text.Html
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.graphics.drawable.toDrawable
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import butterknife.BindView
import butterknife.OnClick
import com.biganto.visual.roompark.R
......@@ -114,7 +116,13 @@ class ArticleScreenController :
private fun render(viewState: ArticleScreenViewState.ArticleLoaded) {
title.text = viewState.item.title
contentView.text = Html.fromHtml(viewState.item.htmlBody)
contentView.text = Html.fromHtml(viewState.item.htmlBody,
HtmlCompat.FROM_HTML_MODE_LEGACY, Html.ImageGetter { url ->
Picasso.get()
.load(url)
.get()
.toDrawable(resources!!)
},HtmlTa)
articleDate.text = viewState.item.published.toString()
Picasso.get()
......@@ -137,3 +145,42 @@ class ArticleScreenController :
}
public class HtmlTagHandler implements Html.TagHandler {
@Override
public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
Log.e("Tag", tag);
if (tag.startsWith("b") ) {
Log.e("Tage", "Code tag encountered1");
if (opening) {
Log.e("Tage", "Code tag encountered1");
output.setSpan(new TypefaceSpan("monospace"), output.length(), output.length(), Spannable.SPAN_MARK_MARK);
} else {
Log.e("Tage", "Code tag encountered2");
Object obj = getLast(output, TypefaceSpan.class);
int where = output.getSpanStart(obj);
output.removeSpan(obj);
output.setSpan(new TypefaceSpan("monospace"), where, output.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
else {
Log.e("Tage", "Code Exited");
}
}
private Object getLast(Editable text, Class kind) {
Object[] objs = text.getSpans(0, text.length(), kind);
if (objs.length == 0) {
return null;
} else {
for (int i = objs.length; i > 0; i--) {
if (text.getSpanFlags(objs[i - 1]) == Spannable.SPAN_MARK_MARK) {
return objs[i - 1];
}
}
return null;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment