Coder Social home page Coder Social logo

richlinkpreview's Introduction

RichLink-Preview

A Rich Link Preview Library for Android

Android Arsenal

Sample Image

ScreenShot

Import using Gradle

compile 'io.github.ponnamkarthik:richlinkpreview:1.0.9'

for android studio 3.x

implementation 'io.github.ponnamkarthik:richlinkpreview:1.0.9'

### jsoup library required 
Implementation 'org.jsoup:jsoup:1.12.1'

To implement existing layout using XML

Add below code in activity_main.xml

<!--default view or whatsapp -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkView
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkView>
<!-- Telegram -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkViewTelegram
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkViewTelegram>
<!-- Skype -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkViewSkype
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkViewSkype>
<!-- Twitter -->
<io.github.ponnamkarthik.richlinkpreview.RichLinkViewTwitter
    android:id="@+id/richLinkView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</io.github.ponnamkarthik.richlinkpreview.RichLinkViewTwitter>

In your MainActivity.java add below code

public class MainActivity extends AppCompatActivity {
    
    RichLinkView richLinkView; 
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // ...
        // 
        richLinkView = (RichLinkView) findViewById(R.id.richLinkView);
        
        
        
        richLinkView.setLink("https://stackoverflow.com", new ViewListener() {
            
            @Override
            public void onSuccess(boolean status) {
                
            }
            
            @Override
            public void onError(Exception e) {
                
            }
        });
        
    }
}
RichLinkView richLinkView;
RichLinkViewTelegram richLinkViewTelegram;
RichLinkViewSkype richLinkViewSkype;
RichLinkViewTwitter richLinkViewTwitter;

//Set Link is same as default

OR

If you want to implement your own layout.

private MetaData data;

RichPreview richPreview = new RichPreview(new ResponseListener() {
    @Override
    public void onData(MetaData metaData) {
        data = metaData;
       
        //Implement your Layout
    }
    
    @Override
    public void onError(Exception e) {
        //handle error
    }
});

if you want to set obtained meta data to view

richLinkView.setLinkFromMeta(metaData)

or

MetaData metaData = new MetaData();
metaData.setTitle("Title");
metaData.setDescription("Custom Meta Data");
metaData.setFavicon("http://favicon url");
metaData.setImageurl("http://image url");
metaData.setSitename("Custom Meta data site");

richLinkView.setLinkFromMeta(metaData);

Set your own CickListener

//at first disable default click
richLinkView.setDefaultClickListener(false);

//set your own click listener
richLinkView.setClickListener(new RichLinkListener() {
    @Override
    public void onClicked(View view, MetaData meta) {
        //do stuff
        Toast.makeText(getApplicationContext(), meta.getTitle(), Toast.LENGTH_SHORT).show();
    }
});

MetaData

metaData.getTitle();

metaData.getImageurl();

metaData.getDescription();

metaData.getSitename();

metaData.getUrl();

metaData.getMediatype();

richlinkpreview's People

Contributors

bargeamol2000 avatar chintanrathod avatar ponnamkarthik avatar troutslaps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

richlinkpreview's Issues

illegal character in path at index 0: {{metaservice.metaImage()}}

This crash happen sometimes:

Caused by java.lang.IllegalArgumentException: Illegal character in path at index 0: {{metaservice.metaImage()}}
at java.net.URI.create(URI.java:734)
at java.net.URI.resolve(URI.java:1264)
at io.github.ponnamkarthik.richlinkpreview.RichPreview.resolveURL(SourceFile:170)
at io.github.ponnamkarthik.richlinkpreview.RichPreview.access$100$421289a4(SourceFile:19)
at io.github.ponnamkarthik.richlinkpreview.RichPreview$getData.doInBackground$10299ca(SourceFile:86)
at io.github.ponnamkarthik.richlinkpreview.RichPreview$getData.doInBackground(SourceFile:35)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

Plain text

How to set plain text in richlink preview ?

unable to handle MalformedException

