mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Editor | Fix | Sync status toolbar and header overlay (#2170)
This commit is contained in:
parent
63d8822d15
commit
c49dae3c99
3 changed files with 84 additions and 2 deletions
|
@ -326,8 +326,11 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
}
|
||||
|
||||
private val titleVisibilityDetector by lazy {
|
||||
FirstItemInvisibilityDetector { isVisible ->
|
||||
if (isVisible) {
|
||||
EditorHeaderOverlayDetector(
|
||||
threshold = dimen(R.dimen.default_toolbar_height),
|
||||
thresholdPadding = dimen(R.dimen.dp_8)
|
||||
) { isHeaderOverlaid ->
|
||||
if (isHeaderOverlaid) {
|
||||
binding.topToolbar.setBackgroundColor(0)
|
||||
binding.topToolbar.statusText.animate().alpha(1f).setDuration(DEFAULT_TOOLBAR_ANIM_DURATION)
|
||||
.start()
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
package com.anytypeio.anytype.core_ui.tools
|
||||
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.anytypeio.anytype.core_ui.features.editor.holders.other.Title
|
||||
import com.anytypeio.anytype.core_ui.features.editor.holders.relations.FeaturedRelationListViewHolder
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
/**
|
||||
* @property [threshold] threshold space between header and top toolbar with sync status when header and toolbar are considered overlaid.
|
||||
* @property [thresholdPadding] extra space for [threshold]
|
||||
*/
|
||||
class EditorHeaderOverlayDetector(
|
||||
private val threshold: Int,
|
||||
private val thresholdPadding: Int,
|
||||
onHeaderOverlayStateChanged: (Boolean) -> Unit
|
||||
) : RecyclerView.OnScrollListener() {
|
||||
|
||||
private var onHeaderOverlaid: Boolean by Delegates.observable(true) { _, old, new ->
|
||||
if (new != old) onHeaderOverlayStateChanged(new)
|
||||
}
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
if (recyclerView.layoutManager is LinearLayoutManager) {
|
||||
val lm = (recyclerView.layoutManager as LinearLayoutManager)
|
||||
val isFirstItemVisible = lm.findFirstVisibleItemPosition() == 0
|
||||
if (isFirstItemVisible) {
|
||||
when (val holder = recyclerView.findViewHolderForLayoutPosition(0)) {
|
||||
is Title.Document -> {
|
||||
val root = holder.binding.root
|
||||
val title = holder.binding.title
|
||||
val emojiIconContainer = holder.binding.docEmojiIconContainer
|
||||
val imageIconContainer = holder.binding.docImageIconContainer
|
||||
onHeaderOverlaid = when {
|
||||
emojiIconContainer.isVisible -> {
|
||||
(emojiIconContainer.top + root.top >= threshold + thresholdPadding)
|
||||
}
|
||||
imageIconContainer.isVisible -> {
|
||||
(imageIconContainer.top + root.top >= threshold + thresholdPadding)
|
||||
}
|
||||
else -> {
|
||||
root.top + title.top >= threshold + thresholdPadding
|
||||
}
|
||||
}
|
||||
}
|
||||
is Title.Todo -> {
|
||||
val root = holder.binding.root
|
||||
val title = holder.binding.titleContainer
|
||||
onHeaderOverlaid = if (holder.binding.cover.isVisible) {
|
||||
root.top + title.bottom >= threshold + thresholdPadding
|
||||
} else {
|
||||
root.top + title.top >= threshold + thresholdPadding
|
||||
}
|
||||
}
|
||||
is Title.Profile -> {
|
||||
val container = holder.itemView
|
||||
val cover = holder.binding.cover
|
||||
val icon = holder.binding.docProfileIconContainer
|
||||
val title = holder.binding.title
|
||||
onHeaderOverlaid = if (cover.isVisible) {
|
||||
(container.top + icon.bottom >= threshold + thresholdPadding)
|
||||
} else {
|
||||
(container.top + title.top >= threshold + thresholdPadding)
|
||||
}
|
||||
}
|
||||
is FeaturedRelationListViewHolder -> {
|
||||
// Handling note layout when header and title are missing.
|
||||
onHeaderOverlaid = holder.itemView.top >= threshold
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onHeaderOverlaid = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -49,6 +49,7 @@
|
|||
</FrameLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/titleContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue