Skip to content

Commit

Permalink
Deploy maven central (#10)
Browse files Browse the repository at this point in the history
* Add deployment scripts

* Refactoring and cleanup

* Add RichTextManager
  • Loading branch information
cp-radhika-s authored Nov 9, 2023
1 parent 699e084 commit 19f804f
Show file tree
Hide file tree
Showing 26 changed files with 631 additions and 697 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish

on:
push:
tags:
- '*'

jobs:
publish:
name: Release build and publish
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: adopt
java-version: 17

- name: Publish to MavenCentral
run: ./gradlew rich-editor-compose:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
13 changes: 13 additions & 0 deletions License
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2023 Canopas Software LLP

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ The editor offers the following <b>options</b>:
@Composable
fun Sample() {
val state = rememberEditorState()
val context = LocalContext.current
val state = remember {
val input = /* YOUR INPUT */
RichEditorState.Builder()
.setInput(input)
.adapter(JsonEditorParser())
.build()
}
RichEditor(
state = state,
modifier = Modifier
Expand Down
7 changes: 1 addition & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,9 @@ dependencies {
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'

implementation "io.noties.markwon:core:4.6.2"
implementation "io.noties.markwon:image-coil:4.6.2"
implementation "io.noties.markwon:editor:4.6.2"

implementation("io.coil-kt:coil:2.4.0")

implementation 'jp.wasabeef:richeditor-android:2.0.0'
implementation project(path: ':editor')


implementation 'com.google.code.gson:gson:2.10.1'
}
110 changes: 110 additions & 0 deletions app/src/main/assets/sample-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"spans": [
{
"from": 0,
"to": 10,
"style": "h1"
},
{
"from": 0,
"to": 10,
"style": "bold"
},
{
"from": 19,
"to": 27,
"style": "bold"
},
{
"from": 44,
"to": 59,
"style": "bold"
},
{
"from": 44,
"to": 59,
"style": "italic"
},
{
"from": 44,
"to": 59,
"style": "underline"
},
{
"from": 61,
"to": 69,
"style": "h3"
},
{
"from": 62,
"to": 69,
"style": "bold"
},
{
"from": 103,
"to": 118,
"style": "bold"
},
{
"from": 119,
"to": 126,
"style": "italic"
},
{
"from": 130,
"to": 138,
"style": "underline"
},
{
"from": 160,
"to": 167,
"style": "h3"
},
{
"from": 161,
"to": 167,
"style": "bold"
},
{
"from": 169,
"to": 180,
"style": "bold"
},
{
"from": 224,
"to": 235,
"style": "bold"
},
{
"from": 224,
"to": 235,
"style": "italic"
},
{
"from": 224,
"to": 235,
"style": "underline"
},
{
"from": 237,
"to": 251,
"style": "h4"
},
{
"from": 238,
"to": 250,
"style": "bold"
},
{
"from": 238,
"to": 250,
"style": "italic"
},
{
"from": 238,
"to": 250,
"style": "underline"
}
],
"text": "Rich Editor\nAndroid WYSIWYG Rich editor for Jetpack compose.\n\nFeatures\nThe editor offers the following options\n\n- Bold\n- Italic\n- Underline\n- Different headers\n\nCredits\nRich Editor for compose is owned and maintained by the canopas team\n\nThanks You ☺️\n"
}
32 changes: 23 additions & 9 deletions app/src/main/java/com/example/texteditor/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.texteditor

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.DrawableRes
Expand All @@ -18,7 +19,7 @@ import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
Expand All @@ -33,14 +34,15 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.PopupProperties
import com.canopas.editor.ui.data.RichTextState
import com.canopas.editor.ui.data.RichEditorState
import com.canopas.editor.ui.ui.RichEditor
import com.canopas.editor.ui.ui.rememberEditorState
import com.canopas.editor.ui.utils.TextSpanStyle
import com.example.texteditor.parser.JsonEditorParser
import com.example.texteditor.ui.theme.TextEditorTheme

class MainActivity : ComponentActivity() {
Expand All @@ -62,7 +64,17 @@ class MainActivity : ComponentActivity() {
@Composable
fun Sample() {
TextEditorTheme {
val state = rememberEditorState()
val context = LocalContext.current

val state = remember {
val input =
context.assets.open("sample-data.json").bufferedReader().use { it.readText() }
RichEditorState.Builder()
.setInput(input)
.adapter(JsonEditorParser())
.build()
}

Column {

StyleContainer(state)
Expand All @@ -82,7 +94,7 @@ fun Sample() {

@Composable
fun StyleContainer(
state: RichTextState,
state: RichEditorState,
) {
Row(
Modifier
Expand Down Expand Up @@ -116,21 +128,23 @@ fun StyleContainer(
.padding(2.dp)
.size(48.dp),
onClick = {
state.reset()
Log.d("XXX", "json ${state.output()}")
// state.reset()
},
) {
Icon(
Icons.Default.Refresh, contentDescription = null,
Icons.Default.Check, contentDescription = null,
modifier = Modifier.size(24.dp)
)
}

}
}


@Composable
fun TitleStyleButton(
value: RichTextState
value: RichEditorState
) {
var expanded by remember { mutableStateOf(false) }

Expand Down Expand Up @@ -206,7 +220,7 @@ fun DropDownItem(
fun StyleButton(
@DrawableRes icon: Int,
style: TextSpanStyle,
value: RichTextState,
value: RichEditorState,
) {
IconButton(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.texteditor.parser

import com.canopas.editor.ui.model.RichText
import com.canopas.editor.ui.model.RichTextSpan
import com.canopas.editor.ui.parser.EditorAdapter
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken

class JsonEditorParser : EditorAdapter {

private val gson: Gson = GsonBuilder()
.registerTypeAdapter(RichTextSpan::class.java, RichTextSpanAdapter())
.create()

override fun encode(input: String): RichText {
return gson.fromJson(input, object : TypeToken<RichText>() {}.type)
}

override fun decode(editorValue: RichText): String {
return gson.toJson(editorValue)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.canopas.editor.ui.parser.json
package com.example.texteditor.parser

import com.canopas.editor.ui.data.RichTextSpan
import com.canopas.editor.ui.data.RichTextState
import com.canopas.editor.ui.model.RichTextSpan
import com.canopas.editor.ui.utils.TextSpanStyle
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
Expand All @@ -10,36 +9,8 @@ import com.google.gson.JsonObject
import com.google.gson.JsonParseException
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type

class RichTextStateAdapter : JsonSerializer<RichTextState>, JsonDeserializer<RichTextState> {
override fun serialize(
src: RichTextState?,
typeOfSrc: Type?,
context: JsonSerializationContext?
): JsonElement {
val jsonObject = JsonObject()
jsonObject.addProperty("text", src?.editable.toString())
jsonObject.add("spans", context?.serialize(src?.spans))
return jsonObject
}

override fun deserialize(
json: JsonElement?,
typeOfT: Type?,
context: JsonDeserializationContext?
): RichTextState {
val jsonObject = json?.asJsonObject ?: throw JsonParseException("Invalid JSON")
val text = jsonObject.get("text").asString
val parts = context?.deserialize<MutableList<RichTextSpan>>(
jsonObject.get("spans"),
object : TypeToken<MutableList<RichTextSpan>>() {}.type
)
return RichTextState(text, parts ?: mutableListOf())
}
}

class RichTextSpanAdapter : JsonSerializer<RichTextSpan>, JsonDeserializer<RichTextSpan> {
override fun serialize(
src: RichTextSpan?,
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
id 'io.github.gradle-nexus.publish-plugin' version "1.3.0"
}
apply from: "${rootDir}/scripts/publish-root.gradle"
Loading

0 comments on commit 19f804f

Please sign in to comment.