├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── dictionaries │ └── m7mdra.xml ├── gradle.xml ├── markdown-navigator.xml ├── markdown-navigator │ └── profiles_settings.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── build │ └── outputs │ │ └── apk │ │ └── debug │ │ ├── app-debug.apk │ │ └── output.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── m7mdra │ │ └── com │ │ └── htmlrecyclerview │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── m7mdra │ │ │ └── com │ │ │ └── htmlrecyclerview │ │ │ ├── Data.java │ │ │ ├── ImageFragment.kt │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── fragment_image.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── m7mdra │ └── com │ └── htmlrecyclerview │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── htmlrecycler ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── m7mdra │ │ └── com │ │ └── htmlrecycler │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── m7mdra │ │ │ └── com │ │ │ └── htmlrecycler │ │ │ ├── HtmlRecycler.java │ │ │ ├── ResizableImageView.java │ │ │ ├── adapter │ │ │ ├── DefaultElementsAdapter.kt │ │ │ ├── DescriptionListAdapter.kt │ │ │ ├── ElementsAdapter.kt │ │ │ ├── ListAdapter.kt │ │ │ └── ParagraphAdapter.kt │ │ │ ├── common.kt │ │ │ ├── elements │ │ │ ├── Element.kt │ │ │ ├── ElementIdentifier.kt │ │ │ └── ElementType.kt │ │ │ ├── extractor │ │ │ ├── AnchorLinkExtractor.kt │ │ │ ├── AudioExtractor.kt │ │ │ ├── DescriptionListExtractor.kt │ │ │ ├── Extractor.kt │ │ │ ├── HeadingExtractor.kt │ │ │ ├── IFrameExtractor.kt │ │ │ ├── ImageExtractor.kt │ │ │ ├── ListExtractor.kt │ │ │ ├── ParagraphExtractor.kt │ │ │ └── VideoExtractor.kt │ │ │ ├── model │ │ │ ├── AnchorLink.kt │ │ │ ├── DescriptionList.kt │ │ │ └── Row.kt │ │ │ ├── source │ │ │ ├── AssetSource.kt │ │ │ ├── FileSource.kt │ │ │ ├── NetworkSource.kt │ │ │ ├── Source.kt │ │ │ └── StringSource.kt │ │ │ └── viewholder │ │ │ ├── AnchorLinkViewHolder.kt │ │ │ ├── AudioViewHolder.kt │ │ │ ├── BlockQuoteViewHolder.kt │ │ │ ├── DescriptionItemViewHolder.kt │ │ │ ├── DescriptionListViewHolder.kt │ │ │ ├── DivViewHolder.kt │ │ │ ├── Heading1ViewHolder.kt │ │ │ ├── Heading2ViewHolder.kt │ │ │ ├── Heading3ViewHolder.kt │ │ │ ├── Heading4ViewHolder.kt │ │ │ ├── Heading5ViewHolder.kt │ │ │ ├── Heading6ViewHolder.kt │ │ │ ├── IFrameViewHolder.kt │ │ │ ├── ImageViewHolder.kt │ │ │ ├── ListItemViewHolder.kt │ │ │ ├── OrderedListViewHolder.kt │ │ │ ├── ParagraphViewHolder.kt │ │ │ ├── UnOrderedListViewHolder.kt │ │ │ ├── UnknownViewHolder.kt │ │ │ ├── VideoViewHolder.kt │ │ │ └── paragraph │ │ │ ├── AnchorLinkViewHolder.kt │ │ │ ├── BodyViewHolder.kt │ │ │ ├── BoldViewHolder.kt │ │ │ ├── EmphasizesViewHolder.kt │ │ │ └── UnderLineViewHolder.kt │ └── res │ │ ├── layout │ │ ├── row_anchor_link.xml │ │ ├── row_audio.xml │ │ ├── row_blockquote.xml │ │ ├── row_description_title_detail.xml │ │ ├── row_heading1.xml │ │ ├── row_heading2.xml │ │ ├── row_heading3.xml │ │ ├── row_heading4.xml │ │ ├── row_heading5.xml │ │ ├── row_heading6.xml │ │ ├── row_iframe.xml │ │ ├── row_image.xml │ │ ├── row_list.xml │ │ ├── row_list_item.xml │ │ ├── row_paragarph.xml │ │ ├── row_paragraph_item.xml │ │ ├── row_unknown.xml │ │ └── row_video.xml │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── m7mdra │ └── com │ └── htmlrecycler │ └── ExampleUnitTest.kt ├── media ├── demo1.gif └── demo2.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | 12 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/dictionaries/m7mdra.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | htmlfiy 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/markdown-navigator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 36 | 37 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /.idea/markdown-navigator/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### ***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.*** 2 | 3 | 4 | # HtmlRecycler 5 | Converts a simple html page into A `RecyclerView` of native android widgets powered by [Jsoup library](https://jsoup.org/) and inspired by [Medium Textview](https://github.com/angebagui/medium-textview/). 6 | 7 | 8 | > ### ***Note*** 9 | > 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` 10 | 11 | ## Add it to your project 12 | ```groovy 13 | dependencies { 14 | implementation 'com.github.m7mdra:HtmlRecycler:0.1.11' 15 | } 16 | ``` 17 | 18 | This project is distributed using jitpack. Make sure you add it as a maven repository to your `build.gradle` 19 | ```groovy 20 | allprojects { 21 | repositories { 22 | maven { 23 | url 'https://jitpack.io' 24 | } 25 | } 26 | } 27 | ``` 28 | 29 | ## Demo 30 | | | | 31 | |--|--| 32 | | ![enter image description here](https://raw.githubusercontent.com/m7mdra/HtmlRecycler/master/media/demo1.gif) | ![enter image description here](https://raw.githubusercontent.com/m7mdra/HtmlRecycler/master/media/demo2.gif) | 33 | 34 | - [APK](https://cdn.rawgit.com/m7mdra/HtmlRecycler/d278854a/app/build/outputs/apk/debug/app-debug.apk) 35 | - Or simply `git clone` the repository and build the `app` module. 36 | 37 | 38 | 39 | ## Currently supported html elements 40 | - [x] Paragraph 41 | - [x] H1...H6 42 | - [x] Image 43 | - [x] Video 44 | - [x] Audio 45 | - [x] Ordered List 46 | - [x] Unordered List 47 | - [x] Description List 48 | - [x] Anchor Link 49 | - [x] IFrame 50 | - [ ] Table 51 | - [x] DIV 52 | 53 | ## Implementation 54 | ```Kotlin 55 | val networkSource = NetworkSource("https://gist.githubusercontent.com/m7mdra/f22c62bc6941e08064b4fbceb4832a90/raw/ea8574d986635cf214541f1f5702ef37cc731aaf/article.html") 56 | 57 | HtmlRecycler.Builder(this@MainActivity) 58 | .setSource(networkSource) 59 | .setAdapter(DefaultElementsAdapter(this@MainActivity) { element, i, view -> 60 | }}) 61 | .setRecyclerView(recyclerView) 62 | .setLoadingCallback(object : HtmlRecycler.LoadCallback { 63 | override fun onLoadingStart() { 64 | progressBar.visibility = View.VISIBLE 65 | } 66 | override fun onLoaded(document: Document?) { 67 | progressBar.visibility = View.GONE 68 | } 69 | }) 70 | .build() 71 | ``` 72 | 73 | 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). 74 | 75 | Want to create your own adapter? just simply extend `ElementsAdapter` and override methods: 76 | ```Kotlin 77 | class BetterImplementationThanTheAuthorsAdapter : ElementsAdapter() { 78 | override fun onCreateElement(parent: ViewGroup, elementType: ElementType): RecyclerView.ViewHolder { 79 | when (elementType) { 80 | ElementType.Paragraph -> { 81 | return ParagraphViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragarph, parent, false)) 82 | } 83 | // Define other elements here 84 | } 85 | } 86 | 87 | override fun onBindElement(holder: RecyclerView.ViewHolder, position: Int) { 88 | val element = elements[position] //current element 89 | if (holder is ParagraphViewHolder){ 90 | val paragraphElement = element as ParagraphElement 91 | holder.paragraphText.text= paragraphElement.text 92 | } 93 | } 94 | } 95 | } 96 | ``` 97 | 98 | Then replace the default adapter with your adapter: 99 | ```Kotlin 100 | HtmlRecycler.Builder(this) 101 | .setSource(StringSource(Data.data)) 102 | .setAdapter(BetterImplementationThanTheAuthorsAdapter()) // this is a custom adapter 103 | .setRecyclerView(recyclerView) 104 | .build() 105 | ``` 106 | 107 | ### How to add Data 108 | Data can come from different sources, the library support the following: 109 | 110 | - [x] Assets 111 | - [x] File 112 | - [x] String 113 | - [x] Network (runs on `UI thread` by default so you have to run it on different thread or write your own Source Implementation ) 114 | 115 | ### Write your own source 116 | Simply implement the `Source` interface which will return a `Document` of the parsed `Source`: 117 | ```Kotlin 118 | class FileSource(val file: File) : Source { 119 | override fun get(): Document { 120 | return Jsoup.parse(file, "UTF-8") 121 | } 122 | } 123 | ``` 124 | 125 | ## Attach Click listeners on elements 126 | In `DefaultElemetsAdapter` class at line [#27](https://github.com/m7mdra/HtmlRecylcer/blob/master/htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/adapter/DefaultElementsAdapter.kt#L27) l i defined a [higher-order-function](https://kotlinlang.org/docs/reference/lambdas.html#higher-order-functions) in the constructor method (which dose the same as defining an interface) and on line [#75](https://github.com/m7mdra/HtmlRecylcer/blob/master/htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/adapter/DefaultElementsAdapter.kt#L75) we envoke the method passing our element and the position of the clicked view. 127 | ## What about Unimplemented elements ? 128 | 129 | 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` 130 | 131 | ## TODO list: 132 | - [ ] Define a standard Layout styling. 133 | - [x] allow `NetworkSource` to run on `UI thread` without crashing. 134 | - [ ] Support the following elements: 135 | - [ ] `Table` 136 | - [x] `Div` 137 | - [x] `Section` 138 | - [ ] `Superscript` and `Subscrpit` 139 | - [ ] Test Element Extractors for different data sets. 140 | - [x] ~~add more control over paragraph element.~~ paragraph element will be rendered using the `android.text.Html` class rather than handled by the library 141 | - [ ] other thing that i come up with... 142 | 143 | ## Dependencies: 144 | - [~~FlowLayoutManager~~](https://github.com/xiaofeng-han/AndroidLibs/tree/master/flowlayoutmanager) 145 | - [Jsoup](https://jsoup.org/) 146 | - [Picasso](https://github.com/square/picasso) 147 | 148 | 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**. 149 | ## projects using this library: 150 | if you are using this library in your project let me by sending an email at xm7mdrax@gmail.com know and i will post it here. 151 | 152 | - be the first on the list. 153 | 154 | 155 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build/tmp 2 | /build/kotlin 3 | /build/intermediates 4 | /build/generated 5 | /build/outputs/logs/ 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 27 9 | defaultConfig { 10 | applicationId "m7mdra.com.htmlrecyclerview" 11 | minSdkVersion 17 12 | targetSdkVersion 27 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:27.1.1' 29 | implementation 'com.android.support.constraint:constraint-layout:1.1.2' 30 | implementation 'com.android.support:support-v4:27.1.1' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | implementation project(":htmlrecycler") 35 | implementation 'com.android.support:recyclerview-v7:27.1.1' 36 | implementation 'org.jsoup:jsoup:1.11.3' 37 | implementation 'com.squareup.picasso:picasso:2.71828' 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /app/build/outputs/apk/debug/app-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/build/outputs/apk/debug/app-debug.apk -------------------------------------------------------------------------------- /app/build/outputs/apk/debug/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}] -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/m7mdra/com/htmlrecyclerview/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecyclerview 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("m7mdra.com.htmlrecyclerview", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/m7mdra/com/htmlrecyclerview/Data.java: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecyclerview; 2 | 3 | public class Data { 4 | public static String data = 5 | "

Hyundai Atos

\n" + 6 | "

\"\"

\n" + 7 | "

The Hyundai Atos was a city car produced by the South Korean manufacturer Hyundai since 1997. It was also marketed under the Atoz, Amica and Santro Xing model names. It was facelifted in 1999, from when it marketed as the Atos Prime, and in 2003. It has been available only with a five-door hatchback body style. It was replaced in most markets by the Hyundai i10 in 2007, but production continued in India till late 2014

\n" + 8 | "

\"\"

\n" + 9 | "

Overview

\n" + 10 | "

The first Atos was introduced in 1997. It is fitted with a 999cc engine and has a top speed of 88 mph (142 km/h). It was succeeded by a facelift version by 2000 and in 2003 another one. It was discontinued in Europe in 2007, in favour of the Indian assembled i10 and in other markets in 2011." + 11 | "Contact us on our website" + 12 | "

\n" + 13 | "

Other names

\n" + 14 | "

The Atos Prime is marketed as the:

\n" + 15 | "\n" + 22 | "

Hyundai entered the Indian market in 1997 with the Atos, marketed under the name Santro and various variants as Zip Drive, Zip Plus etc. Produced at Hyundai's factory in Chennai, its primary competitor at that time was the popular Maruti Suzuki Zen. The distinctive styling of the first generation had mixed reviews, but the car was a success primarily due to its power steering feature and price.

\n" + 23 | "

Variants in India

\n" + 24 | "

The Hyundai Santro was first released in India in 1998.It came with three variants:

\n" + 25 | "\n" + 33 | "

Specifications

\n" + 34 | "

Figures as listed for the 2000-2003, 5 door, 1.0i model with GSi trim as sold in the UK (as the Amica), with standard options.

\n" + 35 | "

Dimensions

\n" + 36 | "\n" + 43 | "

Technical data

\n" + 44 | "\n" + 55 | "

IFrame

\n" + 56 | "" + 57 | "

Video

\n" + 58 | "

\n" + 60 | "

Audio

\n" + 61 | "

"; 62 | public static String data2 = "

\"Editor

\n" + 63 | "\n" + 64 | "

Froala Editor is a lightweight WYSIWYG HTML Editor written in Javascript that enables rich text editing capabilities for your applications.

\n" + 65 | "\n" + 66 | "

Its complete documentation, specially designed framework plugins and tons of examples make it easy to integrate. We're continuously working to add in new features and take the Javascript web WYSIWYG editing capabilities beyond its current limits.

\n" + 67 | 68 | 69 | 70 | "
\n" + 71 | "
\n" + 72 | "
\n" + 73 | "

Smart contract development & Solidity

\n" + 74 | "
\n" + 75 | "\n" + 76 | "
\n" + 77 | "

Solidity

\n" + 78 | "

Solidity is a programming language for writing smart contracts which run on Ethereum Virtual Machine on Blockchain. It is a contract-oriented, high-level language.

\n" + 79 | "\n" + 80 | "
\n" + 81 | "\n" + 82 | "
\n" + 83 | "

Prerequisites

\n" + 84 | "
(Before learning Solidity)
\n" + 85 | "
    \n" + 86 | "
  • JavaScript (variable assignments, loops, arrays, functions)
  • \n" + 87 | "
  • Object-oriented programming concepts (classes, methods, static and instance variables)
  • \n" + 88 | "
  • Command line usage
  • \n" + 89 | "
\n" + 90 | "
\n" + 91 | "\n" + 92 | "
\n" + 93 | "

Part 1

\n" + 94 | "
    \n" + 95 | "
  • Environment setup
  • \n" + 96 | "
  • Data types
  • \n" + 97 | "
  • Operators
  • \n" + 98 | "
  • Functions
  • \n" + 99 | "
  • Visibility
  • \n" + 100 | "
  • ERC20 token standard interface
  • \n" + 101 | "
  • Dummy Token project
  • \n" + 102 | "
\n" + 103 | "
\n" + 104 | "\n" + 105 | "
\n" + 106 | "

Part 2

\n" + 107 | "
    \n" + 108 | "
  • Events and logging (finish Dummy Token project)
  • \n" + 109 | "
  • Inheritance and polymorphism
  • \n" + 110 | "
  • Exceptions
  • \n" + 111 | "
  • Security concerns
  • \n" + 112 | "
  • Deployment on Ethereum blockchain
  • \n" + 113 | "
\n" + 114 | "
\n" + 115 | "
\n" + 116 | "
\n"; 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /app/src/main/java/m7mdra/com/htmlrecyclerview/ImageFragment.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecyclerview 2 | 3 | 4 | import android.os.Bundle 5 | import android.support.v4.app.Fragment 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import com.squareup.picasso.Picasso 10 | import kotlinx.android.synthetic.main.fragment_image.* 11 | 12 | 13 | class ImageFragment : Fragment() { 14 | 15 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, 16 | savedInstanceState: Bundle?): View? { 17 | return inflater.inflate(R.layout.fragment_image, container, false) 18 | } 19 | 20 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 21 | super.onViewCreated(view, savedInstanceState) 22 | Picasso.get().load(arguments?.getString(IMAGE)).into(image) 23 | 24 | } 25 | 26 | companion object { 27 | const val IMAGE = "img" 28 | @JvmStatic 29 | fun newInstance(imageUrl: String): ImageFragment { 30 | val imageFragment = ImageFragment() 31 | val bundle = Bundle() 32 | bundle.putString(IMAGE, imageUrl) 33 | imageFragment.arguments = bundle 34 | return imageFragment 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/m7mdra/com/htmlrecyclerview/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecyclerview 2 | 3 | import android.annotation.SuppressLint 4 | import android.app.FragmentTransaction 5 | import android.support.v7.app.AppCompatActivity 6 | import android.os.Bundle 7 | import android.support.v4.view.accessibility.AccessibilityRecordCompat.setSource 8 | import android.view.View 9 | import android.widget.Toast 10 | import kotlinx.android.synthetic.main.activity_main.* 11 | import m7mdra.com.htmlrecycler.* 12 | import m7mdra.com.htmlrecycler.adapter.DefaultElementsAdapter 13 | import m7mdra.com.htmlrecycler.elements.ImageElement 14 | import m7mdra.com.htmlrecycler.source.NetworkSource 15 | import org.jsoup.nodes.Document 16 | 17 | 18 | class MainActivity : AppCompatActivity() { 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setContentView(R.layout.activity_main) 23 | val networkSource = NetworkSource("https://gist.githubusercontent.com/m7mdra/f22c62bc6941e08064b4fbceb4832a90/raw/ea8574d986635cf214541f1f5702ef37cc731aaf/article.html") 24 | 25 | HtmlRecycler.Builder(this@MainActivity) 26 | .setSource(networkSource) 27 | .setAdapter(DefaultElementsAdapter(this@MainActivity) { element, i, view -> 28 | 29 | Toast.makeText(this, "you clicked ${element::class.java.simpleName} element", Toast.LENGTH_SHORT).show() 30 | if (element is ImageElement) 31 | supportFragmentManager.beginTransaction().apply { 32 | replace(R.id.fragment_layout, ImageFragment.newInstance(element.ImageUrl)) 33 | setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_OPEN) 34 | commit() 35 | addToBackStack("") 36 | } 37 | }).setRecyclerView(recyclerView) 38 | .setLoadingCallback(object : HtmlRecycler.LoadCallback { 39 | override fun onLoadingStart() { 40 | progressBar.visibility = View.VISIBLE 41 | } 42 | 43 | override fun onLoaded(document: Document?) { 44 | progressBar.visibility = View.GONE 45 | 46 | } 47 | }) 48 | .build() 49 | 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 14 | 18 | 19 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | HtmlRecyclerView 3 | 4 | 5 | Hello blank fragment 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/m7mdra/com/htmlrecyclerview/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecyclerview 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.2.51' 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.2.0-beta05' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Aug 12 13:11:01 EAT 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /htmlrecycler/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /htmlrecycler/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdkVersion 27 6 | 7 | 8 | 9 | defaultConfig { 10 | minSdkVersion 17 11 | targetSdkVersion 27 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | 31 | implementation 'com.android.support:appcompat-v7:27.1.1' 32 | testImplementation 'junit:junit:4.12' 33 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 35 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 36 | 37 | implementation 'org.jsoup:jsoup:1.11.3' 38 | implementation 'com.squareup.picasso:picasso:2.71828' 39 | implementation 'com.android.support:recyclerview-v7:27.1.1' 40 | 41 | } 42 | repositories { 43 | mavenCentral() 44 | } 45 | -------------------------------------------------------------------------------- /htmlrecycler/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /htmlrecycler/src/androidTest/java/m7mdra/com/htmlrecycler/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("m7mdra.com.htmlrecycler.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/HtmlRecycler.java: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler; 2 | 3 | import android.content.Context; 4 | import android.os.AsyncTask; 5 | import android.support.v7.widget.DefaultItemAnimator; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | import org.jsoup.nodes.Document; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | import m7mdra.com.htmlrecycler.adapter.ElementsAdapter; 15 | import m7mdra.com.htmlrecycler.elements.Element; 16 | import m7mdra.com.htmlrecycler.elements.ElementIdentifier; 17 | import m7mdra.com.htmlrecycler.source.Source; 18 | 19 | public class HtmlRecycler { 20 | private RecyclerView recyclerView; 21 | private ElementsAdapter adapter; 22 | private Source source; 23 | private LoadCallback mLoadCallback; 24 | 25 | private HtmlRecycler(Builder builder) { 26 | recyclerView = builder.recyclerView; 27 | adapter = builder.adapter; 28 | source = builder.source; 29 | mLoadCallback = builder.loadingCallback; 30 | } 31 | 32 | public static final class Builder { 33 | public LoadCallback loadingCallback; 34 | private RecyclerView recyclerView; 35 | private ElementsAdapter adapter; 36 | private Source source; 37 | private Context context; 38 | 39 | public Builder(Context context) { 40 | this.context = context; 41 | } 42 | 43 | 44 | public Builder setRecyclerView(RecyclerView val) { 45 | recyclerView = val; 46 | return this; 47 | } 48 | 49 | public Builder setLoadingCallback(LoadCallback loadingCallback) { 50 | this.loadingCallback = loadingCallback; 51 | return this; 52 | } 53 | 54 | public Builder setAdapter(ElementsAdapter val) { 55 | adapter = val; 56 | return this; 57 | } 58 | 59 | public Builder setSource(Source val) { 60 | source = val; 61 | return this; 62 | } 63 | 64 | private static final String TAG = "Builder"; 65 | 66 | public HtmlRecycler build() { 67 | final DocumentParseTask documentParseTask = new DocumentParseTask(source, new LoadCallback() { 68 | @Override 69 | public void onLoaded(Document document) { 70 | if (loadingCallback != null) 71 | loadingCallback.onLoaded(document); 72 | List elements = new ArrayList<>(); 73 | ElementIdentifier.extractData(elements, document.body().children()); 74 | adapter.addElements(elements); 75 | recyclerView.setAdapter(adapter); 76 | recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); 77 | recyclerView.setItemAnimator(new DefaultItemAnimator()); 78 | recyclerView.setHasFixedSize(true); 79 | } 80 | 81 | @Override 82 | public void onLoadingStart() { 83 | if (loadingCallback != null) 84 | loadingCallback.onLoadingStart(); 85 | } 86 | 87 | }); 88 | documentParseTask.execute(); 89 | return new HtmlRecycler(this); 90 | } 91 | } 92 | 93 | static class DocumentParseTask extends AsyncTask { 94 | private LoadCallback mLoadCallback; 95 | private Source source; 96 | 97 | public DocumentParseTask(Source source, LoadCallback loadCallback) { 98 | mLoadCallback = loadCallback; 99 | this.source = source; 100 | } 101 | 102 | @Override 103 | protected void onPreExecute() { 104 | super.onPreExecute(); 105 | mLoadCallback.onLoadingStart(); 106 | } 107 | 108 | @Override 109 | protected Document doInBackground(Void... voids) { 110 | return source.get(); 111 | } 112 | 113 | @Override 114 | protected void onPostExecute(Document document) { 115 | super.onPostExecute(document); 116 | mLoadCallback.onLoaded(document); 117 | } 118 | 119 | 120 | } 121 | 122 | public interface LoadCallback { 123 | void onLoaded(Document document); 124 | 125 | void onLoadingStart(); 126 | 127 | 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/ResizableImageView.java: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.util.AttributeSet; 6 | import android.widget.ImageView; 7 | 8 | public class ResizableImageView extends android.support.v7.widget.AppCompatImageView { 9 | 10 | public ResizableImageView(Context context, AttributeSet attrs) { 11 | super(context, attrs); 12 | } 13 | 14 | @Override 15 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 16 | Drawable d = getDrawable(); 17 | 18 | if (d != null) { 19 | int width = MeasureSpec.getSize(widthMeasureSpec); 20 | int height = (int) Math.ceil((float) width * (float) d.getIntrinsicHeight() / (float) d.getIntrinsicWidth()); 21 | setMeasuredDimension(width, height); 22 | } else { 23 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/adapter/DefaultElementsAdapter.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.adapter 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.graphics.drawable.ColorDrawable 6 | import android.net.Uri 7 | import android.support.v7.widget.LinearLayoutManager 8 | import android.support.v7.widget.RecyclerView 9 | import android.view.LayoutInflater 10 | import android.view.View 11 | import android.view.ViewGroup 12 | import android.widget.Toast 13 | import com.squareup.picasso.Picasso 14 | import m7mdra.com.htmlrecycler.* 15 | import m7mdra.com.htmlrecycler.elements.* 16 | import m7mdra.com.htmlrecycler.viewholder.* 17 | 18 | class DefaultElementsAdapter(private val context: Context, private val onClick: (Element, Int, View) -> Unit) : ElementsAdapter() { 19 | 20 | override fun onCreateElement(parent: ViewGroup, elementType: ElementType): RecyclerView.ViewHolder { 21 | return when (elementType) { 22 | ElementType.Heading1 -> 23 | Heading1ViewHolder(LayoutInflater.from(context).inflate(R.layout.row_heading1, parent, false)) 24 | ElementType.Heading2 -> 25 | Heading2ViewHolder(LayoutInflater.from(context).inflate(R.layout.row_heading2, parent, false)) 26 | ElementType.Heading3 -> 27 | Heading3ViewHolder(LayoutInflater.from(context).inflate(R.layout.row_heading3, parent, false)) 28 | ElementType.Heading4 -> 29 | Heading4ViewHolder(LayoutInflater.from(context).inflate(R.layout.row_heading4, parent, false)) 30 | ElementType.Heading5 -> 31 | Heading5ViewHolder(LayoutInflater.from(context).inflate(R.layout.row_heading5, parent, false)) 32 | ElementType.Heading6 -> 33 | Heading6ViewHolder(LayoutInflater.from(context).inflate(R.layout.row_heading6, parent, false)) 34 | ElementType.IFrame -> 35 | IFrameViewHolder(LayoutInflater.from(context).inflate(R.layout.row_iframe, parent, false)) 36 | ElementType.Image -> 37 | ImageViewHolder(LayoutInflater.from(context).inflate(R.layout.row_image, parent, false)) 38 | ElementType.Video -> 39 | VideoViewHolder(LayoutInflater.from(context).inflate(R.layout.row_video, parent, false)) 40 | ElementType.Audio -> 41 | AudioViewHolder(LayoutInflater.from(context).inflate(R.layout.row_audio, parent, false)) 42 | ElementType.Paragraph -> 43 | ParagraphViewHolder(LayoutInflater.from(context).inflate(R.layout.row_paragarph, parent, false)) 44 | ElementType.Div -> 45 | DivViewHolder(LayoutInflater.from(context).inflate(R.layout.row_paragarph, parent, false)) 46 | ElementType.BlockQuote -> 47 | BlockQuoteViewHolder(LayoutInflater.from(context).inflate(R.layout.row_blockquote, parent, false)) 48 | ElementType.Unknown -> 49 | UnknownViewHolder(LayoutInflater.from(context).inflate(R.layout.row_unknown, parent, false)) 50 | ElementType.AnchorLink -> 51 | AnchorLinkViewHolder(LayoutInflater.from(context).inflate(R.layout.row_anchor_link, parent, false)) 52 | ElementType.OrderedList -> 53 | OrderedListViewHolder(LayoutInflater.from(context).inflate(R.layout.row_list, parent, false)) 54 | ElementType.UnorderedList -> 55 | UnOrderedListViewHolder(LayoutInflater.from(context).inflate(R.layout.row_list, parent, false)) 56 | ElementType.DescriptionList -> 57 | DescriptionListViewHolder(LayoutInflater.from(context).inflate(R.layout.row_list, parent, false)) 58 | else -> 59 | UnknownViewHolder(LayoutInflater.from(context).inflate(R.layout.row_unknown, parent, false)) 60 | } 61 | } 62 | 63 | override fun onBindElement(holder: RecyclerView.ViewHolder, position: Int) { 64 | val element = elements[position] 65 | holder.itemView.setOnClickListener { 66 | onClick(element, holder.adapterPosition, it) 67 | } 68 | when (holder) { 69 | is Heading1ViewHolder -> { 70 | val heading1Element = element as Heading1Element 71 | holder.headingView.text = heading1Element.text 72 | } 73 | is Heading2ViewHolder -> { 74 | val heading1Element = element as Heading2Element 75 | holder.headingView.text = heading1Element.text 76 | } 77 | is Heading3ViewHolder -> { 78 | 79 | val heading1Element = element as Heading3Element 80 | holder.headingView.text = heading1Element.text 81 | } 82 | is Heading4ViewHolder -> { 83 | 84 | val heading1Element = element as Heading4Element 85 | holder.headingView.text = heading1Element.text 86 | } 87 | is Heading5ViewHolder -> { 88 | val heading1Element = element as Heading5Element 89 | holder.headingView.text = heading1Element.text 90 | } 91 | is Heading6ViewHolder -> { 92 | val heading1Element = element as Heading6Element 93 | holder.headingView.text = heading1Element.text 94 | } 95 | is ParagraphViewHolder -> { 96 | val paragraphElement = element as ParagraphElement 97 | holder.paragraphText.text= htmlfiy(paragraphElement.paragraph) 98 | 99 | } 100 | is AnchorLinkViewHolder -> { 101 | val anchorLinkElement = element as AnchorLinkElement 102 | val anchorUrl = anchorLinkElement.anchorUrl 103 | holder.anchorTextView.text = anchorUrl.displayText 104 | holder.anchorTextView.setOnClickListener { 105 | Toast.makeText(context, anchorUrl.anchorUrl, Toast.LENGTH_SHORT).show() 106 | } 107 | } 108 | is ImageViewHolder -> { 109 | Picasso.get().load((element as ImageElement).ImageUrl) 110 | .placeholder(ColorDrawable(Color.parseColor("#EFF0EE"))) 111 | .error(ColorDrawable(Color.parseColor("#EFF0EE"))) 112 | .into(holder.image) 113 | } 114 | is BlockQuoteViewHolder -> { 115 | holder.blockQuoteTextView.text = (element as BlockQuoteElement).text 116 | } 117 | is OrderedListViewHolder -> { 118 | holder.recyclerView.apply { 119 | val itemList = (element as OrderListElement).list 120 | adapter = ListAdapter(itemList.first, itemList.second) 121 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 122 | } 123 | } 124 | is UnOrderedListViewHolder -> { 125 | holder.recyclerView.apply { 126 | val itemList = (element as UnOrderListElement).list 127 | adapter = ListAdapter(itemList.first, itemList.second) 128 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 129 | } 130 | } 131 | is DescriptionListViewHolder -> { 132 | holder.recyclerView.apply { 133 | val descriptionList = (element as DescriptionListElement).descriptionList 134 | adapter = DescriptionListAdapter(descriptionList) 135 | layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) 136 | } 137 | } 138 | is VideoViewHolder -> { 139 | holder.videoView.apply { 140 | val videoElement = element as VideoElement 141 | val parse = Uri.parse(videoElement.videoSourceUrl) 142 | setVideoURI(parse) 143 | start() 144 | } 145 | } 146 | is AudioViewHolder -> { 147 | holder.videoView.apply { 148 | val parse = Uri.parse((element as AudioElement).audioSourceUrl) 149 | setVideoURI(parse) 150 | start() 151 | } 152 | 153 | } 154 | is IFrameViewHolder -> { 155 | holder.iframeView.loadUrl((element as IFrameElement).url) 156 | holder.iframeView.settings.javaScriptEnabled = true 157 | } 158 | 159 | is UnknownViewHolder->{ 160 | holder.unknownTextView.text= htmlfiy((element as UnknownElement).html) 161 | 162 | } 163 | 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/adapter/DescriptionListAdapter.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.adapter 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.LayoutInflater 5 | import android.view.ViewGroup 6 | import m7mdra.com.htmlrecycler.R 7 | import m7mdra.com.htmlrecycler.model.DescriptionList 8 | import m7mdra.com.htmlrecycler.viewholder.DescriptionItemViewHolder 9 | 10 | class DescriptionListAdapter(val list: List) : RecyclerView.Adapter() { 11 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DescriptionItemViewHolder { 12 | return DescriptionItemViewHolder(LayoutInflater.from(parent.context) 13 | .inflate(R.layout.row_description_title_detail, parent, false)) 14 | } 15 | 16 | override fun getItemCount(): Int = list.size 17 | 18 | override fun onBindViewHolder(holder: DescriptionItemViewHolder, position: Int) { 19 | val description = list[position] 20 | holder.title.text = description.descriptionTitle 21 | holder.description.text = description.descriptionData 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/adapter/ElementsAdapter.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.adapter 2 | 3 | 4 | import android.support.v7.widget.RecyclerView 5 | import android.util.Log 6 | import android.view.ViewGroup 7 | import m7mdra.com.htmlrecycler.elements.ElementType 8 | import m7mdra.com.htmlrecycler.elements.* 9 | 10 | abstract class ElementsAdapter() : RecyclerView.Adapter() { 11 | 12 | abstract fun onCreateElement(parent: ViewGroup, elementType: ElementType): RecyclerView.ViewHolder 13 | abstract fun onBindElement(holder: RecyclerView.ViewHolder, position: Int) 14 | val elements = mutableListOf() 15 | 16 | 17 | fun addElements(elementList: List) { 18 | elements.clear() 19 | elements.addAll(elementList) 20 | notifyDataSetChanged() 21 | } 22 | 23 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 24 | Log.d("MEGA", "${findElementWith(viewType)}") 25 | return onCreateElement(parent, findElementWith(viewType)) 26 | 27 | } 28 | 29 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 30 | onBindElement(holder, position) 31 | } 32 | 33 | 34 | override fun getItemCount(): Int { 35 | return elements.size 36 | } 37 | 38 | override fun getItemViewType(position: Int): Int { 39 | val element = elements[position] 40 | return when (element) { 41 | is AnchorLinkElement -> TYPE_ANCHOR_LINK 42 | is VideoElement -> TYPE_VIDEO 43 | is BlockQuoteElement -> TYPE_BLOCK_QUOTE 44 | is Heading1Element -> TYPE_HEADING1 45 | is Heading2Element -> TYPE_HEADING2 46 | is Heading3Element -> TYPE_HEADING3 47 | is Heading4Element -> TYPE_HEADING4 48 | is Heading5Element -> TYPE_HEADING5 49 | is Heading6Element -> TYPE_HEADING6 50 | is ImageElement -> TYPE_IMAGE 51 | is IFrameElement -> TYPE_IFRMAE 52 | is AudioElement -> TYPE_AUDIO 53 | is ParagraphElement -> TYPE_PARAGRAPH 54 | is UnknownElement -> TYPE_UNKNOWN 55 | is DescriptionListElement -> TYPE_DESCRIPTION_LIST 56 | is UnOrderListElement -> TYPE_UNORDERED_LIST 57 | is OrderListElement -> TYPE_ORDERED_LIST 58 | } 59 | } 60 | 61 | companion object { 62 | const val TYPE_UNKNOWN = -1 63 | const val TYPE_HEADING1 = 1 64 | const val TYPE_HEADING2 = 2 65 | const val TYPE_HEADING3 = 3 66 | const val TYPE_HEADING4 = 4 67 | const val TYPE_HEADING5 = 5 68 | const val TYPE_HEADING6 = 6 69 | const val TYPE_IFRMAE = 7 70 | const val TYPE_BLOCK_QUOTE = 8 71 | const val TYPE_PARAGRAPH = 9 72 | const val TYPE_ANCHOR_LINK = 10 73 | const val TYPE_IMAGE = 11 74 | const val TYPE_VIDEO = 12 75 | const val TYPE_AUDIO = 13 76 | const val TYPE_ORDERED_LIST = 14 77 | const val TYPE_DESCRIPTION_LIST = 15 78 | const val TYPE_DIV = 16 79 | const val TYPE_TABLE = 17 80 | const val TYPE_UNORDERED_LIST = 18 81 | } 82 | 83 | private fun findElementWith(type: Int): ElementType { 84 | for (value in ElementType.values()) { 85 | if (value.ordinal == type) 86 | return value 87 | } 88 | return ElementType.Unknown 89 | } 90 | 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/adapter/ListAdapter.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.adapter 2 | 3 | import android.graphics.Typeface 4 | import android.support.v7.widget.RecyclerView 5 | import android.text.* 6 | import android.text.style.StyleSpan 7 | import android.view.LayoutInflater 8 | import android.view.ViewGroup 9 | import m7mdra.com.htmlrecycler.R 10 | import m7mdra.com.htmlrecycler.viewholder.ListItemViewHolder 11 | 12 | class ListAdapter(private val type: String, private val list: List) : RecyclerView.Adapter() { 13 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListItemViewHolder { 14 | return ListItemViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_list_item, parent, false)) 15 | } 16 | 17 | private val listType: ListType 18 | 19 | init { 20 | listType = if (type == "ol") 21 | ListType.Ordered 22 | else 23 | ListType.Unordered 24 | } 25 | 26 | override fun getItemCount(): Int = list.size 27 | 28 | override fun onBindViewHolder(holder: ListItemViewHolder, position: Int) { 29 | 30 | holder.listItem.text = if (listType == ListType.Unordered) 31 | "${boldyify("*")} ${list[position]}" 32 | else 33 | "${position + 1}- ${list[position]}" 34 | } 35 | 36 | enum class ListType { 37 | Ordered, Unordered 38 | } 39 | 40 | fun boldyify(text: String): Spanned { 41 | val spannableString = SpannableStringBuilder(text) 42 | spannableString.setSpan(StyleSpan(Typeface.BOLD), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) 43 | return spannableString 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/adapter/ParagraphAdapter.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.adapter 2 | 3 | import android.graphics.Color 4 | import android.support.v7.widget.RecyclerView 5 | import android.view.LayoutInflater 6 | import android.view.ViewGroup 7 | import android.widget.Toast 8 | import m7mdra.com.htmlrecycler.R 9 | import m7mdra.com.htmlrecycler.elements.* 10 | import m7mdra.com.htmlrecycler.htmlfiy 11 | import m7mdra.com.htmlrecycler.viewholder.UnknownViewHolder 12 | import m7mdra.com.htmlrecycler.viewholder.paragraph.* 13 | 14 | class ParagraphAdapter(private val list: List) : RecyclerView.Adapter() { 15 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder = when (viewType) { 16 | UNDERLINE -> 17 | UnderLineViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragraph_item, parent, false)) 18 | ANCHOR_LINK -> 19 | AnchorLinkViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragraph_item, parent, false)) 20 | BODY -> 21 | BodyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragraph_item, parent, false)) 22 | BOLD -> 23 | BoldViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragraph_item, parent, false)) 24 | EMPHASIZES -> 25 | EmphasizesViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragraph_item, parent, false)) 26 | UNKNOWN -> 27 | UnknownViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragraph_item, parent, false)) 28 | else -> 29 | UnknownViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_paragraph_item, parent, false)) 30 | 31 | } 32 | 33 | 34 | override fun getItemCount(): Int = list.size 35 | 36 | 37 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 38 | val paragraph = list[position] 39 | when (holder) { 40 | is EmphasizesViewHolder -> holder.paragraphText.text = htmlfiy("${(paragraph as Emphasizes).text}") 41 | is BodyViewHolder -> holder.paragraphText.text = (paragraph as Body).bodyText 42 | is AnchorLinkViewHolder -> { 43 | val anchorLink = paragraph as AnchorLinkInParagraph 44 | holder.paragraphText.apply { 45 | text = anchorLink.text 46 | setTextColor(Color.BLUE) 47 | setOnClickListener { 48 | Toast.makeText(holder.itemView.context, anchorLink.url, Toast.LENGTH_SHORT).show() 49 | } 50 | } 51 | } 52 | is UnderLineViewHolder -> 53 | holder.paragraphText.text = htmlfiy("${(paragraph as UnderLine).text}") 54 | 55 | is BoldViewHolder-> 56 | holder.paragraphText.text = htmlfiy("${(paragraph as Bold).text}") 57 | 58 | } 59 | 60 | } 61 | 62 | override fun getItemViewType(position: Int): Int = when (list[position]) { 63 | is Body -> BODY 64 | is UnderLine -> UNDERLINE 65 | is AnchorLinkInParagraph -> ANCHOR_LINK 66 | is Bold -> BOLD 67 | is Emphasizes -> EMPHASIZES 68 | 69 | else -> UNKNOWN 70 | } 71 | 72 | companion object { 73 | const val UNKNOWN = 0 74 | 75 | const val ANCHOR_LINK = 1 76 | const val BODY = 2 77 | const val BOLD = 3 78 | const val EMPHASIZES = 4 79 | const val UNDERLINE = 5 80 | 81 | } 82 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/common.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package m7mdra.com.htmlrecycler 4 | 5 | import android.text.Html 6 | import android.text.Spanned 7 | import android.util.Log 8 | 9 | fun htmlfiy(html: String): Spanned { 10 | return if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) 11 | Html.fromHtml(html, Html.FROM_HTML_MODE_COMPACT) 12 | else 13 | Html.fromHtml(html) 14 | } 15 | 16 | fun Any.println() { 17 | println(this) 18 | } 19 | 20 | fun Any.log(){ 21 | Log.d("MEGA","$this") 22 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/elements/Element.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.elements 2 | 3 | import m7mdra.com.htmlrecycler.model.AnchorLink 4 | import m7mdra.com.htmlrecycler.model.DescriptionList 5 | 6 | sealed class Element 7 | 8 | data class DescriptionListElement(val descriptionList: List) : Element() 9 | data class OrderListElement(val list: Pair>) : Element() 10 | data class ImageElement(val ImageUrl: String) : Element() 11 | data class ParagraphElement(val paragraph: String) : Element() 12 | data class UnOrderListElement(val list: Pair>) : Element() 13 | data class Heading1Element(val text: String) : Element() 14 | data class Heading2Element(val text: String) : Element() 15 | data class Heading3Element(val text: String) : Element() 16 | data class Heading4Element(val text: String) : Element() 17 | data class Heading5Element(val text: String) : Element() 18 | data class Heading6Element(val text: String) : Element() 19 | data class VideoElement(val videoSourceUrl: String, val videoThumbnailUrl: String = "") : Element() 20 | data class AudioElement(val audioSourceUrl: String) : Element() 21 | data class AnchorLinkElement(val anchorUrl: AnchorLink) : Element() 22 | data class BlockQuoteElement(val text: String) : Element() 23 | data class IFrameElement(val url: String) : Element() 24 | data class UnknownElement(val html:String) : Element() 25 | 26 | sealed class Paragraph 27 | 28 | data class Body(val bodyText: String) : Paragraph() 29 | data class AnchorLinkInParagraph(val text: String, val url: String) : Paragraph() 30 | data class UnderLine(val text: String) : Paragraph() 31 | data class Bold(val text: String) : Paragraph() 32 | data class Emphasizes(val text: String) : Paragraph() 33 | class Unknown : Paragraph() 34 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/elements/ElementIdentifier.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.elements 2 | 3 | import android.util.Log 4 | import junit.framework.Assert 5 | import m7mdra.com.htmlrecycler.extractor.* 6 | import m7mdra.com.htmlrecycler.log 7 | import m7mdra.com.htmlrecycler.model.AnchorLink 8 | import m7mdra.com.htmlrecycler.model.DescriptionList 9 | import m7mdra.com.htmlrecycler.println 10 | import org.jsoup.nodes.Element 11 | import org.jsoup.nodes.TextNode 12 | import org.jsoup.select.Elements 13 | 14 | class ElementIdentifier(private val element: Element) { 15 | fun identify(): ElementType = when (element.tagName()) { 16 | "h1" -> ElementType.Heading1 17 | "h2" -> ElementType.Heading2 18 | "h3" -> ElementType.Heading3 19 | "h4" -> ElementType.Heading4 20 | "h5" -> ElementType.Heading5 21 | "h6" -> ElementType.Heading6 22 | "blockquote" -> ElementType.BlockQuote 23 | "p" -> ElementType.Paragraph 24 | "iframe" -> ElementType.IFrame 25 | "a" -> ElementType.AnchorLink 26 | "img" -> ElementType.Image 27 | "video" -> ElementType.Video 28 | "audio" -> ElementType.Audio 29 | "ol" -> ElementType.OrderedList 30 | "ul" -> ElementType.UnorderedList 31 | "dl" -> ElementType.DescriptionList 32 | "div" -> ElementType.Div 33 | "section" -> ElementType.Section 34 | else -> ElementType.Unknown 35 | } 36 | 37 | 38 | companion object { 39 | @JvmStatic 40 | fun extractData(elementList: MutableList, elements: Elements) { 41 | elements.forEach { 42 | when (ElementIdentifier(it).identify()) { 43 | ElementType.Image -> { 44 | val imageUrl = ImageExtractor(it).extract() 45 | elementList.add(ImageElement(imageUrl)) 46 | } 47 | ElementType.Heading1 -> { 48 | val heading = HeadingExtractor(it).extract() 49 | elementList.add(Heading1Element(heading)) 50 | 51 | } 52 | ElementType.Heading2 -> { 53 | val heading = HeadingExtractor(it).extract() 54 | elementList.add(Heading2Element(heading)) 55 | 56 | } 57 | ElementType.Heading3 -> { 58 | val heading = HeadingExtractor(it).extract() 59 | elementList.add(Heading3Element(heading)) 60 | 61 | } 62 | ElementType.Heading4 -> { 63 | val heading = HeadingExtractor(it).extract() 64 | elementList.add(Heading4Element(heading)) 65 | 66 | } 67 | ElementType.Heading5 -> { 68 | val heading = HeadingExtractor(it).extract() 69 | elementList.add(Heading5Element(heading)) 70 | 71 | } 72 | ElementType.Heading6 -> { 73 | val heading = HeadingExtractor(it).extract() 74 | elementList.add(Heading6Element(heading)) 75 | 76 | } 77 | ElementType.UnorderedList -> { 78 | val listExtractor = ListExtractor(it).extract() 79 | elementList.add(UnOrderListElement(listExtractor)) 80 | } 81 | ElementType.OrderedList -> { 82 | val listExtractor = ListExtractor(it).extract() 83 | elementList.add(OrderListElement(listExtractor)) 84 | } 85 | ElementType.Video -> { 86 | val videoUrl = VideoExtractor(it).extract() 87 | elementList.add(VideoElement(videoUrl)) 88 | } 89 | ElementType.AnchorLink -> { 90 | val anchorLink = AnchorLinkExtractor(it).extract() 91 | elementList.add(AnchorLinkElement(AnchorLink(anchorLink.first, anchorLink.second))) 92 | } 93 | ElementType.DescriptionList -> { 94 | val extract = DescriptionListExtractor(it).extract() 95 | val descriptionList = mutableListOf() 96 | extract.forEach { 97 | descriptionList.add(DescriptionList(it.first, it.second)) 98 | } 99 | val descriptionListElement = DescriptionListElement(descriptionList) 100 | elementList.add(descriptionListElement) 101 | } 102 | ElementType.Div -> extractData(elementList, it.children()) 103 | ElementType.Paragraph -> { 104 | val children = it.children() 105 | if (children.size > 0 && 106 | it.getElementsByTag("img").isNotEmpty() || 107 | it.getElementsByTag("audio").isNotEmpty() || 108 | it.getElementsByTag("video").isNotEmpty()) 109 | extractData(elementList, children) 110 | else { 111 | elementList.add(ParagraphElement(it.toString())) 112 | } 113 | } 114 | ElementType.BlockQuote -> { 115 | elementList.add(BlockQuoteElement(it.text())) 116 | } 117 | 118 | ElementType.IFrame -> { 119 | 120 | } 121 | ElementType.Audio -> { 122 | val audio = AudioExtractor(it).extract() 123 | elementList.add(AudioElement(audio)) 124 | } 125 | ElementType.Unknown -> { 126 | elementList.add(UnknownElement(it.toString())) 127 | } 128 | ElementType.Section -> extractData(elementList, it.children()) 129 | else -> { 130 | elementList.add(UnknownElement(it.toString())) 131 | } 132 | } 133 | } 134 | elementList.map { it::class.java.simpleName }.log() 135 | } 136 | } 137 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/elements/ElementType.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.elements 2 | 3 | enum class ElementType(type: Int) { 4 | Unknown(-1), 5 | Heading1(1), 6 | Heading2(2), 7 | Heading3(3), 8 | Heading4(4), 9 | Heading5(5), 10 | Heading6(6), 11 | IFrame(7), 12 | BlockQuote(8), 13 | Paragraph(9), 14 | AnchorLink(10), 15 | Image(11), 16 | Video(12), 17 | Audio(13), 18 | OrderedList(14), 19 | DescriptionList(15), 20 | Div(16), 21 | Table(17), 22 | UnorderedList(18), 23 | Section(19) 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/AnchorLinkExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | class AnchorLinkExtractor(val element: Element) : Extractor>(element) { 6 | override fun extract(): Pair { 7 | return element.text() to element.attr("href") 8 | } 9 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/AudioExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | class AudioExtractor(val e: Element) : Extractor(e) { 6 | override fun extract(): String { 7 | return e.attr("src") 8 | } 9 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/DescriptionListExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | class DescriptionListExtractor(val element: Element) : Extractor>>(element) { 6 | override fun extract(): List> { 7 | val list = mutableListOf>() 8 | val dts = element.getElementsByTag("dt") 9 | val dds = element.getElementsByTag("dd") 10 | dts.forEachIndexed { index, element -> 11 | list.add(Pair(element.text(), dds[index].text())) 12 | } 13 | return list 14 | } 15 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/Extractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | abstract class Extractor(private val element: Element) { 6 | abstract fun extract(): T 7 | init { 8 | requireNotNull(element){ 9 | "Element can not be null" 10 | } 11 | } 12 | 13 | 14 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/HeadingExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | class HeadingExtractor(val element: Element) : Extractor(element) { 6 | override fun extract(): String { 7 | return element.text() 8 | } 9 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/IFrameExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | 6 | class IFrameExtractor(val element: Element) : Extractor(element) { 7 | override fun extract(): String { 8 | return element.attr("abs:src") 9 | } 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/ImageExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | class ImageExtractor(val element: Element) : Extractor(element) { 6 | override fun extract(): String { 7 | val src = element.attr("src") 8 | val absSrc = element.attr("abs:src") 9 | return if (absSrc.isNotEmpty()) 10 | absSrc 11 | else 12 | src 13 | } 14 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/ListExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | 6 | class ListExtractor(private val element: Element) : Extractor>>(element) { 7 | override fun extract(): Pair> { 8 | return element.tagName() to element.children().map { it.text() } 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/ParagraphExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import android.os.Build 4 | import android.text.Html 5 | import android.text.Spannable 6 | import android.text.Spanned 7 | import org.jsoup.nodes.Element 8 | 9 | @Suppress("DEPRECATION") 10 | class ParagraphExtractor(val element: Element) :Extractor(element) { 11 | override fun extract(): Spanned { 12 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) 13 | Html.fromHtml(element.html(),Html.FROM_HTML_MODE_LEGACY) 14 | else 15 | Html.fromHtml(element.html()) 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/extractor/VideoExtractor.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.extractor 2 | 3 | import org.jsoup.nodes.Element 4 | 5 | class VideoExtractor(val element: Element) : Extractor(element) { 6 | override fun extract(): String { 7 | return if (element.children().size > 0) 8 | element.child(0).attr("abs:src") 9 | else element.attr("abs:src") 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/model/AnchorLink.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.model 2 | 3 | data class AnchorLink(val displayText: String, val anchorUrl: String) -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/model/DescriptionList.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.model 2 | 3 | data class DescriptionList(val descriptionTitle: String, val descriptionData: String) -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/model/Row.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.model 2 | 3 | data class Row(val list: List = mutableListOf()) 4 | 5 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/source/AssetSource.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.source 2 | 3 | import android.content.Context 4 | import org.jsoup.Jsoup 5 | import org.jsoup.nodes.Document 6 | 7 | class AssetSource(private val context: Context, private val uri: String) : Source { 8 | override fun get(): Document { 9 | return Jsoup.parse(context.assets.open(uri).bufferedReader().readLines().joinToString { it }) 10 | } 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/source/FileSource.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.source 2 | 3 | import org.jsoup.Jsoup 4 | import org.jsoup.nodes.Document 5 | import java.io.File 6 | 7 | class FileSource(val file: File) : Source { 8 | override fun get(): Document { 9 | return Jsoup.parse(file, "UTF-8") 10 | } 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/source/NetworkSource.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.source 2 | 3 | import android.os.HandlerThread 4 | import android.os.Looper 5 | import android.os.NetworkOnMainThreadException 6 | import android.support.annotation.WorkerThread 7 | import org.jsoup.Jsoup 8 | import org.jsoup.nodes.Document 9 | import java.util.logging.Handler 10 | 11 | @WorkerThread 12 | class NetworkSource(private val url: String) : Source { 13 | override fun get(): Document { 14 | return Jsoup.connect(url).get() 15 | } 16 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/source/Source.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.source 2 | 3 | import org.jsoup.nodes.Document 4 | 5 | interface Source { 6 | fun get(): Document 7 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/source/StringSource.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.source 2 | 3 | import org.jsoup.Jsoup 4 | import org.jsoup.nodes.Document 5 | 6 | class StringSource(private val html: String) : Source { 7 | override fun get(): Document { 8 | return Jsoup.parse(html) 9 | } 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/AnchorLinkViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class AnchorLinkViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val anchorTextView = view.findViewById(R.id.anchorLink) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/AudioViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.VideoView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class AudioViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val videoView = view.findViewById(R.id.audioView) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/BlockQuoteViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class BlockQuoteViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val blockQuoteTextView: TextView = view.findViewById(R.id.blockquote) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/DescriptionItemViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class DescriptionItemViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val title: TextView = view.findViewById(R.id.title) 10 | val description: TextView = view.findViewById(R.id.description) 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/DescriptionListViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import m7mdra.com.htmlrecycler.R 6 | 7 | class DescriptionListViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 8 | val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView) 9 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/DivViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class DivViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val paragraphText = view.findViewById(R.id.paragraph) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/Heading1ViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class Heading1ViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val headingView: TextView = view.findViewById(R.id.heading) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/Heading2ViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class Heading2ViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val headingView: TextView = view.findViewById(R.id.heading) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/Heading3ViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class Heading3ViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val headingView: TextView = view.findViewById(R.id.heading) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/Heading4ViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class Heading4ViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val headingView: TextView = view.findViewById(R.id.heading) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/Heading5ViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class Heading5ViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val headingView: TextView = view.findViewById(R.id.heading) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/Heading6ViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class Heading6ViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val headingView: TextView = view.findViewById(R.id.heading) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/IFrameViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.webkit.WebView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class IFrameViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val iframeView = view.findViewById(R.id.iframe) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/ImageViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.ImageView 6 | import m7mdra.com.htmlrecycler.R 7 | import m7mdra.com.htmlrecycler.ResizableImageView 8 | 9 | class ImageViewHolder(val view: View) :RecyclerView.ViewHolder(view) { 10 | val image=view.findViewById(R.id.image) 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/ListItemViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class ListItemViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val listItem=view.findViewById(R.id.listItem) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/OrderedListViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import m7mdra.com.htmlrecycler.R 6 | 7 | class OrderedListViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 8 | val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView) 9 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/ParagraphViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class ParagraphViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val paragraphText = view.findViewById(R.id.paragraph_text) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/UnOrderedListViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import m7mdra.com.htmlrecycler.R 6 | 7 | class UnOrderedListViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 8 | val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView) 9 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/UnknownViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class UnknownViewHolder (val view: View) : RecyclerView.ViewHolder(view) { 9 | val unknownTextView = view.findViewById(R.id.unknown_text) 10 | 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/VideoViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.VideoView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class VideoViewHolder(val view: View) : RecyclerView.ViewHolder(view) { 9 | val videoView = view.findViewById(R.id.videoView) 10 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/paragraph/AnchorLinkViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder.paragraph 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class AnchorLinkViewHolder(private val view: View) : RecyclerView.ViewHolder(view){ 9 | val paragraphText = view.findViewById(R.id.paragraph) 10 | 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/paragraph/BodyViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder.paragraph 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class BodyViewHolder(private val view: View) : RecyclerView.ViewHolder(view){ 9 | val paragraphText = view.findViewById(R.id.paragraph) 10 | 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/paragraph/BoldViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder.paragraph 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class BoldViewHolder(private val view: View) : RecyclerView.ViewHolder(view){ 9 | val paragraphText = view.findViewById(R.id.paragraph) 10 | 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/paragraph/EmphasizesViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder.paragraph 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class EmphasizesViewHolder(private val view: View) : RecyclerView.ViewHolder(view){ 9 | val paragraphText = view.findViewById(R.id.paragraph) 10 | 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/java/m7mdra/com/htmlrecycler/viewholder/paragraph/UnderLineViewHolder.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler.viewholder.paragraph 2 | 3 | import android.support.v7.widget.RecyclerView 4 | import android.view.View 5 | import android.widget.TextView 6 | import m7mdra.com.htmlrecycler.R 7 | 8 | class UnderLineViewHolder(private val view: View) : RecyclerView.ViewHolder(view){ 9 | val paragraphText = view.findViewById(R.id.paragraph) 10 | 11 | } -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_anchor_link.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_audio.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 11 | 12 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_blockquote.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 18 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_description_title_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_heading1.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 16 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_heading2.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_heading3.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_heading4.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_heading5.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_heading6.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_iframe.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_paragarph.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_paragraph_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_unknown.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/layout/row_video.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 11 | 12 | -------------------------------------------------------------------------------- /htmlrecycler/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | HtmlRecycler 3 | 4 | -------------------------------------------------------------------------------- /htmlrecycler/src/test/java/m7mdra/com/htmlrecycler/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package m7mdra.com.htmlrecycler 2 | 3 | import junit.framework.Assert.* 4 | import m7mdra.com.htmlrecycler.elements.* 5 | import m7mdra.com.htmlrecycler.extractor.* 6 | import m7mdra.com.htmlrecycler.model.AnchorLink 7 | import m7mdra.com.htmlrecycler.model.DescriptionList 8 | import org.jsoup.Jsoup 9 | import org.jsoup.nodes.Element 10 | import org.jsoup.nodes.TextNode 11 | import org.jsoup.select.Elements 12 | 13 | import org.junit.Test 14 | 15 | /** 16 | * Example local unit test, which will execute on the development machine (host). 17 | * 18 | * @see [Testing documentation](http://d.android.com/tools/testing) 19 | */ 20 | class ExampleUnitTest { 21 | 22 | @Test 23 | fun testIdentifier() { 24 | val parse = Jsoup.parse(Data.data) 25 | assertNotNull(parse) 26 | val elements = parse.body().children() 27 | val elementList = mutableListOf() 28 | extractData(elementList, elements) 29 | 30 | } 31 | 32 | private fun extractData(elementList: MutableList, elements: Elements) { 33 | elements.forEach { 34 | when (ElementIdentifier(it).identify()) { 35 | ElementType.Image -> { 36 | val imageUrl = ImageExtractor(it).extract() 37 | elementList.add(ImageElement(imageUrl)) 38 | } 39 | ElementType.Heading1 -> { 40 | val heading = HeadingExtractor(it).extract() 41 | elementList.add(Heading1Element(heading)) 42 | 43 | } 44 | ElementType.Heading2 -> { 45 | val heading = HeadingExtractor(it).extract() 46 | elementList.add(Heading2Element(heading)) 47 | 48 | } 49 | ElementType.Heading3 -> { 50 | val heading = HeadingExtractor(it).extract() 51 | elementList.add(Heading3Element(heading)) 52 | 53 | } 54 | ElementType.Heading4 -> { 55 | val heading = HeadingExtractor(it).extract() 56 | elementList.add(Heading4Element(heading)) 57 | 58 | } 59 | ElementType.Heading5 -> { 60 | val heading = HeadingExtractor(it).extract() 61 | elementList.add(Heading5Element(heading)) 62 | 63 | } 64 | ElementType.Heading6 -> { 65 | val heading = HeadingExtractor(it).extract() 66 | elementList.add(Heading6Element(heading)) 67 | 68 | } 69 | ElementType.UnorderedList -> { 70 | val listExtractor = ListExtractor(it).extract() 71 | elementList.add(UnOrderListElement(listExtractor)) 72 | } 73 | ElementType.OrderedList -> { 74 | val listExtractor = ListExtractor(it).extract() 75 | elementList.add(OrderListElement(listExtractor)) 76 | } 77 | ElementType.Video -> { 78 | val videoUrl = VideoExtractor(it).extract() 79 | elementList.add(VideoElement(videoUrl)) 80 | } 81 | ElementType.AnchorLink -> { 82 | val anchorLink = AnchorLinkExtractor(it).extract() 83 | elementList.add(AnchorLinkElement(AnchorLink(anchorLink.first, anchorLink.second))) 84 | } 85 | ElementType.DescriptionList -> { 86 | val extract = DescriptionListExtractor(it).extract() 87 | val descriptionList = mutableListOf() 88 | extract.forEach { 89 | descriptionList.add(DescriptionList(it.first, it.second)) 90 | } 91 | val descriptionListElement = DescriptionListElement(descriptionList) 92 | elementList.add(descriptionListElement) 93 | } 94 | ElementType.Div -> extractData(elementList, it.children()) 95 | ElementType.Paragraph -> { 96 | val children = it.children() 97 | if (children.size > 0 && 98 | it.getElementsByTag("img").isNotEmpty() || 99 | it.getElementsByTag("audio").isNotEmpty() || 100 | it.getElementsByTag("video").isNotEmpty()) 101 | extractData(elementList, children) 102 | else { 103 | val list = mutableListOf() 104 | val dataNodes = it.childNodes() 105 | dataNodes.forEach { node -> 106 | if (node is TextNode) 107 | list.add(Body(node.text())) 108 | else if (node is Element) 109 | when { 110 | node.tagName() == "a" -> 111 | list.add(AnchorLinkInParagraph(node.text(), node.absUrl("href"))) 112 | node.tagName() == "b" || node.tagName() == "strong" -> 113 | list.add(Bold(node.text())) 114 | node.tagName() == "em" || node.tagName() == "i" -> 115 | list.add(Emphasizes(node.text())) 116 | node.tagName() == "u" || node.tagName() == "span" && 117 | node.attributes()["style"].contains("underline") -> 118 | list.add(UnderLine(node.text())) 119 | else -> list.add(Unknown()) 120 | } 121 | } 122 | assertEquals(dataNodes.size, list.size) 123 | 124 | } 125 | } 126 | ElementType.BlockQuote -> { 127 | elementList.add(BlockQuoteElement(it.text())) 128 | } 129 | 130 | ElementType.IFrame -> { 131 | 132 | } 133 | ElementType.Audio -> { 134 | val audio = AudioExtractor(it).extract() 135 | elementList.add(AudioElement(audio)) 136 | } 137 | ElementType.Unknown -> { 138 | elementList.add(UnknownElement(it.toString())) 139 | } 140 | 141 | else -> { 142 | elementList.add(UnknownElement(it.toString())) 143 | } 144 | } 145 | } 146 | } 147 | 148 | object Data { 149 | val data = "