I m getting this error and i am unable to handle it
plz help how to handle it i have tried my code with try catch but exception is occur in
your side which i cannot handle

java.lang.RuntimeException: An error occured while executing doInBackground()
java.lang.IllegalArgumentException: Malformed URL
java.net.MalformedURLException: Unknown protocol

Not getting twitter preview

i was using twitterrichlink to preview url on twitter but instead it was not publishing,then i use simple richlink then only twitter image with twitter.com is coming , can you please help me

Connection timeout

How to change connection timeout. I use RecyclerView to show list data, when it has some items that contain link. It take too much time to create RichLinkView, especially the fake link.

Cache preview

Is there any cache mechanism once user open after that no need to load again.

Ios Library

Is an ios version of this library available for iOS ?

Issue while using in recyclerview

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().

RichLinkPreview is not shwing on relaese build

RichLinkPreview is working and showing preview in debug build in emulator and real device , but once i build a release build it's not showing preview with no error in logcat.
is there something that i should add in proguard ?

i tried this but still not working :

-ignorewarnings
-obfuscationdictionary windows.txt
-classobfuscationdictionary windows.txt
-keep class android.support.v7.internal.** { ; }
-keep class android.support.v7.
* { ; }
-keep interface android.support.v7.internal.
* { ; }
-keep interface android.support.v7.
* { ; }
-keep class dgsn.gov.ma.dgsn.model.
* { ; }
-keep class com.fasterxml.jackson.
* { *; }

-dontwarn com.squareup.okhttp.**

-keepattributes Signature
-keepattributes Annotation
-keep class okhttp3.** { ; }
-keep interface okhttp3.
* { ; }
-dontwarn okhttp3.
*
-keeppackagenames org.jsoup.nodes
-keep class io.github.ponnamkarthik.richlinkpreview.** { *; }

Additional dependicies

To make lib work a have to add 2 dependencies:

implementation 'io.github.ponnamkarthik:richlinkpreview:1.0.8'
implementation 'org.jsoup:jsoup:1.11.2'
implementation 'com.squareup.picasso:picasso:2.5.2'

W/o that it doesnt work.

Not Compatible Anymore

Screen Shot 2022-05-01 at 2 18 20 PM

Android Studio Bumblebee | 2021.1.1 Patch 3
Build #AI-211.7628.21.2111.8309675, built on March 16, 2022
Runtime version: 11.0.11+0-b60-7590822 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 8
Registry: external.system.auto.import.disabled=true, ide.images.show.chessboard=true
Non-Bundled Plugins: com.thoughtworks.gauge (211.6693.111), org.jetbrains.kotlin (211-1.6.0-release-798-AS7442.40), org.intellij.plugins.markdown (211.7142.37)

Caching

Is there any caching available?

Memory Leak through ResponseListener

If the view is destroyed before the results are returned, there will be a memory leak

Also, there can be null pointer exceptions when the view is accessed after being changed since there is no view to work on after the callback is complete

There should be a way to cancel the request and set the listener to null

Jsoup timeout Exception

My app crashed sometimes due to Jsop timeout exception. I find solution to solve this exception.
You need to add timeout in Jsoup.connect() method.

In your RichPreview.java class, You used Jsoup.connect(url).get(); instaead of that use Jsoup.connect(url).timeout(30*1000).get();

Please add method to set this custom timeout so that user can adjust timeout and prevent exception.

https://parler.com url use then crash app

Caused by: java.lang.IllegalArgumentException: Illegal character in path at index 0: assets/img/app-icons/icon-384x384.png

Getting this type of error

please solve this error

Unable to create RichLinkViewTelegram fromMeta

richLinkViewTelegram.setLinkFromMeta(metaData) won't work because of next lines in richLinkViewTelegram.java :

textViewOriginalUrl = (TextView) findViewById(R.id.rich_link_original_url);

textViewOriginalUrl.setText(main_url);
removeUnderlines((Spannable)textViewOriginalUrl.getText());

Trying to set main_url will produce an error because it is an empty string (And the only way to set it is through setLink mehod)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.