mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1022 Sets or Collections | Fix | Fix inconsistent state when header title is updated by user (#3151)
This commit is contained in:
parent
0300102243
commit
8efc6b4c8a
6 changed files with 38 additions and 27 deletions
|
@ -554,14 +554,16 @@ open class ObjectSetFragment :
|
|||
}
|
||||
}
|
||||
|
||||
private fun bindHeader(title: BlockView.Title.Basic) {
|
||||
this.title.pauseTextWatchers {
|
||||
this.title.setText(title.text)
|
||||
private fun bindHeader(header: BlockView.Title.Basic) {
|
||||
if (title.text.toString() != header.text) {
|
||||
title.pauseTextWatchers {
|
||||
title.setText(header.text)
|
||||
}
|
||||
}
|
||||
binding.topToolbar.root.findViewById<TextView>(R.id.tvTopToolbarTitle).text = title.text
|
||||
binding.topToolbar.root.findViewById<TextView>(R.id.tvTopToolbarTitle).text = header.text
|
||||
|
||||
binding.objectHeader.root.findViewById<ViewGroup>(R.id.docEmojiIconContainer).apply {
|
||||
if (title.emoji != null) visible() else gone()
|
||||
if (header.emoji != null) visible() else gone()
|
||||
jobs += this.clicks()
|
||||
.throttleFirst()
|
||||
.onEach { vm.onIconClicked() }
|
||||
|
@ -569,7 +571,7 @@ open class ObjectSetFragment :
|
|||
}
|
||||
|
||||
binding.objectHeader.root.findViewById<View>(R.id.imageIcon).apply {
|
||||
if (title.image != null) visible() else gone()
|
||||
if (header.image != null) visible() else gone()
|
||||
jobs += this.clicks()
|
||||
.throttleFirst()
|
||||
.onEach { vm.onIconClicked() }
|
||||
|
@ -577,13 +579,13 @@ open class ObjectSetFragment :
|
|||
}
|
||||
|
||||
binding.objectHeader.root.findViewById<ImageView>(R.id.emojiIcon)
|
||||
.setEmojiOrNull(title.emoji)
|
||||
.setEmojiOrNull(header.emoji)
|
||||
|
||||
if (title.image != null) {
|
||||
if (header.image != null) {
|
||||
binding.objectHeader.root.findViewById<ImageView>(R.id.imageIcon).apply {
|
||||
Glide
|
||||
.with(this)
|
||||
.load(title.image)
|
||||
.load(header.image)
|
||||
.centerCrop()
|
||||
.into(this)
|
||||
}
|
||||
|
@ -592,9 +594,9 @@ open class ObjectSetFragment :
|
|||
}
|
||||
|
||||
setCover(
|
||||
coverColor = title.coverColor,
|
||||
coverGradient = title.coverGradient,
|
||||
coverImage = title.coverImage
|
||||
coverColor = header.coverColor,
|
||||
coverGradient = header.coverGradient,
|
||||
coverImage = header.coverImage
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.anytypeio.anytype.core_models.DVViewerType
|
|||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Relation
|
||||
import com.anytypeio.anytype.core_models.ext.content
|
||||
import com.anytypeio.anytype.core_utils.ext.CURRENT_MONTH
|
||||
import com.anytypeio.anytype.core_utils.ext.CURRENT_WEEK
|
||||
import com.anytypeio.anytype.core_utils.ext.EXACT_DAY
|
||||
|
@ -24,6 +23,7 @@ import com.anytypeio.anytype.core_utils.ext.NUMBER_OF_DAYS_FROM_NOW
|
|||
import com.anytypeio.anytype.core_utils.ext.TODAY
|
||||
import com.anytypeio.anytype.core_utils.ext.TOMORROW
|
||||
import com.anytypeio.anytype.core_utils.ext.YESTERDAY
|
||||
import com.anytypeio.anytype.core_utils.ext.orNull
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.ObjectStore
|
||||
import com.anytypeio.anytype.domain.objects.StoreOfRelations
|
||||
|
@ -195,20 +195,18 @@ fun title(
|
|||
urlBuilder: UrlBuilder,
|
||||
details: Map<Id, Block.Fields>
|
||||
): BlockView.Title.Basic {
|
||||
|
||||
val wrapper = ObjectWrapper.Basic(details[ctx]?.map ?: emptyMap())
|
||||
val objectDetails = details[ctx]
|
||||
val coverContainer = BlockFieldsCoverWrapper(objectDetails)
|
||||
.getCover(urlBuilder, coverImageHashProvider)
|
||||
|
||||
val coverContainer = BlockFieldsCoverWrapper(objectDetails).getCover(
|
||||
urlBuilder = urlBuilder,
|
||||
coverImageHashProvider = coverImageHashProvider
|
||||
)
|
||||
return BlockView.Title.Basic(
|
||||
id = title.id,
|
||||
text = title.content<Block.Content.Text>().text,
|
||||
emoji = objectDetails?.iconEmoji?.ifEmpty { null },
|
||||
image = objectDetails?.iconImage?.let { hash ->
|
||||
if (hash.isNotEmpty())
|
||||
urlBuilder.thumbnail(hash = hash)
|
||||
else
|
||||
null
|
||||
text = wrapper.name.orEmpty(),
|
||||
emoji = wrapper.iconEmoji.orNull(),
|
||||
image = wrapper.iconImage.orNull()?.let { hash ->
|
||||
urlBuilder.thumbnail(hash = hash)
|
||||
},
|
||||
coverImage = coverContainer.coverImage,
|
||||
coverColor = coverContainer.coverColor,
|
||||
|
|
|
@ -161,6 +161,7 @@ class ObjectSetViewModel(
|
|||
viewModelScope.launch {
|
||||
stateReducer.state
|
||||
.filterIsInstance<ObjectState.DataView>()
|
||||
.distinctUntilChanged()
|
||||
.collectLatest { state ->
|
||||
featured.value = state.featuredRelations(
|
||||
ctx = context,
|
||||
|
@ -221,7 +222,8 @@ class ObjectSetViewModel(
|
|||
.mapLatest { params ->
|
||||
updateText(params).process(
|
||||
failure = { e -> Timber.e(e, "Error while updating title") },
|
||||
success = { Timber.d("Sets' title updated successfully") }
|
||||
success = {
|
||||
Timber.d("Sets' title updated successfully") }
|
||||
)
|
||||
}
|
||||
.collect()
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.anytypeio.anytype.core_models.ObjectType
|
|||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.RelationLink
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.Relations.ID
|
||||
import com.anytypeio.anytype.core_models.Relations.LAYOUT
|
||||
import com.anytypeio.anytype.core_models.StubRelationObject
|
||||
|
@ -76,7 +77,13 @@ class CollectionAddRelationTest : ObjectSetViewModelTestSetup() {
|
|||
stubInterceptEvents()
|
||||
stubInterceptThreadStatus()
|
||||
|
||||
val rootObject = ObjectWrapper.Basic(map = mapOf(ID to root, LAYOUT to COLLECTION_LAYOUT))
|
||||
val rootObject = ObjectWrapper.Basic(
|
||||
map = mapOf(
|
||||
ID to root,
|
||||
Relations.NAME to objectCollection.details.details[root]?.name,
|
||||
LAYOUT to COLLECTION_LAYOUT
|
||||
)
|
||||
)
|
||||
|
||||
stubOpenObject(
|
||||
doc = listOf(
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.anytypeio.anytype.core_models.StubRelationLink
|
|||
import com.anytypeio.anytype.core_models.StubRelationObject
|
||||
import com.anytypeio.anytype.core_models.StubTitle
|
||||
import com.anytypeio.anytype.presentation.sets.subscription.DefaultDataViewSubscription
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import net.bytebuddy.utility.RandomString
|
||||
|
||||
class MockCollection(context: String) {
|
||||
|
@ -201,6 +202,7 @@ class MockCollection(context: String) {
|
|||
root to Block.Fields(
|
||||
mapOf(
|
||||
Relations.ID to root,
|
||||
Relations.NAME to MockDataFactory.randomString(),
|
||||
Relations.LAYOUT to ObjectType.Layout.COLLECTION.code.toDouble()
|
||||
)
|
||||
)
|
||||
|
|
|
@ -61,7 +61,7 @@ class ObjectStateCollectionViewTest : ObjectSetViewModelTestSetup() {
|
|||
assertIs<ObjectState.DataView.Collection>(stateFlow.awaitItem())
|
||||
|
||||
assertEquals(
|
||||
expected = mockObjectCollection.title.content.asText().text,
|
||||
expected = mockObjectCollection.details.details[mockObjectCollection.root]?.name,
|
||||
actual = headerFlow.awaitItem()?.text
|
||||
)
|
||||
viewerFlow.expectNoEvents()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue