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

Fix/code block in multi select mode (#927)

This commit is contained in:
Evgenii Kozlov 2020-09-28 16:51:09 +03:00 committed by GitHub
parent c37f41ac00
commit 79a14ad5b8
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 121 additions and 54 deletions

View file

@ -2,6 +2,10 @@
## Version 0.0.50 (WIP)
### New features 🚀
* Code block in multi-select and scroll-and-move modes (#892)
### Design & UX 🔳
* Changed object names in add-block and turn-into panels (#752)

View file

@ -2,6 +2,9 @@ package com.anytypeio.anytype.core_ui.features.editor.holders.other
import android.text.Editable
import android.view.View
import android.widget.FrameLayout
import androidx.core.view.updateLayoutParams
import com.anytypeio.anytype.core_ui.R
import com.anytypeio.anytype.core_ui.features.editor.holders.`interface`.TextHolder
import com.anytypeio.anytype.core_ui.features.page.BlockView
import com.anytypeio.anytype.core_ui.features.page.BlockViewDiffUtil
@ -10,6 +13,7 @@ import com.anytypeio.anytype.core_ui.features.page.ListenerType
import com.anytypeio.anytype.core_ui.tools.DefaultTextWatcher
import com.anytypeio.anytype.core_ui.widgets.text.EditorLongClickListener
import com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
import com.anytypeio.anytype.core_utils.ext.dimen
import kotlinx.android.synthetic.main.item_block_code_snippet.view.*
import timber.log.Timber
@ -25,8 +29,10 @@ class Code(view: View) : BlockViewHolder(view), TextHolder {
onTextChanged: (String, Editable) -> Unit,
onSelectionChanged: (String, IntRange) -> Unit,
onFocusChanged: (String, Boolean) -> Unit,
clicked: (ListenerType) -> Unit
clicked: (ListenerType) -> Unit,
onTextInputClicked: (String) -> Unit
) {
indentize(item)
if (item.mode == BlockView.Mode.READ) {
content.setText(item.text)
enableReadMode()
@ -61,6 +67,17 @@ class Code(view: View) : BlockViewHolder(view), TextHolder {
}
content.selectionWatcher = { onSelectionChanged(item.id, it) }
}
content.setOnClickListener { onTextInputClicked(item.id) }
}
fun indentize(item: BlockView.Indentable) {
itemView.snippetContainer.updateLayoutParams<FrameLayout.LayoutParams> {
apply {
val extra = item.indent * dimen(R.dimen.indent)
leftMargin = 0 + extra
}
}
}
fun processChangePayload(
@ -98,6 +115,10 @@ class Code(view: View) : BlockViewHolder(view), TextHolder {
if (payload.focusChanged()) {
setFocus(item)
}
if (payload.isIndentChanged) {
indentize(item)
}
}
override fun select(item: BlockView.Selectable) {

View file

@ -778,6 +778,7 @@ class BlockAdapter(
onSelectionChanged = onSelectionChanged,
onFocusChanged = onFocusChanged,
clicked = onClickListener,
onTextInputClicked = onTextInputClicked
)
}
is File -> {

View file

@ -436,8 +436,9 @@ sealed class BlockView : ViewType, Parcelable {
var text: String,
override val mode: Mode = Mode.EDIT,
override var isFocused: Boolean = false,
override val isSelected: Boolean = false
) : BlockView(), Permission, Selectable, Focusable {
override val isSelected: Boolean = false,
override val indent: Int = 0
) : BlockView(), Permission, Selectable, Focusable, Indentable {
override fun getViewType() = HOLDER_CODE_SNIPPET
}

View file

@ -1,5 +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_code_multi_select_unselected" />
</selector>

View file

@ -1,31 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="@drawable/item_block_code_multi_select_mode_selector"
android:paddingTop="6dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:paddingStart="20dp"
android:orientation="vertical"
android:layout_height="wrap_content">
android:paddingBottom="6dp"
android:paddingStart="12dp"
android:paddingEnd="12dp">
<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"/>
<com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
android:id="@+id/snippet"
<LinearLayout
android:id="@+id/snippetContainer"
android:background="@drawable/item_block_code_multi_select_unselected"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="23dp"
android:paddingBottom="30dp"
style="@style/BlockCodeContentStyle"
android:text="No content yet"
android:fontFamily="monospace"
tools:text="@string/default_text_placeholder" />
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:orientation="vertical">
</LinearLayout>
<TextView
android:id="@+id/code_menu"
style="@style/BlockCodeLanguageMenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_12"
android:text="@string/block_code_menu_title" />
<com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
android:id="@+id/snippet"
style="@style/BlockCodeContentStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:paddingTop="23dp"
android:paddingBottom="30dp"
android:text="No content yet"
tools:text="@string/default_text_placeholder" />
</LinearLayout>
</FrameLayout>

View file

@ -1,28 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#F3F2EC"
android:paddingStart="20dp"
android:orientation="vertical"
android:layout_height="wrap_content">
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="@drawable/item_block_code_multi_select_mode_selector"
android:paddingTop="6dp"
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:paddingBottom="6dp"
android:paddingStart="4dp"
android:paddingEnd="4dp">
<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"
<LinearLayout
android:background="@drawable/item_block_code_multi_select_unselected"
android:paddingEnd="20dp"
android:paddingStart="20dp"
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" />
android:layout_marginTop="1dp"
android:layout_marginBottom="1dp"
android:orientation="vertical">
</LinearLayout>
<TextView
android:id="@+id/code_menu"
style="@style/BlockCodeLanguageMenuStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_12"
android:text="@string/block_code_menu_title" />
<com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
android:id="@+id/snippet"
style="@style/BlockCodeContentStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:paddingTop="23dp"
android:paddingBottom="30dp"
android:text="No content yet"
tools:text="@string/default_text_placeholder" />
</LinearLayout>
</FrameLayout>

View file

@ -180,13 +180,14 @@ fun TextView.getCursorOffsetY(): Int? =
}
}
fun View.indentize(indent: Int, defIndent: Int, margin: Int) =
fun View.indentize(indent: Int, defIndent: Int, margin: Int) {
updateLayoutParams<RecyclerView.LayoutParams> {
apply {
val extra = indent * defIndent
leftMargin = margin + extra
}
}
}
fun Fragment.clipboard() : ClipboardManager {
return requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager

View file

@ -223,7 +223,7 @@ class DefaultBlockViewRenderer(
}
Content.Text.Style.CODE_SNIPPET -> {
counter.reset()
result.add(code(mode, block, content, focus))
result.add(code(mode, block, content, focus, indent))
if (block.children.isNotEmpty()) {
result.addAll(
render(
@ -469,12 +469,14 @@ class DefaultBlockViewRenderer(
mode: EditorMode,
block: Block,
content: Content.Text,
focus: Focus
focus: Focus,
indent: Int
): BlockView.Code = BlockView.Code(
mode = if (mode == EditorMode.EDITING) BlockView.Mode.EDIT else BlockView.Mode.READ,
id = block.id,
text = content.text,
isFocused = block.id == focus.id
isFocused = block.id == focus.id,
indent = indent
)
private fun highlight(

View file

@ -378,7 +378,7 @@ class EditorBackspaceNestedDeleteTest : EditorPresentationTestSetup() {
content = Block.Content.Text(
text = MockDataFactory.randomString(),
marks = emptyList(),
style = Block.Content.Text.Style.CODE_SNIPPET
style = Block.Content.Text.Style.BULLET
)
)
@ -478,9 +478,11 @@ class EditorBackspaceNestedDeleteTest : EditorPresentationTestSetup() {
isFocused = false,
text = parent.content<Block.Content.Text>().text
),
BlockView.Code(
BlockView.Text.Bulleted(
indent = 1,
id = child1.id,
isFocused = true,
cursor = child1.content<Block.Content.Text>().text.length,
text = child1.content<Block.Content.Text>().text
),
BlockView.Upload.Picture(