From e12df848547dd67d0ee2d38d2ed80100b76f46f8 Mon Sep 17 00:00:00 2001 From: Evgenii Kozlov Date: Fri, 14 Feb 2025 14:28:36 +0100 Subject: [PATCH] DROID-3381 Widgets | Fix | Automatically apply link layout for widgets where source is image, file, video or space member (#2090) (cherry picked from commit d8673e0ac4064b0b96b87120ce6e7e0055db1539) --- .../anytype/presentation/home/HomeScreenViewModel.kt | 4 ++-- .../presentation/widgets/SelectWidgetSourceViewModel.kt | 4 +--- .../anytype/presentation/widgets/WidgetConfig.kt | 9 +++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModel.kt index ff73588efb..7a7f58dd80 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/home/HomeScreenViewModel.kt @@ -116,6 +116,7 @@ import com.anytypeio.anytype.presentation.widgets.TreeWidgetContainer import com.anytypeio.anytype.presentation.widgets.ViewId import com.anytypeio.anytype.presentation.widgets.Widget import com.anytypeio.anytype.presentation.widgets.WidgetActiveViewStateHolder +import com.anytypeio.anytype.presentation.widgets.WidgetConfig import com.anytypeio.anytype.presentation.widgets.WidgetContainer import com.anytypeio.anytype.presentation.widgets.WidgetDispatchEvent import com.anytypeio.anytype.presentation.widgets.WidgetId @@ -673,8 +674,7 @@ class HomeScreenViewModel( .withLatestFrom(spaceManager.observe()) { dispatch, config -> when (dispatch) { is WidgetDispatchEvent.SourcePicked.Default -> { - if (dispatch.sourceLayout == ObjectType.Layout.DATE.code || - dispatch.sourceLayout == ObjectType.Layout.PARTICIPANT.code) { + if (WidgetConfig.isLinkOnlyLayout(dispatch.sourceLayout)) { proceedWithCreatingWidget( ctx = config.widgets, source = dispatch.source, diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/SelectWidgetSourceViewModel.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/SelectWidgetSourceViewModel.kt index 75b9853fed..6d327f8bf9 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/SelectWidgetSourceViewModel.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/SelectWidgetSourceViewModel.kt @@ -208,9 +208,7 @@ class SelectWidgetSourceViewModel( isInEditMode = curr.isInEditMode ) } - if (view.layout == ObjectType.Layout.DATE || - view.layout == ObjectType.Layout.PARTICIPANT - ) { + if (view.layout != null && WidgetConfig.isLinkOnlyLayout(view.layout.code)) { isDismissed.value = true } } diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/WidgetConfig.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/WidgetConfig.kt index 5037916813..e5f27fb0e4 100644 --- a/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/WidgetConfig.kt +++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/widgets/WidgetConfig.kt @@ -1,5 +1,6 @@ package com.anytypeio.anytype.presentation.widgets +import com.anytypeio.anytype.core_models.ObjectType import com.anytypeio.anytype.core_models.ObjectTypeIds import com.anytypeio.anytype.core_models.ObjectWrapper import com.anytypeio.anytype.core_models.SupportedLayouts @@ -26,6 +27,14 @@ object WidgetConfig { && SupportedLayouts.isSupportedForWidgets(obj.layout) } + fun isLinkOnlyLayout(code: Int): Boolean { + return code == ObjectType.Layout.DATE.code || + code == ObjectType.Layout.PARTICIPANT.code || + code == ObjectType.Layout.IMAGE.code || + code == ObjectType.Layout.VIDEO.code || + code == ObjectType.Layout.FILE.code + } + fun resolveListWidgetLimit( isCompact: Boolean, isGallery: Boolean = false,