1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-3526 Widgets | Enhancement | Do not suggest a system widget if it is already added + remove legacy (#2245)

This commit is contained in:
Evgenii Kozlov 2025-04-04 22:02:07 +02:00 committed by GitHub
parent 4f5dcb435f
commit c45901934a
Signed by: github
GPG key ID: B5690EEEBB952194
15 changed files with 111 additions and 308 deletions

View file

@ -598,8 +598,6 @@ fun Widget.Source.Bundled.res(): Int = when (this) {
Widget.Source.Bundled.Favorites -> R.string.favorites
Widget.Source.Bundled.Recent -> R.string.recent
Widget.Source.Bundled.RecentLocal -> R.string.recently_opened
Widget.Source.Bundled.Sets -> R.string.sets
Widget.Source.Bundled.Collections -> R.string.collections
Widget.Source.Bundled.Bin -> R.string.bin
Widget.Source.Bundled.AllObjects -> R.string.all_content
}

View file

@ -80,8 +80,6 @@ fun ListWidgetCard(
Type.Favorites -> stringResource(id = R.string.favorites)
Type.Recent -> stringResource(id = R.string.recent)
Type.RecentLocal -> stringResource(id = R.string.recently_opened)
Type.Sets -> stringResource(id = R.string.sets)
Type.Collections -> stringResource(id = R.string.collections)
Type.Bin -> stringResource(R.string.bin)
},
isCardMenuExpanded = isCardMenuExpanded,

View file

@ -0,0 +1,11 @@
package com.anytypeio.anytype.core_models.widgets
object BundledWidgetSourceIds {
const val FAVORITE = "favorite"
const val RECENT = "recent"
const val RECENT_LOCAL = "recentOpen"
const val BIN = "bin"
const val ALL_OBJECTS = "allObjects"
val ids = listOf(FAVORITE, RECENT, RECENT_LOCAL, BIN, ALL_OBJECTS)
}

View file

@ -11,6 +11,7 @@ import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.ext.asMap
import com.anytypeio.anytype.core_models.primitives.Space
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.ResultInteractor
import com.anytypeio.anytype.domain.block.repo.BlockRepository
@ -19,11 +20,11 @@ import javax.inject.Inject
class GetSuggestedWidgetTypes @Inject constructor(
dispatchers: AppCoroutineDispatchers,
private val repo: BlockRepository,
) : ResultInteractor<GetSuggestedWidgetTypes.Params, List<ObjectWrapper.Type>>(dispatchers.io) {
) : ResultInteractor<GetSuggestedWidgetTypes.Params, GetSuggestedWidgetTypes.Result>(dispatchers.io) {
override suspend fun doWork(params: Params): List<ObjectWrapper.Type> {
override suspend fun doWork(params: Params): Result {
val alreadyUsedObjectTypes = getAlreadyUsedTypes(
val (alreadyUsedObjectTypes, alreadyUsedSystemSources) = getAlreadyUsedTypes(
space = params.space,
widgets = params.ctx
)
@ -55,11 +56,15 @@ class GetSuggestedWidgetTypes @Inject constructor(
ObjectWrapper.Type(result)
}
return types
return Result(
suggestedObjectTypes = types,
suggestedSystemSources = BundledWidgetSourceIds.ids - alreadyUsedSystemSources
)
}
private suspend fun getAlreadyUsedTypes(space: SpaceId, widgets: Id) : List<Id> {
val result = mutableListOf<Id>()
private suspend fun getAlreadyUsedTypes(space: SpaceId, widgets: Id) : Pair<List<Id>, List<Id>> {
val usedObjectTypes = mutableListOf<Id>()
val usedSystemSources = mutableListOf<Id>()
runCatching {
val preview = repo.getObject(space = space, id = widgets)
@ -77,14 +82,18 @@ class GetSuggestedWidgetTypes @Inject constructor(
)
val wrapper = ObjectWrapper.Basic(source)
if (wrapper.layout == ObjectType.Layout.OBJECT_TYPE) {
result.add(wrapper.id)
usedObjectTypes.add(wrapper.id)
} else {
if (BundledWidgetSourceIds.ids.contains(content.target)) {
usedSystemSources.add(content.target)
}
}
}
}
}
}
return result.distinct()
return usedObjectTypes.distinct() to usedSystemSources.distinct()
}
@ -94,6 +103,11 @@ class GetSuggestedWidgetTypes @Inject constructor(
val objectTypeFilters: List<DVFilter>,
val objectTypeKeys: List<Id>
)
data class Result(
val suggestedObjectTypes: List<ObjectWrapper.Type>,
val suggestedSystemSources: List<String>
)
companion object {
const val DEFAULT_LIMIT = 10

View file

@ -1636,10 +1636,6 @@ fun CoroutineScope.sendDeleteWidgetEvent(
props = Props(
buildMap {
when (bundled) {
Widget.Source.Bundled.Collections -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_COLLECTIONS)
}
Widget.Source.Bundled.Favorites -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_FAVORITES)
}
@ -1652,9 +1648,6 @@ fun CoroutineScope.sendDeleteWidgetEvent(
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_RECENT_LOCAL)
}
Widget.Source.Bundled.Sets -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_SETS)
}
Widget.Source.Bundled.Bin -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_BIN)
}
@ -1682,9 +1675,6 @@ fun CoroutineScope.sendSelectHomeTabEvent(
buildMap {
put(WidgetAnalytics.VIEW, WidgetAnalytics.VIEW_WIDGET)
when (bundled) {
Widget.Source.Bundled.Collections -> {
put(WidgetAnalytics.TAB, WidgetAnalytics.WIDGET_SOURCE_COLLECTIONS)
}
Widget.Source.Bundled.Favorites -> {
put(WidgetAnalytics.TAB, WidgetAnalytics.WIDGET_SOURCE_FAVORITES)
@ -1698,9 +1688,6 @@ fun CoroutineScope.sendSelectHomeTabEvent(
put(WidgetAnalytics.TAB, WidgetAnalytics.WIDGET_SOURCE_RECENT_LOCAL)
}
Widget.Source.Bundled.Sets -> {
put(WidgetAnalytics.TAB, WidgetAnalytics.WIDGET_SOURCE_SETS)
}
Widget.Source.Bundled.Bin -> {
put(WidgetAnalytics.TAB, WidgetAnalytics.WIDGET_SOURCE_BIN)
}
@ -1762,25 +1749,15 @@ fun CoroutineScope.sendReorderWidgetEvent(
props = Props(
buildMap {
when (bundled) {
Widget.Source.Bundled.Collections -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_COLLECTIONS)
}
Widget.Source.Bundled.Favorites -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_FAVORITES)
}
Widget.Source.Bundled.Recent -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_RECENT)
}
Widget.Source.Bundled.RecentLocal -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_RECENT_LOCAL)
}
Widget.Source.Bundled.Sets -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_SETS)
}
Widget.Source.Bundled.Bin -> {
put(WidgetAnalytics.TYPE, WidgetAnalytics.WIDGET_SOURCE_BIN)
}

