mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-11 10:18:05 +09:00
#483: fixes
This commit is contained in:
parent
54b0c75f1c
commit
78570ec56d
9 changed files with 64 additions and 27 deletions
|
@ -53,10 +53,12 @@ fun Editable.extractMarks(): List<Mark> = getSpans(0, length, Span::class.java).
|
|||
|
||||
fun <T> isSpanInRange(textRange: IntRange, text: Spanned, type: Class<T>): Boolean {
|
||||
text.getSpans(textRange.first, textRange.last, type).forEach {
|
||||
val start = text.getSpanStart(it)
|
||||
val end = text.getSpanEnd(it)
|
||||
val spanRange = IntRange(start, end)
|
||||
val overlap = textRange.overlap(spanRange)
|
||||
val overlap = textRange.overlap(
|
||||
IntRange(
|
||||
start = text.getSpanStart(it),
|
||||
endInclusive = text.getSpanEnd(it)
|
||||
)
|
||||
)
|
||||
if (overlap in listOf(
|
||||
Overlap.INNER,
|
||||
Overlap.INNER_LEFT,
|
||||
|
|
|
@ -2,24 +2,27 @@ package com.agileburo.anytype.ui.menu
|
|||
|
||||
import android.animation.ValueAnimator
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.PointF
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.text.Editable
|
||||
import android.view.*
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.HorizontalScrollView
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.TextView
|
||||
import android.widget.*
|
||||
import com.agileburo.anytype.core_ui.R
|
||||
import com.agileburo.anytype.core_ui.common.Markup
|
||||
import com.agileburo.anytype.core_ui.common.Span
|
||||
import com.agileburo.anytype.core_ui.extensions.color
|
||||
import com.agileburo.anytype.core_utils.ext.PopupExtensions.calculateFloatToolbarPosition
|
||||
import com.agileburo.anytype.core_utils.ext.PopupExtensions.lerp
|
||||
import com.agileburo.anytype.core_utils.ext.invisible
|
||||
import com.agileburo.anytype.core_utils.ext.visible
|
||||
import com.agileburo.anytype.ext.isSpanInRange
|
||||
import java.lang.ref.WeakReference
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class AnytypeContextMenu constructor(
|
||||
private val type: AnytypeContextMenuType,
|
||||
private val contextRef: WeakReference<Context>,
|
||||
private val anchorViewRef: WeakReference<TextView>,
|
||||
private val onMarkupActionClicked: (Markup.Type) -> Unit,
|
||||
|
@ -93,7 +96,7 @@ class AnytypeContextMenu constructor(
|
|||
})
|
||||
isClippingEnabled = false
|
||||
isFocusable = false
|
||||
addOnMenuItemClicks(contentView)
|
||||
initMenuItems(contentView)
|
||||
}
|
||||
|
||||
private fun updatePosition() {
|
||||
|
@ -115,7 +118,18 @@ class AnytypeContextMenu constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun addOnMenuItemClicks(view: View) {
|
||||
private fun initButtons(type: AnytypeContextMenuType) =
|
||||
when (type) {
|
||||
AnytypeContextMenuType.P -> {
|
||||
}
|
||||
AnytypeContextMenuType.HEADER -> {
|
||||
|
||||
}
|
||||
AnytypeContextMenuType.HIGHTLIGHTED -> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun initMenuItems(view: View) {
|
||||
view.findViewById<View>(R.id.menu_copy).setOnClickListener {
|
||||
anchorViewRef.get()?.onTextContextMenuItem(android.R.id.copy)
|
||||
}
|
||||
|
@ -125,8 +139,23 @@ class AnytypeContextMenu constructor(
|
|||
view.findViewById<View>(R.id.menu_paste).setOnClickListener {
|
||||
anchorViewRef.get()?.onTextContextMenuItem(android.R.id.paste)
|
||||
}
|
||||
view.findViewById<View>(R.id.menu_bold).setOnClickListener {
|
||||
onMarkupActionClicked.invoke(Markup.Type.BOLD)
|
||||
view.findViewById<ImageView>(R.id.menu_bold).apply {
|
||||
|
||||
anchorViewRef.get()?.let {
|
||||
if (isSpanInRange(
|
||||
textRange = IntRange(it.selectionStart, it.selectionEnd),
|
||||
text = it.text as Editable,
|
||||
type = Span.Bold::class.java
|
||||
)
|
||||
) {
|
||||
this.imageTintList =
|
||||
ColorStateList.valueOf(view.context.color(R.color.context_menu_selected_item))
|
||||
}
|
||||
}
|
||||
|
||||
setOnClickListener {
|
||||
onMarkupActionClicked.invoke(Markup.Type.BOLD)
|
||||
}
|
||||
}
|
||||
view.findViewById<View>(R.id.menu_italic).setOnClickListener {
|
||||
onMarkupActionClicked.invoke(Markup.Type.ITALIC)
|
||||
|
@ -153,12 +182,12 @@ class AnytypeContextMenu constructor(
|
|||
scrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT)
|
||||
}
|
||||
scrollView.setOnScrollChangeListener { _, scrollX, _, oldScrollX, _ ->
|
||||
if (scrollX != oldScrollX) {
|
||||
arrowRight.invisible()
|
||||
} else {
|
||||
arrowRight.visible()
|
||||
}
|
||||
if (scrollX != oldScrollX) {
|
||||
arrowRight.invisible()
|
||||
} else {
|
||||
arrowRight.visible()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDismiss() {
|
||||
|
@ -216,4 +245,6 @@ class AnytypeContextMenu constructor(
|
|||
popupWindowRef.get()?.dismiss()
|
||||
cleanup()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class AnytypeContextMenuType { P, HEADER, HIGHTLIGHTED }
|
|
@ -52,6 +52,7 @@ import com.agileburo.anytype.presentation.page.editor.Command
|
|||
import com.agileburo.anytype.presentation.page.editor.ViewState
|
||||
import com.agileburo.anytype.presentation.settings.EditorSettings
|
||||
import com.agileburo.anytype.ui.base.NavigationFragment
|
||||
import com.agileburo.anytype.ui.menu.AnytypeContextMenuType
|
||||
import com.agileburo.anytype.ui.page.modals.*
|
||||
import com.agileburo.anytype.ui.page.modals.actions.BlockActionToolbarFactory
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
|
@ -724,6 +725,7 @@ open class PageFragment :
|
|||
if (anytypeContextMenu == null) {
|
||||
anytypeContextMenu =
|
||||
AnytypeContextMenu(
|
||||
type = AnytypeContextMenuType.HEADER,
|
||||
contextRef = WeakReference(requireContext()),
|
||||
anchorViewRef = WeakReference(originatingView),
|
||||
onMarkupActionClicked = {
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M6.9968,4V20H12.4816C15.683,20 17.7426,18.5455 17.7426,15.5245V15.435C17.7426,13.3538 16.8695,12.1678 14.5412,11.6084C16.3546,10.9818 16.959,9.6839 16.959,8.2294V8.1399C16.959,4.9846 14.7875,4 11.81,4H6.9968ZM12.4369,18.4783H8.8997V12.5035H12.1682C14.7651,12.5035 15.8397,13.4434 15.8397,15.4126V15.5021C15.8397,17.4713 14.7651,18.4783 12.4369,18.4783ZM11.81,10.9818H8.8997V5.5217H11.7652C14.0039,5.5217 15.0561,6.2601 15.0561,8.0727V8.1622C15.0561,10.1315 14.1606,10.9818 11.81,10.9818Z" />
|
||||
</vector>
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M10.1214,5.2932C10.5119,5.6838 10.5119,6.3169 10.1213,6.7074L4.8285,12L10.1213,17.2926C10.5119,17.6831 10.5119,18.3163 10.1214,18.7068C9.7309,19.0973 9.0977,19.0974 8.7072,18.7068L2,12L8.7072,5.2932C9.0977,4.9027 9.7309,4.9027 10.1214,5.2932Z" />
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M13.8786,5.2932C13.4881,5.6838 13.4881,6.3169 13.8787,6.7074L19.1715,12L13.8787,17.2926C13.4881,17.6831 13.4881,18.3163 13.8786,18.7068C14.2691,19.0973 14.9023,19.0974 15.2928,18.7068L22,12L15.2928,5.2932C14.9023,4.9027 14.2691,4.9027 13.8786,5.2932Z" />
|
||||
</vector>
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M13.5464,8.5H11.6034L9.7142,20H11.6573L13.5464,8.5Z" />
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M14.3906,4.9688C14.3906,5.6591 13.831,6.2188 13.1406,6.2188C12.4503,6.2188 11.8906,5.6591 11.8906,4.9688C11.8906,4.2784 12.4503,3.7188 13.1406,3.7188C13.831,3.7188 14.3906,4.2784 14.3906,4.9688Z" />
|
||||
</vector>
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M11.4364,10.5839C11.8923,10.7146 12.3224,10.9595 12.6814,11.3185C13.8104,12.4475 13.8104,14.2779 12.6814,15.4069L9.9559,18.1325C8.8269,19.2615 6.9965,19.2615 5.8675,18.1325C4.7385,17.0035 4.7385,15.1731 5.8675,14.0441L7.7773,12.1343C7.5525,11.2924 7.5209,10.4096 7.6825,9.5562C7.5256,9.6784 7.3745,9.8115 7.2303,9.9558L4.5047,12.6813C2.6231,14.5629 2.6231,17.6137 4.5047,19.4953C6.3863,21.3769 9.437,21.3769 11.3187,19.4953L14.0442,16.7697C15.9258,14.8881 15.9258,11.8374 14.0442,9.9558C13.5597,9.4713 12.9977,9.1115 12.3981,8.8765L12.0002,9.2745C11.6374,9.6372 11.4495,10.1086 11.4364,10.5839Z" />
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M12.5637,13.4159C12.1078,13.2852 11.6777,13.0404 11.3186,12.6812C10.1896,11.5523 10.1896,9.7218 11.3186,8.5929L14.0441,5.8673C15.1731,4.7383 17.0035,4.7383 18.1325,5.8673C19.2615,6.9963 19.2615,8.8267 18.1325,9.9557L16.2228,11.8654C16.4476,12.7073 16.4793,13.59 16.3177,14.4434C16.4745,14.3213 16.6256,14.1882 16.7697,14.044L19.4953,11.3184C21.3769,9.4368 21.3769,6.3861 19.4953,4.5045C17.6137,2.6229 14.563,2.6229 12.6814,4.5045L9.9558,7.2301C8.0742,9.1117 8.0742,12.1624 9.9558,14.044C10.4403,14.5286 11.0024,14.8883 11.6021,15.1233L12,14.7254C12.3628,14.3627 12.5507,13.8912 12.5637,13.4159Z" />
|
||||
</vector>
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M12.2922,20.5C7.9993,20.5 6.4484,18.0648 6.1563,15.2353H8.0442C8.2915,17.2067 9.0781,18.8765 12.2922,18.8765C14.36,18.8765 15.9558,17.6241 15.9558,15.7456C15.9558,13.867 15.1242,13.0553 12.0674,12.5682C8.696,12.0116 6.6957,10.9679 6.6957,7.9993C6.6957,5.4714 8.8309,3.5 11.8651,3.5C15.1017,3.5 17.0571,5.1003 17.3942,8.0689H15.6411C15.259,5.9584 14.1127,5.1235 11.8651,5.1235C9.64,5.1235 8.5162,6.2367 8.5162,7.8138C8.5162,9.4141 9.1006,10.2954 12.3821,10.7824C15.9558,11.339 17.8438,12.4986 17.8438,15.6064C17.8438,18.3895 15.4838,20.5 12.2922,20.5Z" />
|
||||
<path
|
||||
android:fillColor="#ACA996"
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M4,11h16v2h-16z" />
|
||||
</vector>
|
||||
|
|
|
@ -84,4 +84,6 @@
|
|||
<item>#E3F7D0</item>
|
||||
</array>
|
||||
|
||||
<color name="context_menu_selected_item">#ACA996</color>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue