ponnamkarthik / RichLinkPreview

A Rich Link Preview Library for Android
Apache License 2.0
217 stars 58 forks source link

Issue while using in recyclerview #18

Open Slake07 opened 4 years ago

Slake07 commented 4 years ago

When I am using RichLinkView into recycler view, it generates layout every time I scroll my recycler view.

I solved this issue with change in RichLinkView class. call below initView() method in every constructor of RichLinkView class.

public void initView() {
    this.view = this;
    inflate(context, R.layout.include_link_preview_post_item,this);
    linearLayout = (LinearLayout) findViewById(R.id.llMainIncRowLinPreviewPost);
    imageView = (AppCompatImageView) findViewById(R.id.ivPreviewIncRowLinPreviewPost);
    textViewTitle = (AppCompatTextView) findViewById(R.id.tvTitleIncRowLinPreviewPost);
    textViewUrl = (AppCompatTextView) findViewById(R.id.tvLinkIncRowLinPreviewPost);
  }

private void setData(){
    if(meta.getImageurl().equals("") || meta.getImageurl().isEmpty()) {
        imageView.setVisibility(GONE);
    } else {
        imageView.setVisibility(VISIBLE);
        Glide.with(context).load(meta.getImageurl()).into(imageView);
    }

    if(meta.getTitle().isEmpty() || meta.getTitle().equals("")) {
        textViewTitle.setVisibility(GONE);
    } else {
        textViewTitle.setVisibility(VISIBLE);
        textViewTitle.setText(meta.getTitle());
    }
    if(meta.getUrl().isEmpty() || meta.getUrl().equals("")) {
        textViewUrl.setVisibility(GONE);
    } else {
        textViewUrl.setVisibility(VISIBLE);
        textViewUrl.setText(meta.getUrl());
    }

    linearLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if(isDefaultClick) {
                richLinkClicked();
            } else {
                if(richLinkListener != null) {
                    richLinkListener.onClicked(view, meta);
                } else {
                    richLinkClicked();
                }
            }
        }
    });
}

Then call setData() method into setLink() method instend of initView().

santhoshpr commented 4 years ago

Am also facing the same issue Am using RichLinkViewSkype and it is getting reset and blank view is set when we scroll through the recycler view for the second time !

The above solution by Slake07 seems to work thanks

santhoshpr commented 4 years ago

@Slake07 Thanks for the solution it seems to work now

@PonnamKarthik You can close this issue now.

Mahato12nikhil commented 4 years ago

Actually here I am not using RichLinkview class as I am using Richpreview class and populating values to my own xml and getting same issues.

Mahato12nikhil commented 3 years ago

I solved it!!!

notchdesign commented 3 years ago

hey, do you guys just manually edited the code while downloading? I have implemented and the code is only readable? know any way bypassing? Or I also implement it manually?

notchdesign commented 3 years ago

@santhoshpr can you tell me how you edited the code? I am not familiar with manual installation.

notchdesign commented 3 years ago

@Mahato12nikhil can you help me build is not working for me

mahbub-java commented 3 years ago

When in recycleview link fetch every time when scroll. So I also use a static map to hold url with metadata and check if previous url already successfully fetch for metadata or not.

private static Map<String, MetaData> linkMap=new HashMap<>();

public void setLink(String url, final ViewListener viewListener) {
        MetaData data = linkMap.get(url);
        if(data == null) {
            main_url = url;
            RichPreview richPreview = new RichPreview(new ResponseListener() {
                @Override
                public void onData(MetaData metaData) {
                    meta = metaData;

                    if (!meta.getTitle().isEmpty() || !meta.getTitle().equals("")) {
                        viewListener.onSuccess(true);
                        linkMap.put(url, metaData);
                    }

                    setData();
                }

                @Override
                public void onError(Exception e) {
                    viewListener.onError(e);
                }
            });
            richPreview.getPreview(url);
        }else{
            main_url = url;
            meta = data;
            viewListener.onSuccess(true);
            setData();
        }
    }