-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
946 additions
and
688 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"spans": [{"insert":"RichEditor","attributes":{"bold":true,"header":1}},{"insert":"\nAndroid ","attributes":{}},{"insert":"WYSIWYG ","attributes":{"bold":true,"italic":true}},{"insert":"Rich editor for ","attributes":{}},{"insert":"Jetpack compose.\n\n","attributes":{"bold":true,"underline":true}},{"insert":"Features","attributes":{"bold":true,"header":3}},{"insert":"\nThe editor offers the following ","attributes":{}},{"insert":"options:\n","attributes":{"bold":true,"italic":true,"underline":true}},{"insert":"\n","attributes":{}},{"insert":"Bold\n","attributes":{"bold":true}},{"insert":"Italic\n","attributes":{"italic":true}},{"insert":"Underline\n","attributes":{"underline":true}},{"insert":"Different ","attributes":{}},{"insert":"Headings\n\n","attributes":{"bold":true,"italic":true,"underline":true}},{"insert":"Bullet List:\n","attributes":{"bold":true}},{"insert":"Item 1","attributes":{"list":"bullet"}},{"insert":"\n","attributes":{}},{"insert":"Item 2","attributes":{"list":"bullet"}},{"insert":"\n","attributes":{}},{"insert":"Item 3","attributes":{"list":"bullet"}},{"insert":"\n","attributes":{}},{"insert":"Item 4\n","attributes":{"list":"bullet"}},{"insert":"\n","attributes":{}},{"insert":"Credits","attributes":{"bold":true,"header":3}},{"insert":"\n\n","attributes":{}},{"insert":"RichEditor ","attributes":{"bold":true}},{"insert":"for compose is developed and maintained by the ","attributes":{}},{"insert":"canopas team.\n\n","attributes":{"bold":true,"italic":true,"underline":true}},{"insert":"Thank You! 😊\n\n","attributes":{}}] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
app/src/main/java/com/example/texteditor/parser/JsonEditorParser.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/example/texteditor/parser/QuillJsonEditorParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.QuillSpan | ||
import com.canopas.editor.ui.model.Span | ||
import com.canopas.editor.ui.parser.QuillEditorAdapter | ||
import com.google.gson.Gson | ||
import com.google.gson.GsonBuilder | ||
import com.google.gson.reflect.TypeToken | ||
|
||
class QuillJsonEditorParser : QuillEditorAdapter { | ||
|
||
private val gson: Gson = GsonBuilder() | ||
.registerTypeAdapter(Span::class.java, QuillRichTextStateAdapter()) | ||
.create() | ||
|
||
override fun encode(input: String): QuillSpan { | ||
return gson.fromJson(input, object : TypeToken<QuillSpan>() {}.type) | ||
} | ||
|
||
override fun decode(editorValue: QuillSpan): String { | ||
return gson.toJson(editorValue) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/example/texteditor/parser/QuillRichTextStateAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.example.texteditor.parser | ||
|
||
import android.util.Log | ||
import com.canopas.editor.ui.model.Attributes | ||
import com.canopas.editor.ui.model.Span | ||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonDeserializer | ||
import com.google.gson.JsonElement | ||
import com.google.gson.JsonObject | ||
import com.google.gson.JsonParseException | ||
import com.google.gson.JsonSerializationContext | ||
import com.google.gson.JsonSerializer | ||
import java.lang.reflect.Type | ||
|
||
class QuillRichTextStateAdapter : JsonSerializer<Span>, JsonDeserializer<Span> { | ||
override fun serialize( | ||
src: Span?, | ||
typeOfSrc: Type?, | ||
context: JsonSerializationContext? | ||
): JsonElement { | ||
val jsonObject = JsonObject() | ||
jsonObject.add("insert", context?.serialize(src?.insert)) | ||
jsonObject.add("attributes", context?.serialize(src?.attributes)) | ||
return jsonObject | ||
} | ||
|
||
override fun deserialize( | ||
json: JsonElement?, | ||
typeOfT: Type?, | ||
context: JsonDeserializationContext? | ||
): Span { | ||
try { | ||
val jsonObject = json?.asJsonObject ?: throw JsonParseException("Invalid JSON") | ||
val insert = jsonObject.get("insert") | ||
val attributes = jsonObject.get("attributes") | ||
return Span( | ||
insert = context?.deserialize<String>(insert, String::class.java), | ||
attributes = context?.deserialize<Attributes>(attributes, Attributes::class.java) | ||
) | ||
} catch (e: Exception) { | ||
Log.e("QuillRichTextStateAdapter", "deserialize: ", e) | ||
throw JsonParseException("Invalid JSON") | ||
} | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
app/src/main/java/com/example/texteditor/parser/RichTextStateAdapter.kt
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
app/src/main/res/drawable/baseline_format_list_bulleted_24.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:autoMirrored="true" android:height="24dp" | ||
android:tint="#000000" android:viewportHeight="24" | ||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M4,10.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM4,4.5c-0.83,0 -1.5,0.67 -1.5,1.5S3.17,7.5 4,7.5 5.5,6.83 5.5,6 4.83,4.5 4,4.5zM4,16.5c-0.83,0 -1.5,0.68 -1.5,1.5s0.68,1.5 1.5,1.5 1.5,-0.68 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM7,19h14v-2L7,17v2zM7,13h14v-2L7,11v2zM7,5v2h14L21,5L7,5z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.