Skip to content

avinashcoder/Android-Link-Preview

Repository files navigation

Android-Link-Preview

=================================

It makes a preview from an url, grabbing all the information such as title, relevant texts and images.

Note : Modified project of @LeonardoCardoso/Android-Link-Preview to add support of androidx and latest gradle updates.

Visual Examples

Preview

Requirements

  • jsoup is a smart lib to get the html code.

Installation

gradle

Simply add the repository to your build.gradle file:

repositories {
	jcenter()
	maven { url 'https://jitpack.io' }
}

And you can use the artifacts like this:

dependencies {
    implementation 'com.github.avinashcoder:Android-Link-Preview:1.0.0'
	// ...
}

ProGuard

If you use ProGuard, it is advised that you keep the jsoup dependencies by adding

-keeppackagenames org.jsoup.nodes

to your ProGuard rules file.

Usage

Instantiating

import com.coder.link.preview.library.TextCrawler;
// ...
// Create an instance of the TextCrawler to parse your url into a preview.
TextCrawler textCrawler = new TextCrawler();

// ..

// Create the callbacks to handle pre and post exicution of the preview generation.
LinkPreviewCallback linkPreviewCallback = new LinkPreviewCallback() {
    @Override
    public void onPre() {
        // Any work that needs to be done before generating the preview. Usually inflate 
        // your custom preview layout here.
    }

    @Override
    public void onPos(SourceContent sourceContent, boolean b) {
        // Populate your preview layout with the results of sourceContent.
    }
};

Generate Preview

textCrawler.makePreview( linkPreviewCallback, url);

Cancel unfinished tasks when views are destroied.

If you are using Android Link Preview inside of an Activity, it is important to cancel unfinished Preview activites at the end of the Activity's lifecycle.

 @Override
    protected void onDestroy() {
        super.onDestroy();
        textCrawler.cancel();
    }

Information and Contact

Developed by @Avinash Coder.

@Credit @LeonardoCardoso/Android-Link-Preview

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages