From 8fd6467a15f66e0b0f22622b9dd4220a7caeb44c Mon Sep 17 00:00:00 2001 From: Ubu Date: Sun, 24 Mar 2019 11:30:52 +0300 Subject: [PATCH] Added view holder for code snippet. --- feature_editor/src/main/assets/test.json | 8 +++--- .../anytype/feature_editor/domain/Block.kt | 1 + .../feature_editor/ui/EditorAdapter.kt | 17 ++++++++++++ .../res/drawable/rounded_rectangle_gray.xml | 8 ++++++ .../res/layout/item_block_code_snippet.xml | 26 +++++++++++++++++++ feature_editor/src/main/res/values/colors.xml | 6 +++++ 6 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 feature_editor/src/main/res/drawable/rounded_rectangle_gray.xml create mode 100644 feature_editor/src/main/res/layout/item_block_code_snippet.xml create mode 100644 feature_editor/src/main/res/values/colors.xml diff --git a/feature_editor/src/main/assets/test.json b/feature_editor/src/main/assets/test.json index 316d688807..9d5521dcb6 100644 --- a/feature_editor/src/main/assets/test.json +++ b/feature_editor/src/main/assets/test.json @@ -43,8 +43,8 @@ "id": "22a8f9f5-b042-5532-bb5d-cbda07f579e0", "parentId": "93f8810e-590f-5962-a662-2c1fe17e5cbe", "type": 3, - "contentType": 1, - "content": "{\"text\":\"чайлд третьего\",\"marks\":[]}", + "contentType": 2, + "content": "{\"text\":\"data class User(val name : String)\",\"marks\":[]}", "children": [ { "id": "1983", @@ -70,8 +70,8 @@ "id": "21fe093a-5f74-583b-9c17-ee798e1bfc7e", "parentId": "", "type": 3, - "contentType": 1, - "content": "{\"text\":\"четвертый элемент\",\"marks\":[]}", + "contentType": 2, + "content": "{\"text\":\"data class User(val name : String)\",\"marks\":[]}", "children": [] }, { diff --git a/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/domain/Block.kt b/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/domain/Block.kt index 795f15ac56..dfff9a3197 100644 --- a/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/domain/Block.kt +++ b/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/domain/Block.kt @@ -60,6 +60,7 @@ fun Int.toContentType(): ContentType = fun ContentType.toNumericalCode() : Int { return when(this) { ContentType.P -> 1 + ContentType.Code -> 2 ContentType.H1 -> 3 ContentType.H2 -> 4 ContentType.Quote -> 8 diff --git a/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/ui/EditorAdapter.kt b/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/ui/EditorAdapter.kt index 2ec90c088c..ce2f51fc25 100644 --- a/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/ui/EditorAdapter.kt +++ b/feature_editor/src/main/java/com/agileburo/anytype/feature_editor/ui/EditorAdapter.kt @@ -9,6 +9,7 @@ import com.agileburo.anytype.feature_editor.R import com.agileburo.anytype.feature_editor.domain.Block import com.agileburo.anytype.feature_editor.domain.ContentType import kotlinx.android.synthetic.main.item_block_checkbox.view.* +import kotlinx.android.synthetic.main.item_block_code_snippet.view.* import kotlinx.android.synthetic.main.item_block_editable.view.* import kotlinx.android.synthetic.main.item_block_header_one.view.* import kotlinx.android.synthetic.main.item_block_header_three.view.* @@ -25,6 +26,7 @@ class EditorAdapter(private val blocks: MutableList): RecyclerView.Adapte } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + val inflater = LayoutInflater.from(parent.context) return when(viewType) { @@ -52,6 +54,10 @@ class EditorAdapter(private val blocks: MutableList): RecyclerView.Adapte val view = inflater.inflate(R.layout.item_block_checkbox, parent, false) ViewHolder.CheckBoxHolder(view) } + HOLDER_CODE_SNIPPET -> { + val view = inflater.inflate(R.layout.item_block_code_snippet, parent, false) + ViewHolder.CodeSnippetHolder(view) + } else -> TODO() } } @@ -64,6 +70,7 @@ class EditorAdapter(private val blocks: MutableList): RecyclerView.Adapte is ContentType.H3 -> HOLDER_HEADER_THREE is ContentType.Quote -> HOLDER_QUOTE is ContentType.Check -> HOLDER_CHECKBOX + is ContentType.Code -> HOLDER_CODE_SNIPPET else -> TODO() } } @@ -78,6 +85,7 @@ class EditorAdapter(private val blocks: MutableList): RecyclerView.Adapte is ViewHolder.HeaderThreeHolder -> holder.bind(blocks[position]) is ViewHolder.QuoteHolder -> holder.bind(blocks[position]) is ViewHolder.CheckBoxHolder -> holder.bind(blocks[position]) + is ViewHolder.CodeSnippetHolder -> holder.bind(blocks[position]) } } @@ -136,6 +144,14 @@ class EditorAdapter(private val blocks: MutableList): RecyclerView.Adapte } } + + class CodeSnippetHolder(itemView: View) : ViewHolder(itemView) { + + fun bind(block: Block) { + itemView.codeSnippetContent.text = block.content + } + + } } companion object { @@ -145,5 +161,6 @@ class EditorAdapter(private val blocks: MutableList): RecyclerView.Adapte const val HOLDER_HEADER_THREE = 3 const val HOLDER_QUOTE = 4 const val HOLDER_CHECKBOX = 5 + const val HOLDER_CODE_SNIPPET = 6 } } \ No newline at end of file diff --git a/feature_editor/src/main/res/drawable/rounded_rectangle_gray.xml b/feature_editor/src/main/res/drawable/rounded_rectangle_gray.xml new file mode 100644 index 0000000000..966dff83ef --- /dev/null +++ b/feature_editor/src/main/res/drawable/rounded_rectangle_gray.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/feature_editor/src/main/res/layout/item_block_code_snippet.xml b/feature_editor/src/main/res/layout/item_block_code_snippet.xml new file mode 100644 index 0000000000..a126640b10 --- /dev/null +++ b/feature_editor/src/main/res/layout/item_block_code_snippet.xml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file diff --git a/feature_editor/src/main/res/values/colors.xml b/feature_editor/src/main/res/values/colors.xml new file mode 100644 index 0000000000..4b9f43d062 --- /dev/null +++ b/feature_editor/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #7a1ced + #222936 + #FF4081 + \ No newline at end of file