mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Editor | Enhancement | Show icon in object toolbar (#2397)
This commit is contained in:
parent
0fcade1edf
commit
ce9adb051e
3 changed files with 46 additions and 17 deletions
|
@ -112,6 +112,7 @@ import com.anytypeio.anytype.presentation.editor.editor.sam.ScrollAndMoveTargetD
|
|||
import com.anytypeio.anytype.presentation.editor.markup.MarkupColorView
|
||||
import com.anytypeio.anytype.presentation.editor.model.EditorFooter
|
||||
import com.anytypeio.anytype.presentation.editor.template.SelectTemplateViewState
|
||||
import com.anytypeio.anytype.presentation.objects.ObjectIcon
|
||||
import com.anytypeio.anytype.ui.alert.AlertUpdateAppFragment
|
||||
import com.anytypeio.anytype.ui.base.NavigationFragment
|
||||
import com.anytypeio.anytype.ui.editor.cover.SelectCoverObjectFragment
|
||||
|
@ -1183,15 +1184,18 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
}
|
||||
|
||||
private fun resetDocumentTitle(state: ViewState.Success) {
|
||||
state.blocks.firstOrNull { view ->
|
||||
val title = state.blocks.firstOrNull { view ->
|
||||
view is BlockView.Title.Basic || view is BlockView.Title.Profile || view is BlockView.Title.Todo
|
||||
}?.let { view ->
|
||||
when (view) {
|
||||
}
|
||||
if (title != null) {
|
||||
when (title) {
|
||||
is BlockView.Title.Basic -> {
|
||||
resetTopToolbarTitle(
|
||||
text = view.text,
|
||||
text = title.text,
|
||||
emoji = title.emoji,
|
||||
image = title.image,
|
||||
)
|
||||
if (view.hasCover) {
|
||||
if (title.hasCover) {
|
||||
val mng = binding.recycler.layoutManager as LinearLayoutManager
|
||||
val pos = mng.findFirstVisibleItemPosition()
|
||||
if (pos == -1 || pos == 0) {
|
||||
|
@ -1203,9 +1207,11 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
}
|
||||
is BlockView.Title.Profile -> {
|
||||
resetTopToolbarTitle(
|
||||
text = view.text,
|
||||
text = title.text,
|
||||
emoji = null,
|
||||
image = title.image,
|
||||
)
|
||||
if (view.hasCover) {
|
||||
if (title.hasCover) {
|
||||
val mng = binding.recycler.layoutManager as LinearLayoutManager
|
||||
val pos = mng.findFirstVisibleItemPosition()
|
||||
if (pos == -1 || pos == 0) {
|
||||
|
@ -1217,9 +1223,11 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
}
|
||||
is BlockView.Title.Todo -> {
|
||||
resetTopToolbarTitle(
|
||||
text = view.text,
|
||||
text = title.text,
|
||||
emoji = null,
|
||||
image = title.image,
|
||||
)
|
||||
if (view.hasCover) {
|
||||
if (title.hasCover) {
|
||||
val mng = binding.recycler.layoutManager as LinearLayoutManager
|
||||
val pos = mng.findFirstVisibleItemPosition()
|
||||
if (pos == -1 || pos == 0) {
|
||||
|
@ -1235,8 +1243,27 @@ open class EditorFragment : NavigationFragment<FragmentEditorBinding>(R.layout.f
|
|||
}
|
||||
}
|
||||
|
||||
private fun resetTopToolbarTitle(text: String?) {
|
||||
private fun resetTopToolbarTitle(text: String?, emoji: String?, image: String?) {
|
||||
binding.topToolbar.title.text = text
|
||||
val iconView = binding.topToolbar.icon
|
||||
when {
|
||||
text.isNullOrBlank() -> {
|
||||
iconView.setIcon(ObjectIcon.None)
|
||||
iconView.gone()
|
||||
}
|
||||
!emoji.isNullOrBlank() -> {
|
||||
iconView.setIcon(ObjectIcon.Basic.Emoji(emoji))
|
||||
iconView.visible()
|
||||
}
|
||||
!image.isNullOrBlank()-> {
|
||||
iconView.setIcon(ObjectIcon.Basic.Image(image))
|
||||
iconView.visible()
|
||||
}
|
||||
else -> {
|
||||
iconView.setIcon(ObjectIcon.None)
|
||||
iconView.gone()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun render(state: ControlPanelState) {
|
||||
|
|
|
@ -8,10 +8,10 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.anytypeio.anytype.core_ui.R
|
||||
import com.anytypeio.anytype.core_ui.databinding.WidgetObjectTopToolbarBinding
|
||||
import com.anytypeio.anytype.core_ui.widgets.ObjectIconWidget
|
||||
import com.anytypeio.anytype.core_ui.widgets.StatusBadgeWidget
|
||||
|
||||
class ObjectTopToolbar @JvmOverloads constructor(
|
||||
|
@ -29,7 +29,7 @@ class ObjectTopToolbar @JvmOverloads constructor(
|
|||
val menu: View get() = binding.threeDotsButton
|
||||
val container: ViewGroup get() = binding.titleContainer
|
||||
val title: TextView get() = binding.tvTopToolbarTitle
|
||||
val image: ImageView get() = binding.ivTopToolbarIcon
|
||||
val icon: ObjectIconWidget get() = binding.ivTopToolbarIcon
|
||||
|
||||
init {
|
||||
container.alpha = 0f
|
||||
|
|
|
@ -41,13 +41,15 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
<com.anytypeio.anytype.core_ui.widgets.ObjectIconWidget
|
||||
android:id="@+id/ivTopToolbarIcon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:visibility="gone" />
|
||||
android:layout_marginEnd="6dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTopToolbarTitle"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue