All Projects → m7mdra → Htmlrecycler

m7mdra / Htmlrecycler

Licence: apache-2.0
HtmlRecycler Converts a simple html page into A RecyclerView of Native android widgets.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Htmlrecycler

Lcg
吾爱破解第三方安卓应用
Stars: ✭ 371 (+62.72%)
Mutual labels:  jsoup
Skraper
Kotlin/Java library and cli tool for scraping posts and media from various sources with neither authorization nor full page rendering (Facebook, Instagram, Twitter, Youtube, Tiktok, Telegram, Twitch, Reddit, 9GAG, Pinterest, Flickr, Tumblr, IFunny, VK, Pikabu)
Stars: ✭ 72 (-68.42%)
Mutual labels:  jsoup
Nsoup
NSoup is a .NET port of the jsoup (http://jsoup.org) HTML parser and sanitizer originally written in Java
Stars: ✭ 145 (-36.4%)
Mutual labels:  jsoup
Changedetection
Automatically track websites changes on Android in background.
Stars: ✭ 563 (+146.93%)
Mutual labels:  jsoup
Any Video
【已停止维护】
Stars: ✭ 1,059 (+364.47%)
Mutual labels:  jsoup
House
微信公众号:程序员博博。有完整版的PDF下载。
Stars: ✭ 85 (-62.72%)
Mutual labels:  jsoup
Flesh
Android上福利满满的app,宅男神器
Stars: ✭ 363 (+59.21%)
Mutual labels:  jsoup
Gecco
Easy to use lightweight web crawler(易用的轻量化网络爬虫)
Stars: ✭ 2,310 (+913.16%)
Mutual labels:  jsoup
Wish
常用javaweb技术,不定期更新,欢迎讨论。
Stars: ✭ 60 (-73.68%)
Mutual labels:  jsoup
Deepnight In Kotlin
8小时 用kotlin开发的一款纯看妹子的app
Stars: ✭ 101 (-55.7%)
Mutual labels:  jsoup
Httpraw2jsoup
本工具可以帮你把原生http请求转换成Jsoup请求代码
Stars: ✭ 17 (-92.54%)
Mutual labels:  jsoup
Jsoupsample
jsoupSample
Stars: ✭ 48 (-78.95%)
Mutual labels:  jsoup
Searchitem
小搜搜——商品条形码/二维码搜索APP
Stars: ✭ 96 (-57.89%)
Mutual labels:  jsoup
Rxretrojsoup
A simple API-like from html website (scrapper) for Android, RxJava2 ready !
Stars: ✭ 492 (+115.79%)
Mutual labels:  jsoup
Sakuraanime
使用jsoup爬取樱花动漫部分内容编写的第三方Android客户端。
Stars: ✭ 177 (-22.37%)
Mutual labels:  jsoup
Spider Flow
新一代爬虫平台,以图形化方式定义爬虫流程,不写代码即可完成爬虫。
Stars: ✭ 365 (+60.09%)
Mutual labels:  jsoup
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+3928.07%)
Mutual labels:  jsoup
Awesome Java Crawler
本仓库收集整理爬虫相关资源,开发语言以Java为主
Stars: ✭ 228 (+0%)
Mutual labels:  jsoup
Now
Jsoup + MaterialViewPager + RxJava2 + Retrofit + Lifecycle + Realm + Fresco + Retrolambda example 一款Android图文精选app,通过抓取网页获得图文列表。目前包含猫弄(MONO)早午茶、站酷(Zcool)精选、国家地理(National Geographic)每日一图、知乎日报、豆瓣一刻(Moment)。
Stars: ✭ 189 (-17.11%)
Mutual labels:  jsoup
Crawlerpack
Java 網路資料爬蟲包
Stars: ✭ 99 (-56.58%)
Mutual labels:  jsoup

This library has been under development for over 2 years, I don't think I will ever complete since the project we were working on got cancelled and I don't think I have enough time to finish it, PR are always welcome.

HtmlRecycler

Converts a simple html page into A RecyclerView of native android widgets powered by Jsoup library and inspired by Medium Textview.

Note

This library was design and developed by ME and we use this in our application which depends on a Content Management system and was never intended to replace browsers or act as one. this library simply gave us more control over html page than WebView

Add it to your project

dependencies {
    implementation 'com.github.m7mdra:HtmlRecycler:0.1.11'
}

This project is distributed using jitpack. Make sure you add it as a maven repository to your build.gradle

allprojects {
    repositories {
        maven { 
            url 'https://jitpack.io' 
        }
    }
}

Demo

enter image description here enter image description here
  • APK
  • Or simply git clone the repository and build the app module.

Currently supported html elements

  • [x] Paragraph
  • [x] H1...H6
  • [x] Image
  • [x] Video
  • [x] Audio
  • [x] Ordered List
  • [x] Unordered List
  • [x] Description List
  • [x] Anchor Link
  • [x] IFrame
  • [ ] Table
  • [x] DIV

Implementation

val networkSource = NetworkSource("https://gist.githubusercontent.com/m7mdra/f22c62bc6941e08064b4fbceb4832a90/raw/ea8574d986635cf214541f1f5702ef37cc731aaf/article.html")  
  
HtmlRecycler.Builder([email protected])  
    .setSource(networkSource)  
    .setAdapter(DefaultElementsAdapter([email protected]) { element, i, view ->  
    }})
    .setRecyclerView(recyclerView)  
    .setLoadingCallback(object : HtmlRecycler.LoadCallback {  
        override fun onLoadingStart() {  
            progressBar.visibility = View.VISIBLE  
        }  
        override fun onLoaded(document: Document?) {  
            progressBar.visibility = View.GONE
  	}  
    })  
    .build()

The above code uses the existing implementation of DefaultElementsAdapter which extends ElementsAdapter class which inherently is a RecylcerView Adpater the DefaultElementsAdapter uses a layout resources files defined by me but they not styled probably and are very buggy (especially the video, audio and iframe ones).

Want to create your own adapter? just simply extend ElementsAdapter and override methods:

class BetterImplementationThanTheAuthorsAdapter : ElementsAdapter() {    
    override fun onCreateElement(parent: ViewGroup, elementType: ElementType): RecyclerView.ViewHolder {  
        when (elementType) {  
            ElementType.Paragraph -> {  
                return ParagraphViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragarph, parent, false))  
            }
	    // Define other elements here
        }  
    }  
  
    override fun onBindElement(holder: RecyclerView.ViewHolder, position: Int) {  
        val element = elements[position] //current element  
	    if (holder is ParagraphViewHolder){  
                val paragraphElement = element as ParagraphElement  
            	holder.paragraphText.text= paragraphElement.text  
	    }  
	}  
    }
}

Then replace the default adapter with your adapter:

HtmlRecycler.Builder(this)  
    .setSource(StringSource(Data.data))  
    .setAdapter(BetterImplementationThanTheAuthorsAdapter()) // this is a custom adapter  
    .setRecyclerView(recyclerView)  
    .build()

How to add Data

Data can come from different sources, the library support the following:

  • [x] Assets
  • [x] File
  • [x] String
  • [x] Network (runs on UI thread by default so you have to run it on different thread or write your own Source Implementation )

Write your own source

Simply implement the Source interface which will return a Document of the parsed Source:

class FileSource(val file: File) : Source {  
    override fun get(): Document {  
        return Jsoup.parse(file, "UTF-8")  
    }  
}

Attach Click listeners on elements

In DefaultElemetsAdapter class at line #27 l i defined a higher-order-function in the constructor method (which dose the same as defining an interface) and on line #75 we envoke the method passing our element and the position of the clicked view.

What about Unimplemented elements ?

the library will mark any unimplemented element as UnknownElement and will delegate it to the android.text.Html#fromHtml class to convert it Spans and will be displayed on TextView

TODO list:

  • [ ] Define a standard Layout styling.
  • [x] allow NetworkSource to run on UI thread without crashing.
  • [ ] Support the following elements:
    • [ ] Table
    • [x] Div
    • [x] Section
    • [ ] Superscript and Subscrpit
  • [ ] Test Element Extractors for different data sets.
  • [x] add more control over paragraph element. paragraph element will be rendered using the android.text.Html class rather than handled by the library
  • [ ] other thing that i come up with...

Dependencies:

PR are welcome just use crtl+alt+L or (command + alt+L for mac ... idk if right) after every time your finish write code to format it.

projects using this library:

if you are using this library in your project let me by sending an email at [email protected] know and i will post it here.

  • be the first on the list.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].