View file

@ -32,6 +32,7 @@ import com.anytypeio.anytype.core_models.multiplayer.SpaceMemberPermissions
import com.anytypeio.anytype.core_models.primitives.Space
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.core_utils.ext.cancel
import com.anytypeio.anytype.core_utils.ext.replace
import com.anytypeio.anytype.core_utils.ext.withLatestFrom
@ -111,7 +112,6 @@ import com.anytypeio.anytype.presentation.spaces.spaceIcon
import com.anytypeio.anytype.presentation.util.Dispatcher
import com.anytypeio.anytype.presentation.vault.ExitToVaultDelegate
import com.anytypeio.anytype.presentation.widgets.AllContentWidgetContainer
import com.anytypeio.anytype.presentation.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.presentation.widgets.CollapsedWidgetStateHolder
import com.anytypeio.anytype.presentation.widgets.DataViewListWidgetContainer
import com.anytypeio.anytype.presentation.widgets.DropDownMenuAction
@ -1001,22 +1001,6 @@ class HomeScreenViewModel(
)
}
}
is Widget.Source.Bundled.Sets -> {
viewModelScope.sendSelectHomeTabEvent(
analytics = analytics,
bundled = source
)
// TODO switch to bundled widgets id
viewModelScope.launch {
navigation(
Navigation.ExpandWidget(
subscription = Subscription.Sets,
space = spaceManager.get()
)
)
}
}
is Widget.Source.Bundled.Recent -> {
viewModelScope.sendSelectHomeTabEvent(
analytics = analytics,
@ -1032,7 +1016,6 @@ class HomeScreenViewModel(
)
}
}
is Widget.Source.Bundled.RecentLocal -> {
viewModelScope.sendSelectHomeTabEvent(
analytics = analytics,
@ -1048,23 +1031,6 @@ class HomeScreenViewModel(
)
}
}
is Widget.Source.Bundled.Collections -> {
viewModelScope.sendSelectHomeTabEvent(
analytics = analytics,
bundled = source
)
// TODO switch to bundled widgets id
viewModelScope.launch {
navigation(
Navigation.ExpandWidget(
subscription = Subscription.Collections,
space = spaceManager.get()
)
)
}
}
is Widget.Source.Default -> {
if (source.obj.isArchived != true) {
dispatchSelectHomeTabCustomSourceEvent(source)

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.RelationFormat
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.domain.library.StoreSearchByIdsParams
import com.anytypeio.anytype.domain.library.StoreSearchParams
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
@ -191,9 +192,7 @@ class ListWidgetContainer(
private fun resolveType() = when (subscription) {
BundledWidgetSourceIds.RECENT -> WidgetView.ListOfObjects.Type.Recent
BundledWidgetSourceIds.RECENT_LOCAL -> WidgetView.ListOfObjects.Type.RecentLocal
BundledWidgetSourceIds.SETS -> WidgetView.ListOfObjects.Type.Sets
BundledWidgetSourceIds.FAVORITE -> WidgetView.ListOfObjects.Type.Favorites
BundledWidgetSourceIds.COLLECTIONS -> WidgetView.ListOfObjects.Type.Collections
BundledWidgetSourceIds.BIN -> WidgetView.ListOfObjects.Type.Bin
else -> throw IllegalStateException("Unexpected subscription: $subscription")
}
@ -236,18 +235,6 @@ class ListWidgetContainer(
limit = limit
)
}
BundledWidgetSourceIds.SETS -> {
StoreSearchParams(
space = SpaceId(space),
subscription = subscription,
sorts = ObjectSearchConstants.sortTabSets,
filters = ObjectSearchConstants.filterTabSets(),
keys = keys,
limit = limit
)
}
BundledWidgetSourceIds.FAVORITE -> {
StoreSearchParams(
space = SpaceId(space),
@ -269,18 +256,6 @@ class ListWidgetContainer(
limit = limit
)
}
BundledWidgetSourceIds.COLLECTIONS -> {
StoreSearchParams(
space = SpaceId(space),
subscription = subscription,
sorts = collectionsSorts,
filters = ObjectSearchConstants.collectionFilters(),
keys = keys,
limit = limit
)
}
BundledWidgetSourceIds.BIN, Subscriptions.SUBSCRIPTION_BIN -> {
StoreSearchParams(
space = SpaceId(space),

View file

@ -9,7 +9,9 @@ import com.anytypeio.anytype.core_models.DVFilter
import com.anytypeio.anytype.core_models.DVFilterCondition
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.domain.base.Resultat
import com.anytypeio.anytype.domain.base.fold
import com.anytypeio.anytype.domain.base.getOrDefault
@ -62,7 +64,7 @@ class SelectWidgetSourceViewModel(
storeOfObjectTypes = storeOfObjectTypes
) {
val suggested = MutableStateFlow<List<SuggestWidgetObjectType>?>(null)
val suggested = MutableStateFlow<SuggestedWidgetsState>(SuggestedWidgetsState.Init)
val isDismissed = MutableStateFlow(false)
var config : Config = Config.None
@ -70,38 +72,51 @@ class SelectWidgetSourceViewModel(
val viewState = combine(
stateData
.asFlow(),
suggested.filterNotNull()
suggested.filterIsInstance<SuggestedWidgetsState.Default>()
) { state, suggested ->
if (suggested.isNotEmpty()) {
when(state) {
is ObjectSearchView.Success -> {
state.copy(
objects = buildList {
// System widgets
when(state) {
is ObjectSearchView.Success -> {
state.copy(
objects = buildList {
// System widgets
if (suggested.suggestedSystemSources.isNotEmpty()) {
add(ObjectSearchSection.SelectWidgetSource.System)
add(BundledWidgetSourceView.Favorites)
add(BundledWidgetSourceView.AllObjects)
add(BundledWidgetSourceView.Recent)
add(BundledWidgetSourceView.RecentLocal)
add(BundledWidgetSourceView.Bin)
// Suggested widgets (aka object type widgets)
if (suggested.isNotEmpty()) {
add(ObjectSearchSection.SelectWidgetSource.Suggested)
addAll(suggested)
with(suggested.suggestedSystemSources) {
if (contains(BundledWidgetSourceIds.FAVORITE)) {
add(BundledWidgetSourceView.Favorites)
}
if (contains(BundledWidgetSourceIds.ALL_OBJECTS)) {
add(BundledWidgetSourceView.AllObjects)
}
if (contains(BundledWidgetSourceIds.RECENT)) {
add(BundledWidgetSourceView.Recent)
}
if (contains(BundledWidgetSourceIds.RECENT_LOCAL)) {
add(BundledWidgetSourceView.RecentLocal)
}
if (contains(BundledWidgetSourceIds.BIN)) {
add(BundledWidgetSourceView.Bin)
}
}
// Widgets from existing objects
add(ObjectSearchSection.SelectWidgetSource.FromMyObjects)
addAll(state.objects)
}
)
}
else -> state
// Suggested widgets (aka object type widgets)
if (suggested.suggestedObjectTypes.isNotEmpty()) {
add(ObjectSearchSection.SelectWidgetSource.Suggested)
addAll(suggested.suggestedObjectTypes)
}
// Widgets from existing objects
add(ObjectSearchSection.SelectWidgetSource.FromMyObjects)
addAll(state.objects)
}
)
}
} else {
state
else -> state
}
}
@ -186,14 +201,17 @@ class SelectWidgetSourceViewModel(
objectTypeKeys = ObjectSearchConstants.defaultKeysObjectType,
ctx = ctx
)
).onSuccess { types ->
suggested.value = types.map { type ->
SuggestWidgetObjectType(
id = type.id,
name = fieldParser.getObjectPluralName(type),
objectIcon = type.objectIcon()
)
}
).onSuccess { result ->
suggested.value = SuggestedWidgetsState.Default(
suggestedSystemSources = result.suggestedSystemSources,
suggestedObjectTypes = result.suggestedObjectTypes.map { type ->
SuggestWidgetObjectType(
id = type.id,
name = fieldParser.getObjectPluralName(type),
objectIcon = type.objectIcon()
)
}
)
}
}
getObjectTypes()
@ -415,4 +433,12 @@ class SelectWidgetSourceViewModel(
val isInEditMode: Boolean
) : Config()
}
sealed class SuggestedWidgetsState {
data object Init : SuggestedWidgetsState()
data class Default(
val suggestedObjectTypes: List<SuggestWidgetObjectType>,
val suggestedSystemSources: List<String>
) : SuggestedWidgetsState()
}
}

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.WidgetLayout
import com.anytypeio.anytype.core_models.isDataView
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.fold
import com.anytypeio.anytype.domain.widgets.UpdateWidget

View file

@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.domain.library.StoreSearchByIdsParams
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
import com.anytypeio.anytype.domain.misc.UrlBuilder

View file

@ -9,6 +9,7 @@ import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.Struct
import com.anytypeio.anytype.core_models.ext.asMap
import com.anytypeio.anytype.core_models.SupportedLayouts.isSupportedForWidgets
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.domain.primitives.FieldParser
import com.anytypeio.anytype.presentation.widgets.WidgetView.Name
@ -83,16 +84,6 @@ sealed class Widget {
override val type: Id? = null
}
data object Sets : Bundled() {
override val id: Id = BundledWidgetSourceIds.SETS
override val type: Id? = null
}
data object Collections : Bundled() {
override val id: Id = BundledWidgetSourceIds.COLLECTIONS
override val type: Id? = null
}
data object Recent : Bundled() {
override val id: Id = BundledWidgetSourceIds.RECENT
override val type: Id? = null
@ -240,8 +231,6 @@ fun List<Block>.parseWidgets(
fun Id.bundled() : Widget.Source.Bundled = when (this) {
BundledWidgetSourceIds.RECENT -> Widget.Source.Bundled.Recent
BundledWidgetSourceIds.RECENT_LOCAL -> Widget.Source.Bundled.RecentLocal
BundledWidgetSourceIds.SETS -> Widget.Source.Bundled.Sets
BundledWidgetSourceIds.COLLECTIONS -> Widget.Source.Bundled.Collections
BundledWidgetSourceIds.FAVORITE -> Widget.Source.Bundled.Favorites
BundledWidgetSourceIds.BIN -> Widget.Source.Bundled.Bin
BundledWidgetSourceIds.ALL_OBJECTS -> Widget.Source.Bundled.AllObjects

View file

@ -70,19 +70,4 @@ object WidgetConfig {
private val listLimitOptions = intArrayOf(DEFAULT_LIST_LIMIT, 6, 8)
private val compactListLimitOptions = intArrayOf(DEFAULT_COMPACT_LIST_LIMIT, 10, 14)
private val treeLimitOptions = intArrayOf(DEFAULT_TREE_LIMIT, 10, 14)
}
object BundledWidgetSourceIds {
const val FAVORITE = "favorite"
const val RECENT = "recent"
const val RECENT_LOCAL = "recentOpen"
const val BIN = "bin"
const val ALL_OBJECTS = "allObjects"
@Deprecated("DROID-3438 To be deleted")
const val SETS = "set"
@Deprecated("DROID-3438 To be deleted")
const val COLLECTIONS = "collection"
val ids = listOf(FAVORITE, RECENT, RECENT_LOCAL, SETS, COLLECTIONS, BIN, ALL_OBJECTS)
}

View file

@ -117,8 +117,6 @@ sealed class WidgetView {
data object Recent : Type()
data object RecentLocal : Type()
data object Favorites : Type()
data object Sets: Type()
data object Collections: Type()
data object Bin: Type()
}
}

View file

@ -1,9 +1,9 @@
package com.anytypeio.anytype.presentation.widgets.source
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.presentation.navigation.DefaultSearchItem
import com.anytypeio.anytype.presentation.objects.ObjectIcon
import com.anytypeio.anytype.presentation.widgets.BundledWidgetSourceIds
/**
* Used for picking bundled widget source from list of objects.

View file

@ -29,6 +29,7 @@ import com.anytypeio.anytype.core_models.primitives.Space
import com.anytypeio.anytype.core_models.primitives.SpaceId
import com.anytypeio.anytype.core_models.primitives.TypeId
import com.anytypeio.anytype.core_models.primitives.TypeKey
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.core_utils.tools.FeatureToggles
import com.anytypeio.anytype.domain.auth.interactor.ClearLastOpenedObject
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
@ -89,7 +90,6 @@ import com.anytypeio.anytype.presentation.spaces.SpaceIconView
import com.anytypeio.anytype.presentation.util.DefaultCoroutineTestRule
import com.anytypeio.anytype.presentation.util.Dispatcher
import com.anytypeio.anytype.presentation.vault.ExitToVaultDelegate
import com.anytypeio.anytype.presentation.widgets.BundledWidgetSourceIds
import com.anytypeio.anytype.presentation.widgets.CollapsedWidgetStateHolder
import com.anytypeio.anytype.presentation.widgets.DropDownMenuAction
import com.anytypeio.anytype.presentation.widgets.ListWidgetContainer
@ -917,7 +917,6 @@ class HomeScreenViewModelTest {
val favoriteSource = StubObject(id = BundledWidgetSourceIds.FAVORITE)
val recentSource = StubObject(id = BundledWidgetSourceIds.RECENT)
val setsSource = StubObject(id = BundledWidgetSourceIds.SETS)
val favoriteLink = StubLinkToObjectBlock(
target = favoriteSource.id
@ -927,10 +926,6 @@ class HomeScreenViewModelTest {
target = recentSource.id
)
val setsLink = StubLinkToObjectBlock(
target = setsSource.id
)
val favoriteWidgetBlock = StubWidgetBlock(
layout = layout,
children = listOf(favoriteLink.id)
@ -941,14 +936,9 @@ class HomeScreenViewModelTest {
children = listOf(recentLink.id)
)
val setsWidgetBlock = StubWidgetBlock(
layout = layout,
children = listOf(setsLink.id)
)
val smartBlock = StubSmartBlock(
id = WIDGET_OBJECT_ID,
children = listOf(favoriteWidgetBlock.id, recentWidgetBlock.id, setsWidgetBlock.id),
children = listOf(favoriteWidgetBlock.id, recentWidgetBlock.id)
)
val givenObjectView = StubObjectView(
@ -958,9 +948,7 @@ class HomeScreenViewModelTest {
favoriteWidgetBlock,
favoriteLink,
recentWidgetBlock,
recentLink,
setsWidgetBlock,
setsLink
recentLink
)
)
@ -974,13 +962,6 @@ class HomeScreenViewModelTest {
results = listOf(firstLink, secondLink)
)
stubSearchByIds(
subscription = setsWidgetBlock.id,
targets = listOf(firstLink.id, secondLink.id),
results = listOf(firstLink, secondLink),
keys = TreeWidgetContainer.keys
)
stubDefaultSearch(
params = ListWidgetContainer.params(
subscription = BundledWidgetSourceIds.FAVORITE,
@ -1042,16 +1023,6 @@ class HomeScreenViewModelTest {
stubGetSpaceView(defaultSpaceConfig.spaceView)
stubDefaultSearch(
params = ListWidgetContainer.params(
subscription = BundledWidgetSourceIds.SETS,
space = defaultSpaceConfig.space,
keys = TreeWidgetContainer.keys,
limit = WidgetConfig.DEFAULT_TREE_LIMIT
),
results = listOf(firstLink, secondLink)
)
stubCollapsedWidgetState(id = anyString())
stubGetWidgetSession()
stubWidgetActiveView(favoriteWidgetBlock)
@ -1084,10 +1055,6 @@ class HomeScreenViewModelTest {
val secondWidget = firstTimeLoadingState1[2]
secondWidget is WidgetView.Tree && secondWidget.isLoading
}
assertTrue {
val thirdWidget = firstTimeLoadingState1[3]
thirdWidget is WidgetView.Tree && thirdWidget.isLoading
}
advanceUntilIdle()
@ -1100,10 +1067,6 @@ class HomeScreenViewModelTest {
val secondWidget = firstTimeLoadingState2[2]
secondWidget is WidgetView.Tree && !secondWidget.isLoading
}
assertTrue {
val thirdWidget = firstTimeLoadingState2[3]
thirdWidget is WidgetView.Tree && !thirdWidget.isLoading
}
val secondTimeState = awaitItem()
@ -1180,40 +1143,6 @@ class HomeScreenViewModelTest {
isExpanded = true
)
)
add(
WidgetView.Tree(
id = setsWidgetBlock.id,
source = Widget.Source.Bundled.Sets,
name = WidgetView.Name.Bundled(
Widget.Source.Bundled.Sets,
),
elements = listOf(
WidgetView.Tree.Element(
id = firstLink.id,
elementIcon = WidgetView.Tree.ElementIcon.Leaf,
obj = firstLink,
objectIcon = ObjectIcon.TypeIcon.Fallback.DEFAULT,
indent = 0,
path = setsWidgetBlock.id + "/" + setsSource.id + "/" + firstLink.id,
name = WidgetView.Name.Default(
prettyPrintName = fieldParser.getObjectName(firstLink)
)
),
WidgetView.Tree.Element(
id = secondLink.id,
elementIcon = WidgetView.Tree.ElementIcon.Leaf,
obj = secondLink,
objectIcon = ObjectIcon.TypeIcon.Fallback.DEFAULT,
indent = 0,
path = setsWidgetBlock.id + "/" + setsSource.id + "/" + secondLink.id,
name = WidgetView.Name.Default(
prettyPrintName = fieldParser.getObjectName(secondLink)
)
)
),
isExpanded = true
)
)
addAll(HomeScreenViewModel.actions)
},
actual = secondTimeState
@ -1600,11 +1529,9 @@ class HomeScreenViewModelTest {
val favoriteSource = StubObject(id = BundledWidgetSourceIds.FAVORITE)
val recentSource = StubObject(id = BundledWidgetSourceIds.RECENT)
val setsSource = StubObject(id = BundledWidgetSourceIds.SETS)
val favoriteLink = StubLinkToObjectBlock(target = favoriteSource.id)
val recentLink = StubLinkToObjectBlock(target = recentSource.id)
val setsLink = StubLinkToObjectBlock(target = setsSource.id)
val favoriteWidgetBlock = StubWidgetBlock(
layout = Block.Content.Widget.Layout.TREE,
@ -1616,14 +1543,9 @@ class HomeScreenViewModelTest {
children = listOf(recentLink.id)
)
val setsWidgetBlock = StubWidgetBlock(
layout = Block.Content.Widget.Layout.TREE,
children = listOf(setsLink.id)
)
val firstWidgetObjectSmartBlock = StubSmartBlock(
id = WIDGET_OBJECT_ID,
children = listOf(favoriteWidgetBlock.id, recentWidgetBlock.id, setsWidgetBlock.id),
children = listOf(favoriteWidgetBlock.id, recentWidgetBlock.id)
)
val secondWidgetObjectSmartBlock = StubSmartBlock(
@ -1638,9 +1560,7 @@ class HomeScreenViewModelTest {
favoriteWidgetBlock,
favoriteLink,
recentWidgetBlock,
recentLink,
setsWidgetBlock,
setsLink
recentLink
)
)
@ -1671,12 +1591,6 @@ class HomeScreenViewModelTest {
results = listOf(firstLink, secondLink)
)
stubSearchByIds(
subscription = setsWidgetBlock.id,
targets = listOf(firstLink.id, secondLink.id),
results = listOf(firstLink, secondLink)
)
stubDefaultSearch(
params = ListWidgetContainer.params(
subscription = BundledWidgetSourceIds.FAVORITE,
@ -1697,16 +1611,6 @@ class HomeScreenViewModelTest {
results = listOf(firstLink, secondLink)
)
stubDefaultSearch(
params = ListWidgetContainer.params(
subscription = BundledWidgetSourceIds.SETS,
space = defaultSpaceConfig.space,
keys = ListWidgetContainer.keys,
limit = WidgetConfig.DEFAULT_LIST_LIMIT
),
results = listOf(firstLink, secondLink)
)
stubCollapsedWidgetState(id = anyString())
stubGetWidgetSession()
stubWidgetActiveView(favoriteWidgetBlock)
@ -1728,8 +1632,7 @@ class HomeScreenViewModelTest {
unsubscribe(
listOf(
favoriteSource.id,
recentSource.id,
setsSource.id
recentSource.id
)
)
} doReturn Unit
@ -1752,8 +1655,7 @@ class HomeScreenViewModelTest {
unsubscribe(
subscriptions = listOf(
favoriteSource.id,
recentSource.id,
setsSource.id
recentSource.id
)
)
}
@ -1766,8 +1668,7 @@ class HomeScreenViewModelTest {
unsubscribe(
subscriptions = listOf(
favoriteSource.id,
recentSource.id,
setsSource.id
recentSource.id
)
)
}
@ -1796,11 +1697,9 @@ class HomeScreenViewModelTest {
val favoriteSource = StubObject(id = BundledWidgetSourceIds.FAVORITE)
val recentSource = StubObject(id = BundledWidgetSourceIds.RECENT)
val setsSource = StubObject(id = BundledWidgetSourceIds.SETS)
val favoriteLink = StubLinkToObjectBlock(target = favoriteSource.id)
val recentLink = StubLinkToObjectBlock(target = recentSource.id)
val setsLink = StubLinkToObjectBlock(target = setsSource.id)
val layout = Block.Content.Widget.Layout.LIST
@ -1814,14 +1713,9 @@ class HomeScreenViewModelTest {
children = listOf(recentLink.id)
)
val setsWidgetBlock = StubWidgetBlock(
layout = layout,
children = listOf(setsLink.id)
)
val firstWidgetObjectSmartBlock = StubSmartBlock(
id = WIDGET_OBJECT_ID,
children = listOf(favoriteWidgetBlock.id, recentWidgetBlock.id, setsWidgetBlock.id),
children = listOf(favoriteWidgetBlock.id, recentWidgetBlock.id)
)
val secondWidgetObjectSmartBlock = StubSmartBlock(
@ -1836,9 +1730,7 @@ class HomeScreenViewModelTest {
favoriteWidgetBlock,
favoriteLink,
recentWidgetBlock,
recentLink,
setsWidgetBlock,
setsLink
recentLink
)
)
@ -1871,12 +1763,6 @@ class HomeScreenViewModelTest {
results = listOf(firstLink, secondLink)
)
stubSearchByIds(
subscription = setsWidgetBlock.id,
targets = listOf(firstLink.id, secondLink.id),
results = listOf(firstLink, secondLink)
)
stubSearchByIds(
subscription = favoriteSource.id,
keys = ListWidgetContainer.keys,
@ -1905,16 +1791,6 @@ class HomeScreenViewModelTest {
stubGetSpaceView(defaultSpaceConfig.spaceView)
stubDefaultSearch(
params = ListWidgetContainer.params(
subscription = BundledWidgetSourceIds.SETS,
space = defaultSpaceConfig.space,
keys = ListWidgetContainer.keys,
limit = WidgetConfig.DEFAULT_LIST_LIMIT
),
results = listOf(firstLink, secondLink)
)
stubCollapsedWidgetState(id = anyString())
stubGetWidgetSession()
stubWidgetActiveView(favoriteWidgetBlock)
@ -1950,17 +1826,6 @@ class HomeScreenViewModelTest {
)
}
verifyBlocking(storelessSubscriptionContainer, times(1)) {
subscribe(
ListWidgetContainer.params(
subscription = setsSource.id,
space = defaultSpaceConfig.space,
keys = ListWidgetContainer.keys,
limit = WidgetConfig.DEFAULT_LIST_LIMIT
)
)
}
verifyBlocking(storelessSubscriptionContainer, times(1)) {
subscribe(
ListWidgetContainer.params(
@ -1982,8 +1847,7 @@ class HomeScreenViewModelTest {
unsubscribe(
subscriptions = listOf(
favoriteSource.id,
recentSource.id,
setsSource.id
recentSource.id
)
)
}