mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2191 Relations | Fix | Provide space ID when setting cover image for object (#839)
This commit is contained in:
parent
2030a23242
commit
335e9a09ce
10 changed files with 74 additions and 29 deletions
|
@ -10,6 +10,7 @@ import com.anytypeio.anytype.domain.cover.RemoveDocCover
|
|||
import com.anytypeio.anytype.domain.cover.SetDocCoverColor
|
||||
import com.anytypeio.anytype.domain.cover.SetDocCoverGradient
|
||||
import com.anytypeio.anytype.domain.cover.SetDocCoverImage
|
||||
import com.anytypeio.anytype.domain.workspace.SpaceManager
|
||||
import com.anytypeio.anytype.presentation.editor.cover.SelectCoverObjectSetViewModel
|
||||
import com.anytypeio.anytype.presentation.editor.cover.SelectCoverObjectViewModel
|
||||
import com.anytypeio.anytype.presentation.util.Dispatcher
|
||||
|
@ -65,7 +66,8 @@ object SelectCoverObjectModule {
|
|||
removeCover: RemoveDocCover,
|
||||
dispatcher: Dispatcher<Payload>,
|
||||
getCoverGradientCollection: GetCoverGradientCollection,
|
||||
analytics: Analytics
|
||||
analytics: Analytics,
|
||||
spaceManager: SpaceManager
|
||||
): SelectCoverObjectViewModel.Factory = SelectCoverObjectViewModel.Factory(
|
||||
setCoverImage = setCoverImage,
|
||||
setCoverColor = setCoverColor,
|
||||
|
@ -73,7 +75,8 @@ object SelectCoverObjectModule {
|
|||
removeCover = removeCover,
|
||||
dispatcher = dispatcher,
|
||||
getCoverGradientCollection = getCoverGradientCollection,
|
||||
analytics = analytics
|
||||
analytics = analytics,
|
||||
spaceManager = spaceManager
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
@ -129,7 +132,8 @@ object SelectCoverObjectSetModule {
|
|||
removeCover: RemoveDocCover,
|
||||
dispatcher: Dispatcher<Payload>,
|
||||
getCoverGradientCollection: GetCoverGradientCollection,
|
||||
analytics: Analytics
|
||||
analytics: Analytics,
|
||||
spaceManager: SpaceManager
|
||||
): SelectCoverObjectSetViewModel.Factory = SelectCoverObjectSetViewModel.Factory(
|
||||
setCoverImage = setCoverImage,
|
||||
setCoverColor = setCoverColor,
|
||||
|
@ -137,7 +141,8 @@ object SelectCoverObjectSetModule {
|
|||
removeCover = removeCover,
|
||||
dispatcher = dispatcher,
|
||||
getCoverGradientCollection = getCoverGradientCollection,
|
||||
analytics = analytics
|
||||
analytics = analytics,
|
||||
spaceManager = spaceManager
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.anytypeio.anytype.data.auth.repo.unsplash
|
|||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.UnsplashImage
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.domain.unsplash.UnsplashRepository
|
||||
|
||||
class UnsplashDataRepository(
|
||||
|
@ -15,5 +16,5 @@ class UnsplashDataRepository(
|
|||
query = query,
|
||||
limit = limit
|
||||
)
|
||||
override fun download(id: Id) : Hash = remote.download(id = id)
|
||||
override fun download(id: Id, space: SpaceId) : Hash = remote.download(id = id, space = space)
|
||||
}
|
|
@ -3,8 +3,9 @@ package com.anytypeio.anytype.data.auth.repo.unsplash
|
|||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.UnsplashImage
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
|
||||
interface UnsplashRemote {
|
||||
fun search(query: String, limit: Int) : List<UnsplashImage>
|
||||
fun download(id: Id) : Hash
|
||||
fun download(space: SpaceId, id: Id) : Hash
|
||||
}
|
|
@ -4,6 +4,7 @@ import com.anytypeio.anytype.core_models.Block
|
|||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
||||
|
||||
|
@ -17,7 +18,8 @@ class SetDocCoverImage(
|
|||
val hash = repo.uploadFile(
|
||||
command = Command.UploadFile(
|
||||
path = params.path,
|
||||
type = Block.Content.File.Type.IMAGE
|
||||
type = Block.Content.File.Type.IMAGE,
|
||||
space = params.space
|
||||
)
|
||||
)
|
||||
repo.setDocumentCoverImage(
|
||||
|
@ -36,13 +38,22 @@ class SetDocCoverImage(
|
|||
|
||||
/**
|
||||
* Params for for setting document's image cover
|
||||
* @property path image path in file system
|
||||
* @property context id of the context for this operation
|
||||
*/
|
||||
sealed class Params {
|
||||
abstract val context: String
|
||||
|
||||
data class FromPath(override val context: String, val path: String) : Params()
|
||||
data class FromHash(override val context: String, val hash: Hash) : Params()
|
||||
/**
|
||||
* @property path image path in file system
|
||||
* @property context id of the context for this operation
|
||||
* @property space target space
|
||||
*/
|
||||
data class FromPath(
|
||||
override val context: String,
|
||||
val path: String,
|
||||
val space: SpaceId
|
||||
) : Params()
|
||||
data class FromHash(
|
||||
override val context: String,
|
||||
val hash: Hash
|
||||
) : Params()
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.anytypeio.anytype.domain.unsplash
|
|||
|
||||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
|
||||
class DownloadUnsplashImage(
|
||||
|
@ -9,8 +10,11 @@ class DownloadUnsplashImage(
|
|||
) : BaseUseCase<Hash, DownloadUnsplashImage.Params>() {
|
||||
|
||||
override suspend fun run(params: Params) = safe {
|
||||
repo.download(params.picture)
|
||||
repo.download(
|
||||
id = params.picture,
|
||||
space = params.space
|
||||
)
|
||||
}
|
||||
|
||||
class Params(val picture: Id)
|
||||
class Params(val picture: Id, val space: SpaceId)
|
||||
}
|
|
@ -3,8 +3,9 @@ package com.anytypeio.anytype.domain.unsplash
|
|||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.UnsplashImage
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
|
||||
interface UnsplashRepository {
|
||||
fun search(query: String, limit: Int) : List<UnsplashImage>
|
||||
fun download(id: Id) : Hash
|
||||
fun download(id: Id, space: SpaceId) : Hash
|
||||
}
|
|
@ -5,6 +5,7 @@ import anytype.Rpc.Unsplash.Search
|
|||
import com.anytypeio.anytype.core_models.Hash
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.UnsplashImage
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.data.auth.repo.unsplash.UnsplashRemote
|
||||
import com.anytypeio.anytype.middleware.interactor.MiddlewareProtobufLogger
|
||||
import com.anytypeio.anytype.middleware.mappers.core
|
||||
|
@ -25,8 +26,10 @@ class UnsplashMiddleware @Inject constructor(
|
|||
return response.pictures.map { p -> p.core() }
|
||||
}
|
||||
|
||||
override fun download(id: Id): Hash {
|
||||
val request = Download.Request(pictureId = id).also { logger.logRequest(it) }
|
||||
override fun download(space: SpaceId, id: Id): Hash {
|
||||
val request = Download.Request(pictureId = id, spaceId = space.id).also {
|
||||
logger.logRequest(it)
|
||||
}
|
||||
val response = service.unsplashDownload(request = request).also { logger.logResponse(it) }
|
||||
return response.objectId
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import com.anytypeio.anytype.core_models.ext.sortByType
|
|||
import com.anytypeio.anytype.core_models.ext.supportNesting
|
||||
import com.anytypeio.anytype.core_models.ext.title
|
||||
import com.anytypeio.anytype.core_models.ext.updateTextContent
|
||||
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.restrictions.ObjectRestriction
|
||||
|
@ -480,7 +481,9 @@ class EditorViewModel(
|
|||
) {
|
||||
downloadUnsplashImage(
|
||||
DownloadUnsplashImage.Params(
|
||||
picture = action.img
|
||||
picture = action.img,
|
||||
// TODO re-fact to use space id from arguments or target space id of this object
|
||||
space = SpaceId(spaceManager.get())
|
||||
)
|
||||
).process(
|
||||
failure = {
|
||||
|
|
|
@ -6,11 +6,13 @@ import androidx.lifecycle.viewModelScope
|
|||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.primitives.SpaceId
|
||||
import com.anytypeio.anytype.domain.cover.GetCoverGradientCollection
|
||||
import com.anytypeio.anytype.domain.cover.RemoveDocCover
|
||||
import com.anytypeio.anytype.domain.cover.SetDocCoverColor
|
||||
import com.anytypeio.anytype.domain.cover.SetDocCoverGradient
|
||||
import com.anytypeio.anytype.domain.cover.SetDocCoverImage
|
||||
import com.anytypeio.anytype.domain.workspace.SpaceManager
|
||||
import com.anytypeio.anytype.presentation.common.BaseViewModel
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsRemoveCoverEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsSetCoverEvent
|
||||
|
@ -26,7 +28,8 @@ abstract class SelectCoverViewModel(
|
|||
private val removeCover: RemoveDocCover,
|
||||
private val dispatcher: Dispatcher<Payload>,
|
||||
private val getCoverGradientCollection: GetCoverGradientCollection,
|
||||
private val analytics: Analytics
|
||||
private val analytics: Analytics,
|
||||
private val spaceManager: SpaceManager
|
||||
) : BaseViewModel() {
|
||||
|
||||
val views = MutableStateFlow<List<DocCoverGalleryView>>(emptyList())
|
||||
|
@ -60,7 +63,9 @@ abstract class SelectCoverViewModel(
|
|||
setCoverImage(
|
||||
SetDocCoverImage.Params.FromPath(
|
||||
context = ctx,
|
||||
path = path
|
||||
path = path,
|
||||
// TODO use space provided in arguments
|
||||
space = SpaceId(spaceManager.get())
|
||||
)
|
||||
).proceed(
|
||||
failure = {
|
||||
|
@ -170,7 +175,8 @@ class SelectCoverObjectViewModel(
|
|||
private val removeCover: RemoveDocCover,
|
||||
private val dispatcher: Dispatcher<Payload>,
|
||||
private val getCoverGradientCollection: GetCoverGradientCollection,
|
||||
private val analytics: Analytics
|
||||
private val analytics: Analytics,
|
||||
private val spaceManager: SpaceManager
|
||||
) : SelectCoverViewModel(
|
||||
setCoverColor = setCoverColor,
|
||||
setCoverImage = setCoverImage,
|
||||
|
@ -178,7 +184,8 @@ class SelectCoverObjectViewModel(
|
|||
removeCover = removeCover,
|
||||
dispatcher = dispatcher,
|
||||
getCoverGradientCollection = getCoverGradientCollection,
|
||||
analytics = analytics
|
||||
analytics = analytics,
|
||||
spaceManager = spaceManager
|
||||
) {
|
||||
|
||||
class Factory(
|
||||
|
@ -188,7 +195,8 @@ class SelectCoverObjectViewModel(
|
|||
private val removeCover: RemoveDocCover,
|
||||
private val dispatcher: Dispatcher<Payload>,
|
||||
private val getCoverGradientCollection: GetCoverGradientCollection,
|
||||
private val analytics: Analytics
|
||||
private val analytics: Analytics,
|
||||
private val spaceManager: SpaceManager
|
||||
) : ViewModelProvider.Factory {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
@ -200,7 +208,8 @@ class SelectCoverObjectViewModel(
|
|||
removeCover = removeCover,
|
||||
dispatcher = dispatcher,
|
||||
getCoverGradientCollection = getCoverGradientCollection,
|
||||
analytics = analytics
|
||||
analytics = analytics,
|
||||
spaceManager = spaceManager
|
||||
) as T
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +222,8 @@ class SelectCoverObjectSetViewModel(
|
|||
private val removeCover: RemoveDocCover,
|
||||
private val dispatcher: Dispatcher<Payload>,
|
||||
private val getCoverGradientCollection: GetCoverGradientCollection,
|
||||
private val analytics: Analytics
|
||||
private val analytics: Analytics,
|
||||
private val spaceManager: SpaceManager
|
||||
) : SelectCoverViewModel(
|
||||
setCoverColor = setCoverColor,
|
||||
setCoverImage = setCoverImage,
|
||||
|
@ -221,7 +231,8 @@ class SelectCoverObjectSetViewModel(
|
|||
removeCover = removeCover,
|
||||
dispatcher = dispatcher,
|
||||
getCoverGradientCollection = getCoverGradientCollection,
|
||||
analytics = analytics
|
||||
analytics = analytics,
|
||||
spaceManager = spaceManager
|
||||
) {
|
||||
|
||||
class Factory(
|
||||
|
@ -231,7 +242,8 @@ class SelectCoverObjectSetViewModel(
|
|||
private val removeCover: RemoveDocCover,
|
||||
private val dispatcher: Dispatcher<Payload>,
|
||||
private val getCoverGradientCollection: GetCoverGradientCollection,
|
||||
private val analytics: Analytics
|
||||
private val analytics: Analytics,
|
||||
private val spaceManager: SpaceManager
|
||||
) : ViewModelProvider.Factory {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
@ -243,7 +255,8 @@ class SelectCoverObjectSetViewModel(
|
|||
removeCover = removeCover,
|
||||
dispatcher = dispatcher,
|
||||
getCoverGradientCollection = getCoverGradientCollection,
|
||||
analytics = analytics
|
||||
analytics = analytics,
|
||||
spaceManager = spaceManager
|
||||
) as T
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.anytypeio.anytype.core_models.ObjectWrapper
|
|||
import com.anytypeio.anytype.core_models.Payload
|
||||
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.primitives.TypeId
|
||||
import com.anytypeio.anytype.core_models.primitives.TypeKey
|
||||
import com.anytypeio.anytype.core_models.restrictions.DataViewRestriction
|
||||
|
@ -375,7 +376,9 @@ class ObjectSetViewModel(
|
|||
) {
|
||||
downloadUnsplashImage(
|
||||
DownloadUnsplashImage.Params(
|
||||
picture = action.img
|
||||
picture = action.img,
|
||||
// TODO re-fact to use space id from arguments or target space id of this object
|
||||
space = SpaceId(spaceManager.get())
|
||||
)
|
||||
).process(
|
||||
failure = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue