diff --git a/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockView.kt b/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockView.kt index 60e00091ed..ab0a821c79 100644 --- a/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockView.kt +++ b/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockView.kt @@ -317,16 +317,16 @@ sealed class BlockView : ViewType { * @property title website's title * @property title website's content description * @property url website's url - * @property logoUrl website's logo url - * @property logoUrl content's main image url + * @property faviconUrl website's favicon url + * @property imageUrl content's main image url */ data class Bookmark( override val id: String, - val title: String, - val description: String, val url: String, - val logoUrl: String, - val imageUrl: String + val title: String?, + val description: String?, + val faviconUrl: String?, + val imageUrl: String? ) : BlockView() { override fun getViewType() = HOLDER_BOOKMARK } diff --git a/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockViewHolder.kt b/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockViewHolder.kt index 64ddea85da..1c95aa575e 100644 --- a/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockViewHolder.kt +++ b/core-ui/src/main/java/com/agileburo/anytype/core_ui/features/page/BlockViewHolder.kt @@ -659,12 +659,49 @@ sealed class BlockViewHolder(view: View) : RecyclerView.ViewHolder(view) { private val url = itemView.bookmarkUrl private val image = itemView.bookmarkImage private val logo = itemView.bookmarkLogo + private val error = itemView.loadBookmarkPictureError + + private val listener: RequestListener = object : RequestListener { + + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target?, + isFirstResource: Boolean + ): Boolean { + error.visible() + return false + } + + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { + error.invisible() + return false + } + } fun bind(item: BlockView.Bookmark) { title.text = item.title description.text = item.description url.text = item.url - // TODO set logo icon and website's image + + item.imageUrl?.let { url -> + Glide.with(image) + .load(url) + .listener(listener) + .into(image) + } + item.faviconUrl?.let { url -> + Glide.with(logo) + .load(url) + .listener(listener) + .into(logo) + } } } diff --git a/core-ui/src/main/res/layout/item_block_bookmark.xml b/core-ui/src/main/res/layout/item_block_bookmark.xml index 592a58d939..dd6fc72f96 100644 --- a/core-ui/src/main/res/layout/item_block_bookmark.xml +++ b/core-ui/src/main/res/layout/item_block_bookmark.xml @@ -64,5 +64,17 @@ app:layout_constraintTop_toTopOf="@id/bookmarkUrl" tools:background="@color/orange" /> + + diff --git a/data/src/main/java/com/agileburo/anytype/data/auth/mapper/MapperExtension.kt b/data/src/main/java/com/agileburo/anytype/data/auth/mapper/MapperExtension.kt index ef0f2539f4..8701a77d8c 100644 --- a/data/src/main/java/com/agileburo/anytype/data/auth/mapper/MapperExtension.kt +++ b/data/src/main/java/com/agileburo/anytype/data/auth/mapper/MapperExtension.kt @@ -83,6 +83,7 @@ fun BlockEntity.Content.toDomain(): Block.Content = when (this) { is BlockEntity.Content.Divider -> toDomain() is BlockEntity.Content.File -> toDomain() is BlockEntity.Content.Icon -> toDomain() + is BlockEntity.Content.Bookmark -> toDomain() } fun BlockEntity.Content.File.toDomain(): Block.Content.File { @@ -97,6 +98,16 @@ fun BlockEntity.Content.File.toDomain(): Block.Content.File { ) } +fun BlockEntity.Content.Bookmark.toDomain(): Block.Content.Bookmark { + return Block.Content.Bookmark( + url = url, + title = title, + description = description, + image = image, + favicon = favicon + ) +} + fun BlockEntity.Content.Icon.toDomain(): Block.Content.Icon = Block.Content.Icon( name = name ) @@ -203,6 +214,7 @@ fun Block.Content.toEntity(): BlockEntity.Content = when (this) { is Block.Content.Divider -> toEntity() is Block.Content.File -> toEntity() is Block.Content.Icon -> toEntity() + is Block.Content.Bookmark -> toEntity() } fun Block.Content.File.toEntity(): BlockEntity.Content.File { @@ -217,6 +229,16 @@ fun Block.Content.File.toEntity(): BlockEntity.Content.File { ) } +fun Block.Content.Bookmark.toEntity(): BlockEntity.Content.Bookmark { + return BlockEntity.Content.Bookmark( + url = url, + title = title, + description = description, + image = image, + favicon = favicon + ) +} + fun Block.Content.Icon.toEntity(): BlockEntity.Content.Icon = BlockEntity.Content.Icon( name = name ) diff --git a/data/src/main/java/com/agileburo/anytype/data/auth/model/BlockEntity.kt b/data/src/main/java/com/agileburo/anytype/data/auth/model/BlockEntity.kt index 03a5a8436f..3655168f61 100644 --- a/data/src/main/java/com/agileburo/anytype/data/auth/model/BlockEntity.kt +++ b/data/src/main/java/com/agileburo/anytype/data/auth/model/BlockEntity.kt @@ -85,6 +85,14 @@ data class BlockEntity( enum class State { EMPTY, UPLOADING, DONE, ERROR } } + data class Bookmark( + val url: String, + val title: String?, + val description: String?, + val image: String?, + val favicon: String? + ) : Content() + object Divider : Content() } diff --git a/domain/src/main/java/com/agileburo/anytype/domain/block/model/Block.kt b/domain/src/main/java/com/agileburo/anytype/domain/block/model/Block.kt index 79fe89bba2..8b30054ff2 100644 --- a/domain/src/main/java/com/agileburo/anytype/domain/block/model/Block.kt +++ b/domain/src/main/java/com/agileburo/anytype/domain/block/model/Block.kt @@ -2,7 +2,9 @@ package com.agileburo.anytype.domain.block.model import com.agileburo.anytype.domain.block.model.Block.Content.Text.Mark import com.agileburo.anytype.domain.block.model.Block.Content.Text.Style +import com.agileburo.anytype.domain.common.Hash import com.agileburo.anytype.domain.common.Id +import com.agileburo.anytype.domain.common.Url /** * Represents block as basic data structure. @@ -169,6 +171,21 @@ data class Block( enum class State { EMPTY, UPLOADING, DONE, ERROR } } + /** + * @property url url associated with this bookmark + * @property title optional bookmark title + * @property description optional bookmark's content description + * @property image optional hash of bookmark's image + * @property favicon optional hash of bookmark's favicon + */ + data class Bookmark( + val url: Url, + val title: String?, + val description: String?, + val image: Hash?, + val favicon: Hash? + ) : Content() + object Divider : Content() } diff --git a/domain/src/main/java/com/agileburo/anytype/domain/common/Alias.kt b/domain/src/main/java/com/agileburo/anytype/domain/common/Alias.kt index aa38dfe8d5..11cb568b6a 100644 --- a/domain/src/main/java/com/agileburo/anytype/domain/common/Alias.kt +++ b/domain/src/main/java/com/agileburo/anytype/domain/common/Alias.kt @@ -1,4 +1,5 @@ package com.agileburo.anytype.domain.common typealias Id = String -typealias Url = String \ No newline at end of file +typealias Url = String +typealias Hash = String \ No newline at end of file diff --git a/domain/src/main/java/com/agileburo/anytype/domain/ext/BlockExt.kt b/domain/src/main/java/com/agileburo/anytype/domain/ext/BlockExt.kt index 2b316a5ecf..6f4ab8a540 100644 --- a/domain/src/main/java/com/agileburo/anytype/domain/ext/BlockExt.kt +++ b/domain/src/main/java/com/agileburo/anytype/domain/ext/BlockExt.kt @@ -28,6 +28,7 @@ fun Map>.asRender(anchor: String): List { is Content.Image, is Content.Link, is Content.Divider, + is Content.Bookmark, is Content.File -> { result.add(child) result.addAll(asRender(child.id)) diff --git a/library-page-icon-picker-widget/build.gradle b/library-page-icon-picker-widget/build.gradle index a823ef1084..36078c5004 100644 --- a/library-page-icon-picker-widget/build.gradle +++ b/library-page-icon-picker-widget/build.gradle @@ -28,6 +28,15 @@ android { includeAndroidResources = true } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = "1.8" + } } dependencies { diff --git a/middleware/src/main/java/com/agileburo/anytype/middleware/MapperExtension.kt b/middleware/src/main/java/com/agileburo/anytype/middleware/MapperExtension.kt index 26c86f0b0a..19d4e41525 100644 --- a/middleware/src/main/java/com/agileburo/anytype/middleware/MapperExtension.kt +++ b/middleware/src/main/java/com/agileburo/anytype/middleware/MapperExtension.kt @@ -242,6 +242,14 @@ fun Block.file(): BlockEntity.Content.File = BlockEntity.Content.File( } ) +fun Block.bookmark(): BlockEntity.Content.Bookmark = BlockEntity.Content.Bookmark( + url = bookmark.url, + description = bookmark.description.ifEmpty { null }, + title = bookmark.title.ifEmpty { null }, + image = bookmark.imageHash.ifEmpty { null }, + favicon = bookmark.faviconHash.ifEmpty { null } +) + fun List.blocks(): List = mapNotNull { block -> when (block.contentCase) { Block.ContentCase.DASHBOARD -> { @@ -308,6 +316,14 @@ fun List.blocks(): List = mapNotNull { block -> content = block.icon() ) } + Block.ContentCase.BOOKMARK -> { + BlockEntity( + id = block.id, + children = block.childrenIdsList, + fields = block.fields(), + content = block.bookmark() + ) + } else -> { null } diff --git a/presentation/src/main/java/com/agileburo/anytype/presentation/page/PageViewModel.kt b/presentation/src/main/java/com/agileburo/anytype/presentation/page/PageViewModel.kt index 99b9d82bef..9b4461f1be 100644 --- a/presentation/src/main/java/com/agileburo/anytype/presentation/page/PageViewModel.kt +++ b/presentation/src/main/java/com/agileburo/anytype/presentation/page/PageViewModel.kt @@ -301,6 +301,14 @@ class PageViewModel( is Content.Divider -> block.toView( urlBuilder = urlBuilder ) + is Content.Bookmark -> BlockView.Bookmark( + id = block.id, + url = content.url, + title = content.title, + description = content.description, + imageUrl = content.image?.let { urlBuilder.image(it) }, + faviconUrl = content.favicon?.let { urlBuilder.image(it) } + ) else -> null } }