mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
954: focus after long click (#957)
* #954: fix * #954: fixes * fix Co-authored-by: Ivanov Konstantin <ki@agileburo.com>
This commit is contained in:
parent
175092d40a
commit
1d417e7c1a
4 changed files with 101 additions and 2 deletions
|
@ -3,7 +3,6 @@ package com.anytypeio.anytype.core_ui.features.editor.holders.text
|
|||
import android.text.Editable
|
||||
import android.view.View
|
||||
import com.anytypeio.anytype.core_ui.R
|
||||
import com.anytypeio.anytype.core_ui.common.ThemeColor
|
||||
import com.anytypeio.anytype.core_ui.common.getBlockTextColor
|
||||
import com.anytypeio.anytype.core_ui.common.isLinksPresent
|
||||
import com.anytypeio.anytype.core_ui.extensions.color
|
||||
|
@ -133,7 +132,11 @@ abstract class Text(
|
|||
setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
click = { onBlockLongClick(root, it, clicked) }
|
||||
click = {
|
||||
// TODO do not call this methed directly, ask permission from vm
|
||||
enableReadMode()
|
||||
onBlockLongClick(root, it, clicked)
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ interface Item : Focusable, BlockView.TextSupport, BlockView.Permission, BlockVi
|
|||
override val body: String get() = text
|
||||
}
|
||||
|
||||
@Deprecated("Work in progress")
|
||||
abstract class BlockTextViewHolder(
|
||||
view: View,
|
||||
private val textWatcher: BlockTextWatcher,
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.anytypeio.anytype.sample
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.android.synthetic.main.activity_style.*
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Emulate long click on text block, with following
|
||||
* Selection and Focus events
|
||||
*
|
||||
*/
|
||||
class LongClickActivity: AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_long_clicked)
|
||||
|
||||
findViewById<ImageView>(R.id.close).setOnClickListener {
|
||||
styleToolbar.hideWithAnimation()
|
||||
}
|
||||
|
||||
textInputWidget.enableEditMode()
|
||||
textInputWidget.setText("Hi, Konstantin")
|
||||
|
||||
textInputWidget.setOnClickListener {
|
||||
Timber.d("Single clicked!")
|
||||
}
|
||||
|
||||
textInputWidget.setOnLongClickListener {
|
||||
Timber.d("Long clicked!")
|
||||
lifecycleScope.launch {
|
||||
delay(500)
|
||||
Timber.d("Enabling read mode")
|
||||
textInputWidget.enableReadMode()
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
textInputWidget.selectionWatcher = {intRange: IntRange ->
|
||||
Timber.d("Selection changed : $intRange")
|
||||
}
|
||||
|
||||
textInputWidget.setOnFocusChangeListener { v, hasFocus ->
|
||||
Timber.d("Focus changed:$hasFocus")
|
||||
}
|
||||
|
||||
button.setOnClickListener {
|
||||
textInputWidget.enableEditMode()
|
||||
}
|
||||
}
|
||||
}
|
39
sample/src/main/res/layout/activity_long_clicked.xml
Normal file
39
sample/src/main/res/layout/activity_long_clicked.xml
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Set in Read mode"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.anytypeio.anytype.core_ui.widgets.toolbar.style.StyleToolbarWidget
|
||||
android:id="@+id/styleToolbar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/dp_203"
|
||||
android:background="@color/white"
|
||||
android:translationY="203dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
|
||||
android:id="@+id/textInputWidget"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Add table
Add a link
Reference in a new issue