angebagui / medium-textview

Medium android application displays content with text, image, video etc in post detail. It can be a pain to do it with content came from CMS. So i decided to design that View to display the content quickly
496 stars 63 forks source link

Duplicates paragraphs in recyclerview #5

Open frakc opened 7 years ago

frakc commented 7 years ago

Greate lib but i found that on repeating scrolling some paragraphs are duplicated. eg on fist scroll over all content (20 items) everything is ok on second each paragraph (except last one) of each item appeared twise on third run each paragraph (except last one) of each item appeared 3 times and so on

frakc commented 7 years ago

fixed with removing oldviews

public class MediumTextView extends ElementView {

  public MediumTextView(Context context) {
    super(context, null);
  }

  public MediumTextView(Context context, AttributeSet attrs) {
    super(context, attrs, null);
  }

  @Override public void render() {
    setOrientation(VERTICAL);
  }

  String html = null;

  public void setText(String html) {
    if (!html.equals(this.html)) {
      this.html = html;
      removeAllViews();
      Document document = Jsoup.parse(html);
      Element element = document.body();
      setElement(element);
      Utils.appendView(this, getElement().children());
      invalidate();
    }
  }

  @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  }

  @Override protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
  }
}