Hyundai Atos

\n" + 150 | "

\"\"

\n" + 151 | "

The Hyundai Atos was a city car produced by the South Korean manufacturer Hyundai since 1997. It was also marketed under the Atoz, Amica and Santro Xing model names. It was facelifted in 1999, from when it marketed as the Atos Prime, and in 2003." + 152 | "anchored text It has been available only with a five-door hatchback body style. It was replaced in most markets by the Hyundai i10 in 2007, but production continued in India till late 2014

\n" + 153 | "

\"\"

\n" + 154 | "

Overview

\n" + 155 | "

The first Atos was introduced in 1997. It is fitted with a 999cc engine and has a top speed of 88 mph (142 km/h). It was succeeded by a face-lift version by 2000 and in 2003 another one. It was discontinued in Europe in 2007, in favour of the Indian assembled i10 and in other markets in 2011.

\n" + 156 | "

Other names

\n" + 157 | "

The Atos Prime is marketed as the:

\n" + 158 | "
    \n" + 159 | "
  • Hyundai Amica in the United Kingdom
  • \n" + 160 | "
  • Hyundai Santro Xing in India
  • \n" + 161 | "
  • Atos by Dodge in Mexico
  • \n" + 162 | "
  • Kia Visto in Indonesia and South Korea (Hyundai also sold the original Atoz in Indonesia).
  • \n" + 163 | "
  • Inokom Atos in Malaysia
  • \n" + 164 | "
\n" + 165 | "

Hyundai entered the Indian market in 1997 with the Atos, marketed under the name Santro and various variants as Zip Drive, Zip Plus etc. Produced at Hyundai's factory in Chennai, its primary competitor at that time was the popular Maruti Suzuki Zen. The distinctive styling of the first generation had mixed reviews, but the car was a success primarily due to its power steering feature and price.

\n" + 166 | "

Variants in India

\n" + 167 | "

The Hyundai Santro was first released in India in 1998.It came with three variants:

\n" + 168 | "
    \n" + 169 | "
  • Santro base, with AC and black bumpers, priced at 2,99,000 INR ex-showroom
  • \n" + 170 | "
  • Santro DX 1, added with front power windows, central locking, high quality fabric upholstery an fabric inserts on door trims, body colored bumpers, rear wiper/washer/defogger, front fog lamps, waistline moulding and full wheel covers, priced at 3,49,000 INR.
  • \n" + 171 | "
  • Santro DX 2, added with power steering and first in class rear seat belts, priced at 3,69,000 INR. These were often criticised for their appearance.
  • \n" + 172 | "
  • In 2000, a new version called Santro Zip Drive was introduced. Changes included were things such as every variant got a power steering and a new grille.
  • \n" + 173 | "
  • In 2002, a refreshed version called Santro Zip Plus was introduced. Changes included Clear Lens headlamps and taillamps and a better engine and performance.
  • \n" + 174 | "
  • In 2003, the car underwent a complete facelift and was introduced as the Santro Xing. Pictures are given below alongside technical data.
  • \n" + 175 | "
\n" + 176 | "

Specifications

\n" + 177 | "

Figures as listed for the 2000-2003, 5 door, 1.0i model with GSi trim as sold in the UK (as the Amica), with standard options.

\n" + 178 | "

Dimensions

\n" + 179 | "
    \n" + 180 | "
  • Length: 3,495 mm (137.6 in)
  • \n" + 181 | "
  • Width: 1,495 mm (58.9 in)
  • \n" + 182 | "
  • Height: 1,580 mm (62.2 in)
  • \n" + 183 | "
  • Wheelbase: 2,380 mm (93.7 in)
  • \n" + 184 | "
  • Unladen weight: 847 kg (1,867 lb)
  • \n" + 185 | "
\n" + 186 | "

Technical data

\n" + 187 | "
    \n" + 188 | "
  • Fuel Delivery: Multi-Point Injection
  • \n" + 189 | "
  • Transmission: 5-speed manual
  • \n" + 190 | "
  • Engine size & layout: 996 cc, I4, 12 valves
  • \n" + 191 | "
  • Peak Power: 40 kW (54.4 PS; 53.6 bhp)
  • \n" + 192 | "
  • Peak Torque: 82 N⋅m (60 lb⋅ft)
  • \n" + 193 | "
  • 0-60 mph (96 km/h): 14.6 s
  • \n" + 194 | "
  • Top Speed: 160 km/h (99 mph)
  • \n" + 195 | "
  • Fuel economy: 6.4 L/100 km (44 mpg‑imp; 37 mpg‑US)
  • \n" + 196 | "
  • Emissions: 151 g CO2/km, other emissions below Euro III standard.
  • \n" + 197 | "
