mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
* #409: add code block * #409: update block code * #409: block code action bar * #409: Read mode for code block * #409: fix package * #409: update bg when selected * #409: fix font * #409: design fix * start tests * #409: tests off
This commit is contained in:
parent
f67533adb9
commit
ff2a5185fd
18 changed files with 171 additions and 21 deletions
|
@ -9,7 +9,6 @@ import com.agileburo.anytype.R
|
|||
import com.agileburo.anytype.core_ui.tools.SupportDragAndDropBehavior
|
||||
import com.agileburo.anytype.core_utils.ext.res
|
||||
import com.agileburo.anytype.core_utils.ext.shift
|
||||
import com.agileburo.anytype.feature_desktop.utils.DesktopDiffUtil
|
||||
import com.agileburo.anytype.presentation.desktop.DashboardView
|
||||
import kotlinx.android.synthetic.main.item_desktop_page.view.*
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.agileburo.anytype.feature_desktop.utils
|
||||
package com.agileburo.anytype.ui.desktop
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import com.agileburo.anytype.presentation.desktop.DashboardView
|
||||
|
|
|
@ -408,6 +408,7 @@ open class PageFragment :
|
|||
UiBlock.BULLETED -> vm.onAddTextBlockClicked(Text.Style.BULLET)
|
||||
UiBlock.NUMBERED -> vm.onAddTextBlockClicked(Text.Style.NUMBERED)
|
||||
UiBlock.TOGGLE -> vm.onAddTextBlockClicked(Text.Style.TOGGLE)
|
||||
UiBlock.CODE -> vm.onAddTextBlockClicked(Text.Style.CODE_SNIPPET)
|
||||
UiBlock.PAGE -> vm.onAddNewPageClicked()
|
||||
UiBlock.FILE -> vm.onAddFileBlockClicked()
|
||||
UiBlock.IMAGE -> vm.onAddImageBlockClicked()
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.agileburo.anytype.ui.page.modals.actions
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.agileburo.anytype.R
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
|
||||
|
@ -15,10 +17,13 @@ class CodeBlockActionToolbar : BlockActionToolbar() {
|
|||
block = arguments?.getParcelable(ARG_BLOCK)!!
|
||||
}
|
||||
|
||||
override fun blockLayout() = R.layout.item_block_code_snippet
|
||||
override fun blockLayout() = R.layout.item_block_code_snippet_preview
|
||||
override fun getBlock(): BlockView = block
|
||||
|
||||
override fun initUi(view: View, colorView: ImageView?, backgroundView: ImageView?) {
|
||||
TODO()
|
||||
view.findViewById<TextView>(R.id.snippet).apply {
|
||||
movementMethod = ScrollingMovementMethod()
|
||||
text = block.text
|
||||
}
|
||||
}
|
||||
}
|
|
@ -465,6 +465,12 @@ class BlockAdapter(
|
|||
item = blocks[position]
|
||||
)
|
||||
}
|
||||
is BlockViewHolder.Code -> {
|
||||
holder.processChangePayload(
|
||||
payloads = payloads.typeOf(),
|
||||
item = blocks[position]
|
||||
)
|
||||
}
|
||||
else -> throw IllegalStateException("Unexpected view holder: $holder")
|
||||
}
|
||||
}
|
||||
|
@ -515,7 +521,11 @@ class BlockAdapter(
|
|||
}
|
||||
is BlockViewHolder.Code -> {
|
||||
holder.bind(
|
||||
item = blocks[position] as BlockView.Code
|
||||
item = blocks[position] as BlockView.Code,
|
||||
onTextChanged = onTextChanged,
|
||||
onSelectionChanged = onSelectionChanged,
|
||||
onFocusChanged = onFocusChanged,
|
||||
onLongClickListener = onLongClickListener
|
||||
)
|
||||
}
|
||||
is BlockViewHolder.Checkbox -> {
|
||||
|
|
|
@ -227,8 +227,11 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
@Parcelize
|
||||
data class Code(
|
||||
override val id: String,
|
||||
val snippet: String
|
||||
) : BlockView() {
|
||||
val text: String,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override var focused: Boolean = false,
|
||||
override val isSelected: Boolean = false
|
||||
) : BlockView(), Permission, Selectable, Focusable {
|
||||
override fun getViewType() = HOLDER_CODE_SNIPPET
|
||||
}
|
||||
|
||||
|
|
|
@ -506,12 +506,51 @@ sealed class BlockViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
|||
}
|
||||
}
|
||||
|
||||
class Code(view: View) : BlockViewHolder(view) {
|
||||
class Code(view: View) : BlockViewHolder(view), TextHolder {
|
||||
|
||||
private val code = itemView.snippet
|
||||
override val root: View
|
||||
get() = itemView
|
||||
override val content: TextInputWidget
|
||||
get() = itemView.snippet
|
||||
|
||||
fun bind(item: BlockView.Code) {
|
||||
code.text = item.snippet
|
||||
fun bind(item: BlockView.Code,
|
||||
onTextChanged: (String, Editable) -> Unit,
|
||||
onSelectionChanged: (String, IntRange) -> Unit,
|
||||
onFocusChanged: (String, Boolean) -> Unit,
|
||||
onLongClickListener: (String) -> Unit) {
|
||||
if (item.mode == BlockView.Mode.READ) {
|
||||
content.setText(item.text)
|
||||
enableReadOnlyMode()
|
||||
select(item)
|
||||
} else {
|
||||
enableEditMode()
|
||||
|
||||
select(item)
|
||||
|
||||
content.setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
click = onLongClickListener
|
||||
)
|
||||
)
|
||||
|
||||
content.clearTextWatchers()
|
||||
|
||||
content.setText(item.text)
|
||||
setFocus(item)
|
||||
|
||||
setupTextWatcher(onTextChanged, item)
|
||||
|
||||
content.setOnFocusChangeListener { _, focused ->
|
||||
item.focused = focused
|
||||
onFocusChanged(item.id, focused)
|
||||
}
|
||||
content.selectionDetector = { onSelectionChanged(item.id, it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun select(item: BlockView.Selectable) {
|
||||
root.isSelected = item.isSelected
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
core-ui/src/main/res/drawable/ic_turn_into_arrow.xml
Normal file
10
core-ui/src/main/res/drawable/ic_turn_into_arrow.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="8dp"
|
||||
android:height="9dp"
|
||||
android:viewportWidth="8"
|
||||
android:viewportHeight="9">
|
||||
<path
|
||||
android:pathData="M7.78033,2.71967C7.48744,2.42678 7.01256,2.42678 6.71967,2.71967L4.10607,5.33327C4.04749,5.39185 3.95251,5.39185 3.89393,5.33327L1.28033,2.71967C0.98744,2.42678 0.51256,2.42678 0.21967,2.71967C-0.07322,3.01256 -0.07322,3.48744 0.21967,3.78033L3.89393,7.45459C3.95251,7.51317 4.04749,7.51317 4.10607,7.45459L7.78033,3.78033C8.07322,3.48744 8.07322,3.01256 7.78033,2.71967Z"
|
||||
android:fillColor="#ACA996"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/item_block_multi_select_selected" android:state_selected="true" />
|
||||
<item android:drawable="@drawable/item_block_code_multi_select_unselected" />
|
||||
</selector>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="10dp" />
|
||||
<solid android:color="#F3F2EC" />
|
||||
</shape>
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/item_block_multi_select_selected" android:state_selected="true" />
|
||||
<item android:drawable="@drawable/item_block_multi_select_selected" android:state_selected="true" />
|
||||
</selector>
|
|
@ -1,16 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:paddingStart="@dimen/default_document_item_padding_start"
|
||||
android:paddingEnd="@dimen/default_document_item_padding_end"
|
||||
android:background="@drawable/item_block_code_multi_select_mode_selector"
|
||||
android:layout_marginTop="1dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:paddingStart="20dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
tools:text="@string/default_text_placeholder"
|
||||
android:id="@+id/code_menu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_12"
|
||||
style="@style/BlockCodeLanguageMenuStyle"
|
||||
android:text="@string/block_code_menu_title"/>
|
||||
|
||||
<com.agileburo.anytype.core_ui.widgets.text.TextInputWidget
|
||||
android:id="@+id/snippet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="monospace" />
|
||||
android:paddingTop="23dp"
|
||||
android:paddingBottom="30dp"
|
||||
style="@style/BlockCodeContentStyle"
|
||||
android:text="No content yet"
|
||||
android:fontFamily="monospace"
|
||||
tools:text="@string/default_text_placeholder" />
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:background="#F3F2EC"
|
||||
android:paddingStart="20dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/code_menu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/dp_12"
|
||||
style="@style/BlockCodeLanguageMenuStyle"
|
||||
android:text="@string/block_code_menu_title"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/snippet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/BlockCodeContentStyle"
|
||||
android:paddingTop="23dp"
|
||||
android:paddingBottom="30dp"
|
||||
android:fontFamily="monospace"
|
||||
tools:text="@string/default_text_placeholder" />
|
||||
|
||||
</LinearLayout>
|
|
@ -193,5 +193,6 @@
|
|||
<string name="more">More</string>
|
||||
<string name="done">Done</string>
|
||||
<string name="select_or_drag_and_drop_blocks">Select or drag and drop blocks</string>
|
||||
<string name="block_code_menu_title">Language</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -141,6 +141,24 @@
|
|||
<item name="android:textSize">15sp</item>
|
||||
</style>
|
||||
|
||||
<style name="BlockCodeContentStyle">
|
||||
<item name="android:inputType">textMultiLine|textNoSuggestions</item>
|
||||
<item name="android:background">@null</item>
|
||||
<item name="android:fontFamily">@font/graphik_regular</item>
|
||||
<item name="android:lineSpacingExtra">7sp</item>
|
||||
<item name="android:textColor">#2C2B27</item>
|
||||
<item name="android:textSize">15sp</item>
|
||||
</style>
|
||||
|
||||
<style name="BlockCodeLanguageMenuStyle">
|
||||
<item name="android:fontFamily">@font/graphik_regular</item>
|
||||
<item name="android:lineSpacingExtra">7sp</item>
|
||||
<item name="android:drawablePadding">4dp</item>
|
||||
<item name="android:drawableEnd">@drawable/ic_turn_into_arrow</item>
|
||||
<item name="android:textColor">#ACA996</item>
|
||||
<item name="android:textSize">15sp</item>
|
||||
</style>
|
||||
|
||||
<style name="BlockDividerStyle">
|
||||
<item name="android:layout_marginTop">6dp</item>
|
||||
<item name="android:layout_marginBottom">6dp</item>
|
||||
|
|
|
@ -355,6 +355,7 @@ fun Block.Content.Text.Style.entity(): BlockEntity.Content.Text.Style = when (th
|
|||
Block.Content.Text.Style.Numbered -> BlockEntity.Content.Text.Style.NUMBERED
|
||||
Block.Content.Text.Style.Toggle -> BlockEntity.Content.Text.Style.TOGGLE
|
||||
Block.Content.Text.Style.Checkbox -> BlockEntity.Content.Text.Style.CHECKBOX
|
||||
Block.Content.Text.Style.Code -> BlockEntity.Content.Text.Style.CODE_SNIPPET
|
||||
else -> throw IllegalStateException("Unexpected text style: $this")
|
||||
}
|
||||
|
||||
|
@ -369,6 +370,7 @@ fun BlockEntity.Content.Text.Style.toMiddleware(): Block.Content.Text.Style = wh
|
|||
BlockEntity.Content.Text.Style.NUMBERED -> Block.Content.Text.Style.Numbered
|
||||
BlockEntity.Content.Text.Style.TOGGLE -> Block.Content.Text.Style.Toggle
|
||||
BlockEntity.Content.Text.Style.CHECKBOX -> Block.Content.Text.Style.Checkbox
|
||||
BlockEntity.Content.Text.Style.CODE_SNIPPET -> Block.Content.Text.Style.Code
|
||||
else -> throw IllegalStateException("Unexpected text style: $this")
|
||||
}
|
||||
|
||||
|
|
|
@ -1278,6 +1278,9 @@ class PageViewModel(
|
|||
is BlockView.Toggle -> block.copy(isSelected = true).also {
|
||||
select(block.id)
|
||||
}
|
||||
is BlockView.Code -> block.copy(isSelected = true).also {
|
||||
select(block.id)
|
||||
}
|
||||
else -> block
|
||||
}
|
||||
}
|
||||
|
@ -1519,6 +1522,7 @@ class PageViewModel(
|
|||
is BlockView.Bulleted -> block.copy(isSelected = isSelected(target))
|
||||
is BlockView.Numbered -> block.copy(isSelected = isSelected(target))
|
||||
is BlockView.Toggle -> block.copy(isSelected = isSelected(target))
|
||||
is BlockView.Code -> block.copy(isSelected = isSelected(target))
|
||||
else -> block
|
||||
}
|
||||
else
|
||||
|
|
|
@ -111,7 +111,7 @@ class DefaultBlockViewRenderer(
|
|||
}
|
||||
Content.Text.Style.CODE_SNIPPET -> {
|
||||
counter.reset()
|
||||
result.add(code(block, content))
|
||||
result.add(code(mode, block, content, focus))
|
||||
}
|
||||
Content.Text.Style.BULLET -> {
|
||||
counter.reset()
|
||||
|
@ -270,11 +270,15 @@ class DefaultBlockViewRenderer(
|
|||
)
|
||||
|
||||
private fun code(
|
||||
mode: EditorMode,
|
||||
block: Block,
|
||||
content: Content.Text
|
||||
content: Content.Text,
|
||||
focus: Id
|
||||
): BlockView.Code = BlockView.Code(
|
||||
mode = if (mode == EditorMode.EDITING) BlockView.Mode.EDIT else BlockView.Mode.READ,
|
||||
id = block.id,
|
||||
snippet = content.text
|
||||
text = content.text,
|
||||
focused = block.id == focus
|
||||
)
|
||||
|
||||
private fun highlight(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue