Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor editor structure #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/app-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ jobs:
java-version: 17.0.6
cache: 'gradle'
distribution: adopt
- name: Run Tests
run: ./gradlew test
- name: Build with Gradle
run: ./gradlew build
165 changes: 165 additions & 0 deletions app/src/main/assets/android-quill-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"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\n",
"attributes": {
"list": "bullet"
}
},
{
"insert": "Item 2\n",
"attributes": {
"list": "bullet"
}
},
{
"insert": "Item 3\n",
"attributes": {
"list": "bullet"
}
},
{
"insert": "Item 4\n",
"attributes": {
"list": "bullet"
}
},
{
"insert": "Item 5\n",
"attributes": {
"list": "bullet"
}
},
{
"insert": "Item 6\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": {}
}
]
}
110 changes: 0 additions & 110 deletions app/src/main/assets/sample-data.json

This file was deleted.

28 changes: 17 additions & 11 deletions app/src/main/java/com/example/texteditor/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ 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.RichEditorState
import com.canopas.editor.ui.data.QuillEditorState
import com.canopas.editor.ui.ui.RichEditor
import com.canopas.editor.ui.utils.TextSpanStyle
import com.example.texteditor.parser.JsonEditorParser
import com.example.texteditor.parser.QuillJsonEditorParser
import com.example.texteditor.ui.theme.TextEditorTheme

class MainActivity : ComponentActivity() {
Expand All @@ -66,21 +66,21 @@ fun Sample() {
TextEditorTheme {
val context = LocalContext.current

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

Column {

StyleContainer(state)
StyleContainer(quillState)

RichEditor(
state = state,
state = quillState,
modifier = Modifier
.fillMaxWidth()
.weight(1f)
Expand All @@ -94,7 +94,7 @@ fun Sample() {

@Composable
fun StyleContainer(
state: RichEditorState,
state: QuillEditorState,
) {
Row(
Modifier
Expand Down Expand Up @@ -123,6 +123,12 @@ fun StyleContainer(
value = state,
)

StyleButton(
icon = R.drawable.baseline_format_list_bulleted_24,
style = TextSpanStyle.BulletStyle,
value = state,
)

IconButton(
modifier = Modifier
.padding(2.dp)
Expand All @@ -144,7 +150,7 @@ fun StyleContainer(

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

Expand Down Expand Up @@ -220,7 +226,7 @@ fun DropDownItem(
fun StyleButton(
@DrawableRes icon: Int,
style: TextSpanStyle,
value: RichEditorState,
value: QuillEditorState,
) {
IconButton(
modifier = Modifier
Expand Down

This file was deleted.

Loading
Loading