1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 13:57:10 +09:00

Added view holder for code snippet.

This commit is contained in:
Ubu 2019-03-24 11:30:52 +03:00
parent 7241c1d312
commit 8fd6467a15
6 changed files with 62 additions and 4 deletions

View file

@ -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": []
},
{

View file

@ -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

View file

@ -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<Block>): 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<Block>): 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<Block>): 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<Block>): 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<Block>): 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<Block>): RecyclerView.Adapte
const val HOLDER_HEADER_THREE = 3
const val HOLDER_QUOTE = 4
const val HOLDER_CHECKBOX = 5
const val HOLDER_CODE_SNIPPET = 6
}
}

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/dark_gray"/>
<corners android:radius="4dp"/>
</shape>

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="12sp"
android:typeface="monospace"
android:textColor="#FFFF"
android:padding="8dp"
android:background="@drawable/rounded_rectangle_gray"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/codeSnippetContent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#7a1ced</color>
<color name="dark_gray">#222936</color>
<color name="colorAccent">#FF4081</color>
</resources>