Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nickm-27/linkpreview
An easy to use library for showing a link preview
https://github.com/nickm-27/linkpreview
android jetpack-android kotlin-android kotlin-coroutines kotlin-library linkpreview
Last synced: 3 months ago
JSON representation
An easy to use library for showing a link preview
- Host: GitHub
- URL: https://github.com/nickm-27/linkpreview
- Owner: NickM-27
- License: apache-2.0
- Created: 2018-06-17T14:55:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-01T14:09:26.000Z (almost 3 years ago)
- Last Synced: 2024-10-03T12:16:46.360Z (3 months ago)
- Topics: android, jetpack-android, kotlin-android, kotlin-coroutines, kotlin-library, linkpreview
- Language: Kotlin
- Size: 2.87 MB
- Stars: 49
- Watchers: 1
- Forks: 12
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# LinkPreview
A convenient library to show clickable previews of links.# Features
* Parse entire body of text to automatically find links.
* Find links from different sources and open them in the appropriate app, falling back to a custom tab if none is found.# How Do I Use It?
## Setup
### Gradle
This library is now distributed as part of `mavenCentral()`
On your module's `build.gradle` file add this statement to the `dependencies` section:
```groovy
dependencies {
implementation 'com.nicknackdevelopment:linkpreview:4.0'
}
```Also make sure that the `repositories` section includes both jcenter and `maven` section with the `"google()"` endpoint.
```groovy
repositories {
jcenter()
google()
}
```# Link Preview
### Add to your layout
```xml
...
```
### Create And Setup The View
```kotlin
val preview: LinkPreview = findViewById(R.id.preview)
...
preview.parseTextForLink(string) //Use LinkPreview$parseTextForLink if you have a body of text that contains more than just the link
preview.setLink(linkString) //Use when you have a string that contains only the link
```### Customize The View
```kotlin
preview.articleColor = ContextCompat.getColor(this, R.color.colorPrimary) //Set the color of the custom tab that is launched on link press//Use the load listener if you want to take extra action when a link error or success occurs
preview.loadListener = object : LinkListener {override fun onError() {
Toast.makeText(this@MainActivity, "Link loading failed", Toast.LENGTH_SHORT).show()
}override fun onSuccess(link: String) {
}
}
```### Advanced Usage
You can override the LinkPreview clicklistener all together using the click listener
```kotlin
preview.clickListener = object : LinkClickListener {override fun onLinkClicked(view: View?, url: String) {
}
}
```### Data Binding
LinkPreview supports data binding commands so the view can be customized in xml
```xml
```Appications using LinkPreview
---
Icon | Application
------------ | -------------
| [Texpert](https://play.google.com/store/apps/details?id=com.nick.mowen.texpert)Please [email](mailto:[email protected]) me or send a pull request if you would like to be added here.
Also Seen On
---
![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-LinkPreview-green.svg?style=flat)Developed By
---
Nick Mowen -Contributions
-------Any contributions are welcome!
# Donations
If you would like to donate / contribute to future development, you can [paypal me here](https://paypal.me/nickmowen)License
---Copyright 2018 Nick Nack Developments
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.