\n" + 198 | "

\n" + 200 | "

" 201 | } 202 | 203 | 204 | // class TableElement(val table: Table) : Element() 205 | 206 | 207 | // data class Table(val heads: MutableList = mutableListOf(), val rows: MutableList = mutableListOf()) 208 | 209 | 210 | /* 211 | * 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 |
ProductCostReally?
TinyMCEFreeYES!
PluploadFreeYES!
233 | * */ 234 | /* class TableExtractor(val e: org.jsoup.nodes.Element) : Extractor(e) { 235 | override fun extract(): Table { 236 | val table = Table() 237 | e.select("tr").forEach { tr -> 238 | val tableHead = tr.select("th thead") 239 | val tableData = tr.select("td") 240 | 241 | if (tableHead.size > 0) 242 | tableHead.forEach { 243 | table.heads.add(it.text()) 244 | } 245 | else 246 | tableData.map { it.text() }.apply { 247 | table.rows.add(Row(this)) 248 | } 249 | } 250 | return table 251 | } 252 | }*/ 253 | } 254 | 255 | sealed class Paragraph 256 | 257 | data class Body(val bodyText: String) : Paragraph() 258 | data class AnchorLinkInParagraph(val text: String, val url: String) : Paragraph() 259 | data class UnderLine(val text: String) : Paragraph() 260 | data class Bold(val text: String) : Paragraph() 261 | data class Emphasizes(val text: String) : Paragraph() 262 | class Unknown : Paragraph() 263 | -------------------------------------------------------------------------------- /media/demo1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/media/demo1.gif -------------------------------------------------------------------------------- /media/demo2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m7mdra/HtmlRecycler/0e89591091cc0f724334b194da2f9ad6cf89c018/media/demo2.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':htmlrecycler' 2 | --------------------------------------------------------------------------------