Skip to content

Commit 173f8d9

Browse files
committed
Added support for compose
1 parent e87f3e0 commit 173f8d9

File tree

20 files changed

+667
-389
lines changed

20 files changed

+667
-389
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[![GitHub contributors](https://img.shields.io/github/contributors/mukeshsolanki/MarkdownView-Android.svg)](https://github.com/mukeshsolanki/MarkdownView-Android/graphs/contributors)
22

3-
* Bug reports and pull requests are welcome.
4-
* Make sure you use [square/java-code-styles](https://github.com/square/java-code-styles) to format your code.
3+
* Bug reports and pull requests are welcome.

README.md

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
1-
<h1 align="center">MarkdownView</h1>
1+
<h1 align="center">Compose Markdown View</h1>
22
<p align="center">
33
<a class="badge-align" href="https://www.codacy.com/app/mukeshsolanki/MarkdownView-Android?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=mukeshsolanki/MarkdownView-Android&amp;utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/58e51bc418d349499b3eac9c3f6f3ef1"/></a>
44
<a href="https://jitpack.io/#mukeshsolanki/MarkdownView-Android"><img src="https://jitpack.io/v/mukeshsolanki/MarkdownView-Android/month.svg"/></a>
55
<a href="https://jitpack.io/#mukeshsolanki/MarkdownView-Android/"> <img src="https://jitpack.io/v/mukeshsolanki/MarkdownView-Android.svg" /></a>
66
<a href="https://github.com/mukeshsolanki/MarkdownView-Android/actions"> <img src="https://github.com/mukeshsolanki/MarkdownView-Android/workflows/Build/badge.svg" /></a>
77
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg"/></a>
88
<br /><br />
9-
MarkdownView is a simple library that helps you display Markdown text or files on Android as a html page just like Github.
9+
MarkdownView is a composable library that helps you display Markdown text or files on Android as a html page just like Github.
1010
</p>
1111

12-
1312
![Demo](https://raw.githubusercontent.com/mukeshsolanki/MarkdownView-Android/master/Screenshots/demo.gif)
1413

15-
# Supporting MarkdownView
16-
17-
MarkdownView is an independent project with ongoing development and support made possible thanks to donations made by [these awesome backers](BACKERS.md#sponsors). If you'd like to join them, please consider:
18-
19-
- [Become a backer or sponsor on Patreon](https://www.patreon.com/mukeshsolanki).
20-
- [One-time donation via PayPal](https://www.paypal.me/mukeshsolanki)
14+
# Supporting Compose Markdown View
2115

22-
<a href="https://www.patreon.com/bePatron?c=935498" alt="Become a Patron"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" /></a>
16+
Compose Markdown View is an independent project with ongoing development and support made possible thanks to your donations.
17+
- [Become a backer](https://www.paypal.me/mukeshsolanki)
2318

2419
## Getting started
25-
Its really simple to integrate *MarkdownView* in android. All you need to do make the following change to you build gradle under the app module.
20+
Its really simple to integrate *Markdown* in android. All you need to do make the following change to you build gradle under the app module.
2621

2722
Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:
2823

29-
```java
24+
```kotlin
3025
allprojects {
3126
repositories {
3227
...
@@ -36,33 +31,74 @@ allprojects {
3631
```
3732

3833
Step 2. Add the dependency
39-
```java
34+
```kotlin
4035
dependencies {
41-
implementation 'com.github.mukeshsolanki:MarkdownView-Android:<latest-version>'
36+
implementation 'com.github.mukeshsolanki:MarkdownView-Android:2.0.0'
4237
}
4338
```
4439

45-
## How to use MarkdownView
40+
## How to use Markdown
41+
Its fairly simple and straight forward to use *Markdown* in you application.
42+
43+
- Using Compose
44+
45+
Just use `MarkDown` composable where you need to display the view like
46+
```kotlin
47+
MarkDown(
48+
url = URL("https://raw.githubusercontent.com/mukeshsolanki/MarkdownView-Android/main/README.md"),
49+
modifier = Modifier.fillMaxSize()
50+
)
51+
```
4652

47-
Its fairly simple and straight forward to use *MarkdownView* in you application. Just add the following in your layout where you want to display the markdown file/text.
53+
- Using Older View System (aka XML)
4854

55+
Add a compose view in your xml file like
4956
```XML
50-
<com.mukesh.MarkdownView
51-
android:id="@+id/markdown_view"
57+
<androidx.compose.ui.platform.ComposeView
58+
android:id="@+id/markdown"
5259
android:layout_width="match_parent"
53-
android:layout_height="match_parent"
54-
/>
60+
android:layout_height="match_parent" />
5561
```
5662

5763
and reference it in your activity/fragment and assign the markdown text/file like wise.
58-
```Java
59-
MarkdownView markdownView = (MarkdownView) findViewById(R.id.markdown_view);
60-
markdownView.setMarkDownText("# Hello World\nThis is a simple markdown"); //Displays markdown text
61-
...
62-
markdownView.loadMarkdownFromAssets("README.md"); //Loads the markdown file from the assets folder
63-
...
64-
File markdownFile=new File("filePath");
65-
markdownView.loadMarkdownFromFile(markdownFile); //Loads the markdown file.
64+
```kotlin
65+
val markdown = findViewById(R.id.markdown)
66+
markdown.composeView.apply {
67+
// Dispose of the Composition when the view's LifecycleOwner is destroyed
68+
setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed)
69+
setContent {
70+
// In Compose world
71+
MaterialTheme {
72+
MarkDown(
73+
url = URL("https://raw.githubusercontent.com/mukeshsolanki/MarkdownView-Android/main/README.md"),
74+
modifier = Modifier.fillMaxSize()
75+
)
76+
}
77+
}
78+
}
79+
```
80+
## Markdown Sources
81+
You have 3 different sources from where markdown data can be read
82+
- `Text` - You can pass the content and string to render the markdown
83+
```kotlin
84+
MarkDown(
85+
text = "# Test Markdown",
86+
modifier = Modifier.fillMaxSize()
87+
)
88+
```
89+
- `File` - You can read from a file and display the markdown data.
90+
```kotlin
91+
MarkDown(
92+
file = file,
93+
modifier = Modifier.fillMaxSize()
94+
)
95+
```
96+
- `URL` - You can also specify the url of the markdown file.
97+
```kotlin
98+
MarkDown(
99+
url = URL("https://raw.githubusercontent.com/mukeshsolanki/MarkdownView-Android/main/README.md"),
100+
modifier = Modifier.fillMaxSize()
101+
)
66102
```
67103

68104
## Author
@@ -72,7 +108,6 @@ Maintained by [Mukesh Solanki](https://www.github.com/mukeshsolanki)
72108
[![GitHub contributors](https://img.shields.io/github/contributors/mukeshsolanki/MarkdownView-Android.svg)](https://github.com/mukeshsolanki/MarkdownView-Android/graphs/contributors)
73109

74110
* Bug reports and pull requests are welcome.
75-
* Make sure you use [square/java-code-styles](https://github.com/square/java-code-styles) to format your code.
76111

77112
## License
78113
```

app/build.gradle

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,53 @@
1-
apply plugin: 'com.android.application'
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
25

36
android {
4-
compileSdkVersion 29
5-
defaultConfig {
6-
applicationId "com.mukesh.markdownview.example"
7-
minSdkVersion 14
8-
targetSdkVersion 29
9-
versionCode 1
10-
versionName "1.0"
11-
}
12-
buildTypes {
13-
release {
14-
minifyEnabled false
15-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
7+
compileSdk 32
8+
defaultConfig {
9+
applicationId "com.mukesh.markdownview.example"
10+
minSdk 21
11+
targetSdk 32
12+
versionCode 1
13+
versionName "1.0"
14+
vectorDrawables {
15+
useSupportLibrary true
16+
}
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
kotlinOptions {
30+
jvmTarget = '1.8'
31+
}
32+
buildFeatures {
33+
compose true
34+
}
35+
composeOptions {
36+
kotlinCompilerExtensionVersion compose_version
37+
}
38+
packagingOptions {
39+
resources {
40+
excludes += '/META-INF/{AL2.0,LGPL2.1}'
41+
}
1642
}
17-
}
1843
}
1944

2045
dependencies {
21-
implementation fileTree(include: ['*.jar'], dir: 'libs')
22-
implementation 'com.android.support:appcompat-v7:28.0.0'
23-
implementation project(':markdownview')
46+
implementation 'androidx.core:core-ktx:1.7.0'
47+
implementation "androidx.compose.ui:ui:$compose_version"
48+
implementation "androidx.compose.material:material:$compose_version"
49+
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
50+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
51+
implementation 'androidx.activity:activity-compose:1.4.0'
52+
implementation project(path: ':markdownview')
2453
}

app/src/main/AndroidManifest.xml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.mukesh.markdownview.example">
44

5-
<uses-permission android:name="android.permission.INTERNET"/>
6-
<application
7-
android:allowBackup="true"
8-
android:icon="@mipmap/ic_launcher"
9-
android:label="@string/app_name"
10-
android:supportsRtl="true"
11-
android:theme="@style/AppTheme">
12-
<activity android:name=".MainActivity">
13-
<intent-filter>
14-
<action android:name="android.intent.action.MAIN"/>
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<application
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.ComposeView">
12+
<activity
13+
android:name=".MainActivity"
14+
android:exported="true">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
1517

16-
<category android:name="android.intent.category.LAUNCHER"/>
17-
</intent-filter>
18-
</activity>
19-
</application>
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
2022

2123
</manifest>

app/src/main/assets/README.md

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)