Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
import com.anytypeio.anytype.domain.`object`.GetObject
import com.anytypeio.anytype.domain.`object`.SetObjectDetails
import com.anytypeio.anytype.domain.objects.GetDateObjectByTimestamp
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
import com.anytypeio.anytype.domain.objects.StoreOfRelations
Expand Down Expand Up @@ -172,4 +173,5 @@ interface DateObjectDependencies : ComponentDependencies {
fun provideSpaceSyncAndP2PStatusProvider(): SpaceSyncAndP2PStatusProvider
fun provideUserSettingsRepository(): UserSettingsRepository
fun fieldParser(): FieldParser
fun provideGetDateObjectByTimestamp(): GetDateObjectByTimestamp
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.anytypeio.anytype.ui.date

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -26,6 +27,7 @@ import com.anytypeio.anytype.core_ui.views.BaseAlertDialog
import com.anytypeio.anytype.core_utils.ext.argString
import com.anytypeio.anytype.core_utils.ext.subscribe
import com.anytypeio.anytype.core_utils.ext.toast
import com.anytypeio.anytype.core_utils.insets.EDGE_TO_EDGE_MIN_SDK
import com.anytypeio.anytype.core_utils.ui.BaseComposeFragment
import com.anytypeio.anytype.di.common.componentManager
import com.anytypeio.anytype.feature_date.viewmodel.UiErrorState
Expand Down Expand Up @@ -251,7 +253,11 @@ class DateObjectFragment : BaseComposeFragment(), ObjectTypeSelectionListener {
}

override fun onApplyWindowRootInsets(view: View) {
// Do nothing. TODO add ime padding.
if (Build.VERSION.SDK_INT >= EDGE_TO_EDGE_MIN_SDK) {
// Do nothing.
} else {
super.onApplyWindowRootInsets(view)
}
}

companion object DateLayoutNavigation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import com.anytypeio.anytype.domain.`object`.amend
import com.anytypeio.anytype.domain.`object`.unset
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

interface StoreOfRelations {
val size: Int
suspend fun observe(): Flow<Map<Id, ObjectWrapper.Relation>>
suspend fun getByKey(key: Key): ObjectWrapper.Relation?
suspend fun getByKeys(keys: List<Key>): List<ObjectWrapper.Relation>
suspend fun getById(id: Id): ObjectWrapper.Relation?
Expand Down Expand Up @@ -126,4 +128,8 @@ class DefaultStoreOfRelations : StoreOfRelations {
override fun trackChanges(): Flow<StoreOfRelations.TrackedEvent> = updates.onStart {
emit(StoreOfRelations.TrackedEvent.Init)
}

override suspend fun observe(): Flow<Map<Id, ObjectWrapper.Relation>> {
return trackChanges().map { store }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.anytypeio.anytype.domain.misc

import app.cash.turbine.test
import app.cash.turbine.turbineScope
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_models.StubRelationObject
import com.anytypeio.anytype.domain.objects.DefaultStoreOfRelations
import kotlinx.coroutines.test.runTest
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceUntilIdle

class DefaultRelationsStoreTest {

Expand Down Expand Up @@ -202,4 +207,28 @@ class DefaultRelationsStoreTest {
)
}
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun `should observe changes in store`() = runTest {
turbineScope{
val store = DefaultStoreOfRelations()
val relation = StubRelationObject()
val relation2 = StubRelationObject()
store.observe().test {
val firstItem = awaitItem()
assertTrue(firstItem.isEmpty(), "Initial store should be empty")

store.merge(listOf(relation))
advanceUntilIdle()
val secondItem = awaitItem()
assertEquals(1, secondItem.size, "Store should have one relation after merge")

store.merge(listOf(relation2))
advanceUntilIdle()
val thirdItem = awaitItem()
assertEquals(2, thirdItem.size, "Store should have two relations after second merge")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ suspend fun List<RelationListWithValueItem>.toUiFieldsItem(
.mapNotNull { item ->
val relation = storeOfRelations.getByKey(item.key.key)
if (relation == null) {
Timber.e("Relation ${item.key.key} not found in the relation store")
Timber.w("Relation ${item.key.key} not found in the relation store")
return@mapNotNull null
}
if (relation.key == Relations.LINKS || relation.key == Relations.BACKLINKS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.anytypeio.anytype.domain.misc.DateProvider
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
import com.anytypeio.anytype.domain.`object`.GetObject
import com.anytypeio.anytype.domain.objects.GetDateObjectByTimestamp
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
import com.anytypeio.anytype.domain.objects.StoreOfRelations
Expand All @@ -33,7 +34,8 @@ class DateObjectVMFactory @Inject constructor(
private val spaceSyncAndP2PStatusProvider: SpaceSyncAndP2PStatusProvider,
private val createObject: CreateObject,
private val fieldParser: FieldParser,
private val setObjectListIsArchived: SetObjectListIsArchived
private val setObjectListIsArchived: SetObjectListIsArchived,
private val getDateObjectByTimestamp: GetDateObjectByTimestamp
) : ViewModelProvider.Factory {

@Suppress("UNCHECKED_CAST")
Expand All @@ -53,7 +55,7 @@ class DateObjectVMFactory @Inject constructor(
spaceSyncAndP2PStatusProvider = spaceSyncAndP2PStatusProvider,
createObject = createObject,
fieldParser = fieldParser,
setObjectListIsArchived = setObjectListIsArchived

setObjectListIsArchived = setObjectListIsArchived,
getDateObjectByTimestamp = getDateObjectByTimestamp
) as T
}
Loading
Loading