Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DROID-3185 File as Object | New layout ui, part 1 #1947

Merged
merged 26 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bdac2ba
DROID-2898 open file block
konstantiniiv Dec 16, 2024
b782dfe
DROID-2898 file block is hidden
konstantiniiv Dec 16, 2024
5101e94
DROID-3185 Merge branch 'release/0-34-0' into droid-3185-file-layout-…
konstantiniiv Dec 20, 2024
87d99e3
DROID-3185 test
konstantiniiv Dec 20, 2024
1542d17
DROID-3185 test
konstantiniiv Dec 20, 2024
131dd17
DROID-3185 fixes
konstantiniiv Dec 20, 2024
f864410
DROID-3185 fixes
konstantiniiv Dec 20, 2024
d315c12
DROID-3185 ui
konstantiniiv Dec 21, 2024
327242e
DROID-3185 new holder
konstantiniiv Dec 21, 2024
a68c5b1
DROID-3185 legacy
konstantiniiv Dec 21, 2024
e68cc71
DROID-3185 fix
konstantiniiv Dec 21, 2024
79e63df
DROID-3185 render new file open blocks
konstantiniiv Dec 21, 2024
38804b3
DROID-3185 tests
konstantiniiv Dec 23, 2024
a979f1a
DROID-3185 tests
konstantiniiv Dec 23, 2024
90b2017
DROID-3185 file block
konstantiniiv Dec 23, 2024
0ff884a
DROID-3185 stubs
konstantiniiv Dec 23, 2024
de1cc45
DROID-3185 tests
konstantiniiv Dec 23, 2024
85e0dd5
DROID-3185 fixes
konstantiniiv Dec 23, 2024
92449f8
DROID-3185 fix open file block
konstantiniiv Dec 23, 2024
dabad8f
DROID-3185 move tests
konstantiniiv Dec 23, 2024
a86cca0
DROID-3185 ext files
konstantiniiv Dec 23, 2024
8994c3d
DROID-3185 fixes
konstantiniiv Dec 23, 2024
9f0edea
DROID-3185 fix
konstantiniiv Dec 23, 2024
2c3784c
Merge branch 'release/0-34-0' into droid-3185-file-layout-hide-file-b…
konstantiniiv Dec 23, 2024
88fbd06
DROID-3185 pr fix
konstantiniiv Dec 23, 2024
45e692e
DROID-3185 Merge branch 'droid-3185-file-layout-hide-file-block' of g…
konstantiniiv Dec 23, 2024
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 @@ -19,6 +19,7 @@ import com.anytypeio.anytype.core_models.Position
import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.StubBookmark
import com.anytypeio.anytype.core_models.StubFile
import com.anytypeio.anytype.core_ui.features.editor.slash.holders.MainMenuHolder
import com.anytypeio.anytype.core_ui.features.editor.slash.holders.MediaMenuHolder
import com.anytypeio.anytype.domain.block.interactor.CreateBlock
Expand Down Expand Up @@ -526,14 +527,9 @@ class SlashWidgetTesting : EditorTestSetup() {
val paragraph = paragraph(text = "FooBar")
val paragraph2 = paragraph(text = "Second")

val file = Block(
id = MockDataFactory.randomUuid(),
fields = Block.Fields.empty(),
children = emptyList(),
content = Block.Content.File(
type = Block.Content.File.Type.FILE,
state = Block.Content.File.State.EMPTY
)
val file = StubFile(
type = Block.Content.File.Type.FILE,
state = Block.Content.File.State.EMPTY
)

val page = Block(
Expand Down Expand Up @@ -599,14 +595,9 @@ class SlashWidgetTesting : EditorTestSetup() {
val paragraph = paragraph(text = "FooBar")
val paragraph2 = paragraph(text = "Second")

val picture = Block(
id = MockDataFactory.randomUuid(),
fields = Block.Fields.empty(),
children = emptyList(),
content = Block.Content.File(
type = Block.Content.File.Type.IMAGE,
state = Block.Content.File.State.EMPTY
)
val picture = StubFile(
type = Block.Content.File.Type.IMAGE,
state = Block.Content.File.State.EMPTY
)

val page = Block(
Expand Down Expand Up @@ -678,14 +669,9 @@ class SlashWidgetTesting : EditorTestSetup() {

val paragraph2 = paragraph(text = "Second")

val video = Block(
id = MockDataFactory.randomUuid(),
fields = Block.Fields.empty(),
children = emptyList(),
content = Block.Content.File(
type = Block.Content.File.Type.VIDEO,
state = Block.Content.File.State.EMPTY
)
val video = StubFile(
type = Block.Content.File.Type.VIDEO,
state = Block.Content.File.State.EMPTY
)

val page = Block(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.anytypeio.anytype.domain.config.ConfigStorage
import com.anytypeio.anytype.domain.config.UserSettingsRepository
import com.anytypeio.anytype.domain.debugging.DebugAccountSelectTrace
import com.anytypeio.anytype.domain.debugging.DebugGoroutines
import com.anytypeio.anytype.domain.debugging.Logger
import com.anytypeio.anytype.domain.device.PathProvider
import com.anytypeio.anytype.domain.misc.LocaleProvider
import com.anytypeio.anytype.domain.multiplayer.UserPermissionProvider
Expand Down Expand Up @@ -99,4 +100,5 @@ interface OnboardingMnemonicLoginDependencies : ComponentDependencies {
fun spaceManager(): SpaceManager
fun globalSubscriptionManager(): GlobalSubscriptionManager
fun debugAccountSelectTrace(): DebugAccountSelectTrace
fun logger(): Logger
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate
import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider
import com.anytypeio.anytype.presentation.spaces.SpaceSettingsViewModel
import com.anytypeio.anytype.presentation.util.downloader.UriFileProvider
import com.anytypeio.anytype.providers.DefaultUriFileProvider
import com.anytypeio.anytype.ui.settings.space.SpaceSettingsFragment
import dagger.Binds
import dagger.BindsInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ object DataModule {
@Provides
@Singleton
fun provideFileProvider(
context: Context
): UriFileProvider = DefaultUriFileProvider(context)
context: Context,
logger: Logger
): UriFileProvider = DefaultUriFileProvider(context, logger)

@JvmStatic
@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ import android.content.Context
import android.net.Uri
import androidx.core.content.FileProvider
import com.anytypeio.anytype.BuildConfig
import com.anytypeio.anytype.domain.debugging.Logger
import com.anytypeio.anytype.presentation.util.downloader.UriFileProvider
import java.io.File
import javax.inject.Inject

class DefaultUriFileProvider @Inject constructor(
private val context: Context
private val context: Context,
private val logger: Logger
) : UriFileProvider {

override fun getUriForFile(file: File): Uri = FileProvider.getUriForFile(
context,
BuildConfig.APPLICATION_ID + PROVIDER,
file
)
override fun getUriForFile(file: File): Uri {
logger.logInfo("DefaultUriFileProvider, start getting uri for file $file")
val contentUri = FileProvider.getUriForFile(
context,
BuildConfig.APPLICATION_ID + PROVIDER,
file
)
logger.logInfo("DefaultUriFileProvider, got uri $contentUri")
return contentUri
}
}

private const val PROVIDER = ".provider"
2 changes: 1 addition & 1 deletion app/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="." path="/" />
<files-path name="." path="/" />
<files-path name="file_path" path="/" />
</paths>
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ data class Block(

fun asText() = this as Text
fun asLink() = this as Link
fun asFile() = this as File

/**
* Smart block.
Expand Down Expand Up @@ -227,12 +228,13 @@ data class Block(
* @property state file state
*/
data class File(
val targetObjectId: Id? = null,
val name: String? = null,
val mime: String? = null,
val size: Long? = null,
val type: Type? = null,
val state: State? = null
val targetObjectId: Id,
val name: String,
val mime: String,
val size: Long,
val type: Type,
val state: State,
val addedAt: Long
) : Content() {
enum class Type { NONE, FILE, IMAGE, VIDEO, AUDIO, PDF }
enum class State { EMPTY, UPLOADING, DONE, ERROR }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ object SupportedLayouts {
fun isEditorOrFileLayout(layout: ObjectType.Layout?) : Boolean {
return editorLayouts.contains(layout) || fileLayouts.contains(layout)
}

fun isFileLayout(layout: ObjectType.Layout?) : Boolean {
return fileLayouts.contains(layout)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.anytypeio.anytype.core_ui.databinding.ItemBlockObjectLinkCardSmallIco
import com.anytypeio.anytype.core_ui.databinding.ItemBlockObjectLinkCardSmallIconCoverBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockObjectLinkDeleteBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockObjectLinkLoadingBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockOpenFileBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockPictureBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockRelationCheckboxBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockRelationDefaultBinding
Expand All @@ -55,6 +56,7 @@ import com.anytypeio.anytype.core_ui.databinding.ItemBlockRelationTagBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTableBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTextBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleFileBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleProfileBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleTodoBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTocBinding
Expand Down Expand Up @@ -113,6 +115,8 @@ import com.anytypeio.anytype.core_ui.features.editor.holders.text.Text
import com.anytypeio.anytype.core_ui.features.editor.holders.text.Toggle
import com.anytypeio.anytype.core_ui.features.editor.holders.upload.BookmarkUpload
import com.anytypeio.anytype.core_ui.features.editor.holders.upload.FileUpload
import com.anytypeio.anytype.core_ui.features.editor.holders.upload.OpenFile
import com.anytypeio.anytype.core_ui.features.editor.holders.upload.OpenImage
import com.anytypeio.anytype.core_ui.features.editor.holders.upload.PictureUpload
import com.anytypeio.anytype.core_ui.features.editor.holders.upload.VideoUpload
import com.anytypeio.anytype.core_ui.features.table.holders.TableBlockHolder
Expand Down Expand Up @@ -148,6 +152,7 @@ import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_FILE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_FILE_ERROR
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_FILE_PLACEHOLDER
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_FILE_TITLE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_FILE_UPLOAD
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_HEADER_ONE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_HEADER_THREE
Expand All @@ -163,6 +168,8 @@ import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_OBJECT_LINK_DEFAULT
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_OBJECT_LINK_DELETED
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_OBJECT_LINK_LOADING
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_BUTTON_OPEN_FILE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_BUTTON_OPEN_IMAGE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_PARAGRAPH
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_PICTURE
import com.anytypeio.anytype.presentation.editor.editor.model.types.Types.HOLDER_PICTURE_ERROR
Expand Down Expand Up @@ -358,6 +365,11 @@ class BlockAdapter(
}
}
}
HOLDER_FILE_TITLE -> {
Title.File(
ItemBlockTitleFileBinding.inflate(inflater, parent, false)
)
}
HOLDER_TODO_TITLE -> {
Title.Todo(
ItemBlockTitleTodoBinding.inflate(inflater, parent, false)
Expand Down Expand Up @@ -530,6 +542,12 @@ class BlockAdapter(
ItemBlockMediaErrorBinding.inflate(inflater, parent, false)
)
}
HOLDER_BUTTON_OPEN_FILE -> {
OpenFile(ItemBlockOpenFileBinding.inflate(inflater, parent, false))
}
HOLDER_BUTTON_OPEN_IMAGE -> {
OpenImage(ItemBlockOpenFileBinding.inflate(inflater, parent, false))
}
HOLDER_VIDEO -> {
Video(
ItemBlockVideoBinding.inflate(inflater, parent, false)
Expand Down Expand Up @@ -1002,6 +1020,12 @@ class BlockAdapter(
item = blocks[position] as BlockView.Title.Todo
)
}
is Title.File -> {
holder.processPayloads(
payloads = payloads.typeOf(),
item = blocks[position] as BlockView.Title.File
)
}
is Numbered -> {
holder.processChangePayload(
payloads = payloads.typeOf(),
Expand Down Expand Up @@ -1361,6 +1385,11 @@ class BlockAdapter(
holder.content.clipboardInterceptor = clipboardInterceptor
}
}
is Title.File -> {
holder.apply {
bind(item = blocks[position] as BlockView.Title.File,)
}
}
is Code -> {
holder.bind(
item = blocks[position] as BlockView.Code,
Expand Down Expand Up @@ -1622,6 +1651,18 @@ class BlockAdapter(
clicked = onClickListener
)
}
is OpenFile -> {
holder.bind(
item = blocks[position] as BlockView.ButtonOpenFile.FileButton,
click = onClickListener
)
}
is OpenImage -> {
holder.bind(
item = blocks[position] as BlockView.ButtonOpenFile.ImageButton,
click = onClickListener
)
}
}

if (holder is Text<*>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package com.anytypeio.anytype.core_ui.features.editor.holders.other
import android.text.Spannable
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout.LayoutParams
import android.widget.ImageView
import android.widget.TextView
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.postDelayed
import androidx.core.view.updateLayoutParams
Expand All @@ -16,14 +15,15 @@ import com.anytypeio.anytype.core_ui.R
import com.anytypeio.anytype.core_ui.common.SearchHighlightSpan
import com.anytypeio.anytype.core_ui.common.SearchTargetHighlightSpan
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleFileBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleProfileBinding
import com.anytypeio.anytype.core_ui.databinding.ItemBlockTitleTodoBinding
import com.anytypeio.anytype.core_ui.extensions.setBlockBackgroundColor
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil
import com.anytypeio.anytype.core_ui.features.editor.BlockViewHolder
import com.anytypeio.anytype.core_ui.features.editor.holders.`interface`.TextHolder
import com.anytypeio.anytype.core_ui.tools.DefaultSpannableFactory
import com.anytypeio.anytype.core_ui.widgets.RadialGradientComposeView
import com.anytypeio.anytype.core_ui.widgets.ObjectIconWidget
import com.anytypeio.anytype.core_ui.widgets.text.TextInputWidget
import com.anytypeio.anytype.core_utils.ext.dimen
import com.anytypeio.anytype.core_utils.ext.gone
Expand Down Expand Up @@ -555,4 +555,37 @@ sealed class Title(view: View) : BlockViewHolder(view), TextHolder {
content.setBlockBackgroundColor(item.background)
}
}

class File(val binding: ItemBlockTitleFileBinding) : Title(binding.root) {

override val icon: ObjectIconWidget = binding.objectIconWidget
override val image: ImageView = binding.cover
override val selectionView: View = itemView
override val root: View = itemView
override val content: TextInputWidget = binding.title

init {
icon.binding.ivImage.updateLayoutParams<LayoutParams> {
height = itemView.resources.getDimension(R.dimen.dp_80).toInt()
width = itemView.resources.getDimension(R.dimen.dp_64).toInt()
}
}

fun bind(
item: BlockView.Title.File,
) {
super.bind(
item = item,
onCoverClicked = {}
)
icon.setIcon(item.icon)
}

override fun applyTextColor(item: BlockView.Title) {
//do nothing
}
override fun applyBackground(item: BlockView.Title) {
//do nothing
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.anytypeio.anytype.core_ui.features.editor.holders.upload

import android.view.View
import com.anytypeio.anytype.core_ui.databinding.ItemBlockOpenFileBinding
import com.anytypeio.anytype.core_ui.features.editor.BlockViewHolder
import com.anytypeio.anytype.presentation.editor.editor.listener.ListenerType
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView

class OpenFile(
binding: ItemBlockOpenFileBinding
) : BlockViewHolder(binding.root) {

private val root: View = itemView

fun bind(item: BlockView.ButtonOpenFile.FileButton, click: (ListenerType) -> Unit) {
root.setOnClickListener {
click(
ListenerType.File.View(
target = item.id,
)
)
}
}
}

class OpenImage(
binding: ItemBlockOpenFileBinding
) : BlockViewHolder(binding.root) {

private val root: View = itemView

fun bind(item: BlockView.ButtonOpenFile.ImageButton, click: (ListenerType) -> Unit) {
root.setOnClickListener {
click(
ListenerType.Picture.View(
target = item.id
)
)
}
}
}
Loading
Loading