mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
Sets | Enhancement | Add "Hide icon" icon option to GridView (#2404)
This commit is contained in:
parent
0be0079f05
commit
204076de57
21 changed files with 148 additions and 116 deletions
|
@ -43,6 +43,7 @@ import com.anytypeio.anytype.di.feature.ObjectSetIconPickerModule
|
|||
import com.anytypeio.anytype.di.feature.ObjectSetMenuModule
|
||||
import com.anytypeio.anytype.di.feature.ObjectSetModule
|
||||
import com.anytypeio.anytype.di.feature.ObjectSetRecordModule
|
||||
import com.anytypeio.anytype.di.feature.ObjectSetSettingsModule
|
||||
import com.anytypeio.anytype.di.feature.ObjectTypeChangeModule
|
||||
import com.anytypeio.anytype.di.feature.OtherSettingsModule
|
||||
import com.anytypeio.anytype.di.feature.PageNavigationModule
|
||||
|
@ -59,7 +60,6 @@ import com.anytypeio.anytype.di.feature.StartLoginModule
|
|||
import com.anytypeio.anytype.di.feature.TextBlockIconPickerModule
|
||||
import com.anytypeio.anytype.di.feature.ViewerCustomizeModule
|
||||
import com.anytypeio.anytype.di.feature.ViewerFilterModule
|
||||
import com.anytypeio.anytype.di.feature.ViewerRelationsModule
|
||||
import com.anytypeio.anytype.di.feature.ViewerSortByModule
|
||||
import com.anytypeio.anytype.di.feature.ViewerSortModule
|
||||
import com.anytypeio.anytype.di.feature.auth.DeletedAccountModule
|
||||
|
@ -515,11 +515,11 @@ class ComponentManager(
|
|||
.build()
|
||||
}
|
||||
|
||||
val viewerRelationsComponent = DependentComponentMap { ctx ->
|
||||
val objectsSetSettingsComponent = DependentComponentMap { ctx ->
|
||||
objectSetComponent
|
||||
.get(ctx)
|
||||
.viewerRelationsComponent()
|
||||
.module(ViewerRelationsModule)
|
||||
.objectSetSettingsComponent()
|
||||
.module(ObjectSetSettingsModule)
|
||||
.build()
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import com.anytypeio.anytype.domain.launch.GetDefaultEditorType
|
|||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.objects.SetObjectIsArchived
|
||||
import com.anytypeio.anytype.domain.page.CloseBlock
|
||||
import com.anytypeio.anytype.domain.page.CreateNewObject
|
||||
import com.anytypeio.anytype.domain.page.CreatePage
|
||||
import com.anytypeio.anytype.domain.relations.AddFileToRecord
|
||||
import com.anytypeio.anytype.domain.relations.DeleteRelationFromDataView
|
||||
|
@ -45,7 +46,6 @@ import com.anytypeio.anytype.domain.unsplash.DownloadUnsplashImage
|
|||
import com.anytypeio.anytype.domain.unsplash.UnsplashRepository
|
||||
import com.anytypeio.anytype.presentation.common.Action
|
||||
import com.anytypeio.anytype.presentation.common.Delegator
|
||||
import com.anytypeio.anytype.domain.page.CreateNewObject
|
||||
import com.anytypeio.anytype.presentation.relations.providers.DataViewObjectRelationProvider
|
||||
import com.anytypeio.anytype.presentation.relations.providers.DataViewObjectValueProvider
|
||||
import com.anytypeio.anytype.presentation.relations.providers.ObjectDetailProvider
|
||||
|
@ -85,7 +85,7 @@ interface ObjectSetSubComponent {
|
|||
fun editDataViewViewerComponent(): EditDataViewViewerSubComponent.Builder
|
||||
fun objectRelationValueComponent(): ObjectSetObjectRelationValueSubComponent.Builder
|
||||
fun manageViewerComponent(): ManageViewerSubComponent.Builder
|
||||
fun viewerRelationsComponent(): ViewerRelationsSubComponent.Builder
|
||||
fun objectSetSettingsComponent(): ObjectSetSettingsSubComponent.Builder
|
||||
fun viewerCardSizeSelectComponent(): ViewerCardSizeSelectSubcomponent.Builder
|
||||
fun viewerImagePreviewSelectComponent(): ViewerImagePreviewSelectSubcomponent.Builder
|
||||
fun relationAddToDataViewComponent() : RelationAddToDataViewSubComponent.Builder
|
||||
|
|
|
@ -7,35 +7,35 @@ import com.anytypeio.anytype.domain.block.repo.BlockRepository
|
|||
import com.anytypeio.anytype.domain.dataview.interactor.ModifyDataViewViewerRelationOrder
|
||||
import com.anytypeio.anytype.domain.dataview.interactor.UpdateDataViewViewer
|
||||
import com.anytypeio.anytype.domain.relations.DeleteRelationFromDataView
|
||||
import com.anytypeio.anytype.presentation.relations.ViewerRelationsViewModel
|
||||
import com.anytypeio.anytype.presentation.relations.ObjectSetSettingsViewModel
|
||||
import com.anytypeio.anytype.presentation.sets.ObjectSet
|
||||
import com.anytypeio.anytype.presentation.sets.ObjectSetSession
|
||||
import com.anytypeio.anytype.presentation.util.Dispatcher
|
||||
import com.anytypeio.anytype.ui.sets.modals.ViewerRelationsFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.ObjectSetSettingsFragment
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.Subcomponent
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
@Subcomponent(modules = [ViewerRelationsModule::class])
|
||||
@Subcomponent(modules = [ObjectSetSettingsModule::class])
|
||||
@PerModal
|
||||
interface ViewerRelationsSubComponent {
|
||||
interface ObjectSetSettingsSubComponent {
|
||||
@Subcomponent.Builder
|
||||
interface Builder {
|
||||
fun module(module: ViewerRelationsModule): Builder
|
||||
fun build(): ViewerRelationsSubComponent
|
||||
fun module(module: ObjectSetSettingsModule): Builder
|
||||
fun build(): ObjectSetSettingsSubComponent
|
||||
}
|
||||
|
||||
fun inject(fragment: ViewerRelationsFragment)
|
||||
fun inject(fragment: ObjectSetSettingsFragment)
|
||||
}
|
||||
|
||||
@Module
|
||||
object ViewerRelationsModule {
|
||||
object ObjectSetSettingsModule {
|
||||
|
||||
@JvmStatic
|
||||
@Provides
|
||||
@PerModal
|
||||
fun provideViewerRelationsListViewModelFactory(
|
||||
fun provideViewModelFactory(
|
||||
state: StateFlow<ObjectSet>,
|
||||
session: ObjectSetSession,
|
||||
dispatcher: Dispatcher<Payload>,
|
||||
|
@ -43,7 +43,7 @@ object ViewerRelationsModule {
|
|||
updateDataViewViewer: UpdateDataViewViewer,
|
||||
deleteRelationFromDataView: DeleteRelationFromDataView,
|
||||
analytics: Analytics
|
||||
): ViewerRelationsViewModel.Factory = ViewerRelationsViewModel.Factory(
|
||||
): ObjectSetSettingsViewModel.Factory = ObjectSetSettingsViewModel.Factory(
|
||||
state = state,
|
||||
session = session,
|
||||
dispatcher = dispatcher,
|
|
@ -76,8 +76,8 @@ import com.anytypeio.anytype.ui.relations.RelationValueBaseFragment
|
|||
import com.anytypeio.anytype.ui.sets.modals.CreateDataViewViewerFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.EditDataViewViewerFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.ManageViewerFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.ObjectSetSettingsFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.ViewerBottomSheetRootFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.ViewerRelationsFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.sort.ViewerSortFragment
|
||||
import com.bumptech.glide.Glide
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
|
@ -170,7 +170,7 @@ open class ObjectSetFragment :
|
|||
|
||||
setupWindowInsetAnimation()
|
||||
|
||||
setupGridAdapters(view)
|
||||
setupGridAdapters()
|
||||
title.clearFocus()
|
||||
topToolbarTitle.alpha = 0f
|
||||
binding.root.setTransitionListener(transitionListener)
|
||||
|
@ -193,9 +193,9 @@ open class ObjectSetFragment :
|
|||
vm.onViewerFiltersClicked()
|
||||
}
|
||||
subscribe(
|
||||
binding.bottomPanel.root.findViewById<FrameLayout>(R.id.btnRelations).clicks()
|
||||
binding.bottomPanel.root.findViewById<FrameLayout>(R.id.btnSettings).clicks()
|
||||
) {
|
||||
vm.onViewerRelationsClicked()
|
||||
vm.onViewerSettingsClicked()
|
||||
}
|
||||
subscribe(binding.bottomPanel.root.findViewById<FrameLayout>(R.id.btnSort).clicks()) {
|
||||
vm.onViewerSortsClicked()
|
||||
|
@ -249,7 +249,7 @@ open class ObjectSetFragment :
|
|||
}
|
||||
}
|
||||
|
||||
private fun setupGridAdapters(view: View) {
|
||||
private fun setupGridAdapters() {
|
||||
|
||||
val horizontalDivider = drawable(R.drawable.divider_dv_horizontal)
|
||||
val verticalDivider = drawable(R.drawable.divider_dv_grid)
|
||||
|
@ -589,8 +589,8 @@ open class ObjectSetFragment :
|
|||
val fr = ManageViewerFragment.new(ctx = command.ctx, dataview = command.dataview)
|
||||
fr.show(childFragmentManager, EMPTY_TAG)
|
||||
}
|
||||
is ObjectSetCommand.Modal.ModifyViewerRelationOrder -> {
|
||||
val fr = ViewerRelationsFragment.new(
|
||||
is ObjectSetCommand.Modal.OpenSettings -> {
|
||||
val fr = ObjectSetSettingsFragment.new(
|
||||
ctx = command.ctx,
|
||||
dv = command.dv,
|
||||
viewer = command.viewer
|
||||
|
|
|
@ -19,24 +19,27 @@ import com.anytypeio.anytype.core_ui.features.dataview.ViewerRelationsAdapter
|
|||
import com.anytypeio.anytype.core_ui.layout.DividerVerticalItemDecoration
|
||||
import com.anytypeio.anytype.core_ui.reactive.clicks
|
||||
import com.anytypeio.anytype.core_ui.tools.DefaultDragAndDropBehavior
|
||||
import com.anytypeio.anytype.core_utils.ext.*
|
||||
import com.anytypeio.anytype.core_utils.ext.arg
|
||||
import com.anytypeio.anytype.core_utils.ext.invisible
|
||||
import com.anytypeio.anytype.core_utils.ext.subscribe
|
||||
import com.anytypeio.anytype.core_utils.ext.toast
|
||||
import com.anytypeio.anytype.core_utils.ext.visible
|
||||
import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetFragment
|
||||
import com.anytypeio.anytype.core_utils.ui.OnStartDragListener
|
||||
import com.anytypeio.anytype.databinding.FragmentViewerRelationsListBinding
|
||||
import com.anytypeio.anytype.di.common.componentManager
|
||||
import com.anytypeio.anytype.presentation.relations.ViewerRelationsViewModel
|
||||
import com.anytypeio.anytype.presentation.sets.model.SimpleRelationView
|
||||
import com.anytypeio.anytype.presentation.relations.ObjectSetSettingsViewModel
|
||||
import com.anytypeio.anytype.ui.relations.RelationAddToDataViewFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.viewer.ViewerCardSizeSelectFragment
|
||||
import com.anytypeio.anytype.ui.sets.modals.viewer.ViewerImagePreviewSelectFragment
|
||||
import javax.inject.Inject
|
||||
|
||||
class ViewerRelationsFragment : BaseBottomSheetFragment<FragmentViewerRelationsListBinding>(),
|
||||
class ObjectSetSettingsFragment : BaseBottomSheetFragment<FragmentViewerRelationsListBinding>(),
|
||||
OnStartDragListener {
|
||||
|
||||
@Inject
|
||||
lateinit var factory: ViewerRelationsViewModel.Factory
|
||||
private val vm: ViewerRelationsViewModel by viewModels { factory }
|
||||
lateinit var factory: ObjectSetSettingsViewModel.Factory
|
||||
private val vm: ObjectSetSettingsViewModel by viewModels { factory }
|
||||
|
||||
private val ctx get() = arg<String>(CTX_KEY)
|
||||
private val viewer get() = arg<String>(VIEWER_KEY)
|
||||
|
@ -151,9 +154,9 @@ class ViewerRelationsFragment : BaseBottomSheetFragment<FragmentViewerRelationsL
|
|||
}
|
||||
}
|
||||
|
||||
private fun render(state: ViewerRelationsViewModel.ScreenState) {
|
||||
private fun render(state: ObjectSetSettingsViewModel.ScreenState) {
|
||||
when (state) {
|
||||
ViewerRelationsViewModel.ScreenState.LIST -> {
|
||||
ObjectSetSettingsViewModel.ScreenState.LIST -> {
|
||||
with(binding) {
|
||||
recycler.apply {
|
||||
dndItemTouchHelper.attachToRecyclerView(null)
|
||||
|
@ -168,7 +171,7 @@ class ViewerRelationsFragment : BaseBottomSheetFragment<FragmentViewerRelationsL
|
|||
}
|
||||
}
|
||||
}
|
||||
ViewerRelationsViewModel.ScreenState.EDIT -> {
|
||||
ObjectSetSettingsViewModel.ScreenState.EDIT -> {
|
||||
with(binding) {
|
||||
recycler.apply {
|
||||
dndItemTouchHelper.attachToRecyclerView(this)
|
||||
|
@ -186,26 +189,16 @@ class ViewerRelationsFragment : BaseBottomSheetFragment<FragmentViewerRelationsL
|
|||
}
|
||||
}
|
||||
|
||||
private fun navigateToOptions(item: SimpleRelationView) {
|
||||
val dialog = ViewerRelationOptionFragment.new(
|
||||
ctx = ctx,
|
||||
relation = item.key,
|
||||
title = item.title,
|
||||
format = item.format
|
||||
)
|
||||
dialog.show(parentFragmentManager, null)
|
||||
}
|
||||
|
||||
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
|
||||
dndItemTouchHelper.startDrag(viewHolder)
|
||||
}
|
||||
|
||||
override fun injectDependencies() {
|
||||
componentManager().viewerRelationsComponent.get(ctx).inject(this)
|
||||
componentManager().objectsSetSettingsComponent.get(ctx).inject(this)
|
||||
}
|
||||
|
||||
override fun releaseDependencies() {
|
||||
componentManager().viewerRelationsComponent.release(ctx)
|
||||
componentManager().objectsSetSettingsComponent.release(ctx)
|
||||
}
|
||||
|
||||
override fun inflateBinding(
|
||||
|
@ -216,7 +209,7 @@ class ViewerRelationsFragment : BaseBottomSheetFragment<FragmentViewerRelationsL
|
|||
)
|
||||
|
||||
companion object {
|
||||
fun new(ctx: Id, dv: Id, viewer: Id) = ViewerRelationsFragment().apply {
|
||||
fun new(ctx: Id, dv: Id, viewer: Id) = ObjectSetSettingsFragment().apply {
|
||||
arguments = bundleOf(CTX_KEY to ctx, DV_KEY to dv, VIEWER_KEY to viewer)
|
||||
}
|
||||
|
|
@ -289,7 +289,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/archiveContainer">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRelations"
|
||||
android:id="@+id/tvSettings"
|
||||
style="@style/DocMenuOptionTextStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -118,7 +118,7 @@ class ViewerGridAdapter(
|
|||
binding.objectIcon.setCheckbox(row.isChecked)
|
||||
}
|
||||
ObjectType.Layout.BASIC -> {
|
||||
if (row.image != null || row.emoji != null) {
|
||||
if ((row.image != null || row.emoji != null) && row.showIcon) {
|
||||
binding.objectIcon.visible()
|
||||
if (row.image != null) {
|
||||
binding.objectIcon.setRectangularImage(row.image)
|
||||
|
@ -130,15 +130,23 @@ class ViewerGridAdapter(
|
|||
}
|
||||
}
|
||||
ObjectType.Layout.PROFILE -> {
|
||||
binding.objectIcon.visible()
|
||||
if (row.image != null) {
|
||||
binding.objectIcon.setCircularImage(row.image)
|
||||
if (row.showIcon) {
|
||||
binding.objectIcon.visible()
|
||||
if (row.image != null) {
|
||||
binding.objectIcon.setCircularImage(row.image)
|
||||
} else {
|
||||
binding.objectIcon.setProfileInitials(row.name.orEmpty())
|
||||
}
|
||||
} else {
|
||||
binding.objectIcon.setProfileInitials(row.name.orEmpty())
|
||||
binding.objectIcon.gone()
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
binding.objectIcon.gone()
|
||||
if (row.showIcon) {
|
||||
binding.objectIcon.visible()
|
||||
} else {
|
||||
binding.objectIcon.gone()
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.tvTitle.text = row.name
|
||||
|
@ -163,10 +171,12 @@ class ViewerGridAdapter(
|
|||
override fun getChangePayload(
|
||||
oldItem: Viewer.GridView.Row,
|
||||
newItem: Viewer.GridView.Row
|
||||
): Any {
|
||||
): List<Int>? {
|
||||
val payload = mutableListOf<Int>()
|
||||
if (isHeaderChanged(oldItem, newItem)) payload.add(OBJECT_HEADER_CHANGED)
|
||||
return payload
|
||||
return if (payload.isEmpty()) {
|
||||
null
|
||||
} else payload
|
||||
}
|
||||
|
||||
private fun isHeaderChanged(
|
||||
|
@ -176,7 +186,8 @@ class ViewerGridAdapter(
|
|||
|| oldItem.image != newItem.image
|
||||
|| oldItem.name != newItem.name
|
||||
|| oldItem.isChecked != newItem.isChecked
|
||||
|| oldItem.layout != newItem.layout)
|
||||
|| oldItem.layout != newItem.layout
|
||||
|| oldItem.showIcon != newItem.showIcon)
|
||||
|
||||
const val OBJECT_HEADER_CHANGED = 0
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import androidx.recyclerview.widget.DiffUtil
|
|||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.anytypeio.anytype.core_ui.databinding.ItemGridColumnHeaderBinding
|
||||
import com.anytypeio.anytype.core_ui.databinding.ItemGridColumnHeaderPlusBinding
|
||||
import com.anytypeio.anytype.presentation.sets.model.ColumnView
|
||||
|
||||
class ViewerGridHeaderAdapter() :
|
||||
|
@ -24,15 +23,6 @@ class ViewerGridHeaderAdapter() :
|
|||
override fun onBindViewHolder(holder: HeaderViewHolder, position: Int) {
|
||||
if (holder is HeaderViewHolder.DefaultHolder) holder.bind(getItem(position))
|
||||
}
|
||||
|
||||
// override fun getItemViewType(position: Int) = if (position == super.getItemCount()) {
|
||||
// PLUS_TYPE
|
||||
// } else {
|
||||
// HEADER_TYPE
|
||||
// }
|
||||
|
||||
// override fun getItemCount(): Int = if (super.getItemCount() == 0) 0 else super.getItemCount() + 1
|
||||
|
||||
sealed class HeaderViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
class DefaultHolder(val binding: ItemGridColumnHeaderBinding) : HeaderViewHolder(binding.root) {
|
||||
fun bind(item: ColumnView) {
|
||||
|
@ -51,20 +41,6 @@ class ViewerGridHeaderAdapter() :
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
class PlusHolder(val binding: ItemGridColumnHeaderPlusBinding) : HeaderViewHolder(binding.root) {
|
||||
companion object {
|
||||
fun create(
|
||||
parent: ViewGroup
|
||||
): PlusHolder = PlusHolder(
|
||||
ItemGridColumnHeaderPlusBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object ColumnHeaderDiffCallback : DiffUtil.ItemCallback<ColumnView>() {
|
||||
|
@ -81,6 +57,5 @@ class ViewerGridHeaderAdapter() :
|
|||
|
||||
companion object {
|
||||
const val HEADER_TYPE = 0
|
||||
const val PLUS_TYPE = 1
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@
|
|||
android:layout_height="52dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="@drawable/rect_data_view_customize_view_button"
|
||||
app:layout_constraintEnd_toStartOf="@+id/btnRelations"
|
||||
app:layout_constraintEnd_toStartOf="@+id/btnSettings"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dragger">
|
||||
|
@ -62,7 +62,7 @@
|
|||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/btnRelations"
|
||||
android:id="@+id/btnSettings"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:layout_marginTop="12dp"
|
||||
|
@ -88,7 +88,7 @@
|
|||
android:background="@drawable/rect_data_view_customize_view_button"
|
||||
app:layout_constraintEnd_toStartOf="@+id/btnFilter"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/btnRelations"
|
||||
app:layout_constraintStart_toEndOf="@+id/btnSettings"
|
||||
app:layout_constraintTop_toBottomOf="@+id/dragger">
|
||||
|
||||
<ImageView
|
||||
|
@ -132,7 +132,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/btnView" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvRelations"
|
||||
android:id="@+id/tvSettings"
|
||||
style="@style/DataViewCustomizePanelTextStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -140,9 +140,9 @@
|
|||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/settings"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/btnRelations"
|
||||
app:layout_constraintStart_toStartOf="@+id/btnRelations"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnRelations" />
|
||||
app:layout_constraintEnd_toEndOf="@+id/btnSettings"
|
||||
app:layout_constraintStart_toStartOf="@+id/btnSettings"
|
||||
app:layout_constraintTop_toBottomOf="@+id/btnSettings" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSort"
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.anytypeio.anytype.core_ui.features.dataview
|
||||
|
||||
import com.anytypeio.anytype.presentation.sets.model.Viewer
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertContains
|
||||
import kotlin.test.assertIs
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class GridDiffUtilTest {
|
||||
|
||||
@Test
|
||||
fun `showIcon changed - header payload exists`() {
|
||||
val old = Viewer.GridView.Row(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
showIcon = false
|
||||
)
|
||||
val new = old.copy(
|
||||
showIcon = true
|
||||
)
|
||||
val payload = ViewerGridAdapter.GridDiffUtil.getChangePayload(
|
||||
old, new
|
||||
)
|
||||
val payloadCasted = assertIs<List<Int>>(payload)
|
||||
|
||||
assertContains(payloadCasted, ViewerGridAdapter.GridDiffUtil.OBJECT_HEADER_CHANGED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `nothing changed - payloads is empty`() {
|
||||
val old = Viewer.GridView.Row(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
showIcon = false
|
||||
)
|
||||
val new = old.copy()
|
||||
val payload = ViewerGridAdapter.GridDiffUtil.getChangePayload(
|
||||
old, new
|
||||
)
|
||||
assertNull(payload)
|
||||
}
|
||||
}
|
|
@ -612,24 +612,21 @@ fun Viewer.Filter.Condition.toDomain(): DVFilterCondition = when (this) {
|
|||
is Viewer.Filter.Condition.Text.None -> DVFilterCondition.NONE
|
||||
}
|
||||
|
||||
fun List<Map<String, Any?>>.filterRecordsBy(filterBy: String): List<Map<String, Any?>> =
|
||||
filter { it.containsKey(filterBy) }
|
||||
|
||||
fun List<Map<String, Any?>>.toGridRecordRows(
|
||||
showIcon: Boolean,
|
||||
columns: List<ColumnView>,
|
||||
relations: List<Relation>,
|
||||
types: List<ObjectType>,
|
||||
details: Map<Id, Block.Fields>,
|
||||
builder: UrlBuilder
|
||||
): List<Viewer.GridView.Row> {
|
||||
val rows = mutableListOf<Viewer.GridView.Row>()
|
||||
forEach { record ->
|
||||
val row = columns.buildGridRow(
|
||||
showIcon = showIcon,
|
||||
record = record,
|
||||
relations = relations,
|
||||
details = details,
|
||||
builder = builder,
|
||||
objectTypes = types
|
||||
)
|
||||
rows.add(row)
|
||||
}
|
||||
|
|
|
@ -130,11 +130,11 @@ fun ObjectSet.render(
|
|||
viewerDb[viewer.id]?.let { data ->
|
||||
rows.addAll(
|
||||
data.records.toGridRecordRows(
|
||||
showIcon = !viewer.hideIcon,
|
||||
columns = columns,
|
||||
relations = relations,
|
||||
details = details,
|
||||
builder = builder,
|
||||
types = objectTypes
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,14 +4,17 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.*
|
||||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.DV
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.ext.content
|
||||
import com.anytypeio.anytype.domain.dataview.interactor.ModifyDataViewViewerRelationOrder
|
||||
import com.anytypeio.anytype.domain.dataview.interactor.UpdateDataViewViewer
|
||||
import com.anytypeio.anytype.domain.relations.DeleteRelationFromDataView
|
||||
import com.anytypeio.anytype.presentation.common.BaseListViewModel
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsRelationDeleteEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendAnalyticsRelationValueEvent
|
||||
import com.anytypeio.anytype.presentation.sets.ObjectSet
|
||||
import com.anytypeio.anytype.presentation.sets.ObjectSetSession
|
||||
import com.anytypeio.anytype.presentation.sets.filterHiddenRelations
|
||||
|
@ -21,12 +24,11 @@ import com.anytypeio.anytype.presentation.sets.viewerById
|
|||
import com.anytypeio.anytype.presentation.util.Dispatcher
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
class ViewerRelationsViewModel(
|
||||
class ObjectSetSettingsViewModel(
|
||||
private val objectSetState: StateFlow<ObjectSet>,
|
||||
private val session: ObjectSetSession,
|
||||
private val dispatcher: Dispatcher<Payload>,
|
||||
|
@ -83,7 +85,8 @@ class ViewerRelationsViewModel(
|
|||
result.add(ViewerRelationListView.Setting.Toggle.FitImage(toggled = viewer.coverFit))
|
||||
}
|
||||
Block.Content.DataView.Viewer.Type.GRID -> {
|
||||
// TODO in the next PR
|
||||
result.add(ViewerRelationListView.Section.Settings)
|
||||
result.add(ViewerRelationListView.Setting.Toggle.HideIcon(toggled = viewer.hideIcon))
|
||||
}
|
||||
Block.Content.DataView.Viewer.Type.LIST -> {
|
||||
result.add(ViewerRelationListView.Section.Settings)
|
||||
|
@ -147,7 +150,7 @@ class ViewerRelationsViewModel(
|
|||
)
|
||||
).process(
|
||||
success = { dispatcher.send(it) },
|
||||
failure = { Timber.e("Error while updating") }
|
||||
failure = { Timber.w("Error while updating") }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +270,7 @@ class ViewerRelationsViewModel(
|
|||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return ViewerRelationsViewModel(
|
||||
return ObjectSetSettingsViewModel(
|
||||
objectSetState = state,
|
||||
session = session,
|
||||
dispatcher = dispatcher,
|
|
@ -26,7 +26,7 @@ sealed class ObjectSetCommand {
|
|||
|
||||
data class ManageViewer(val ctx: Id, val dataview: Id) : Modal()
|
||||
|
||||
data class ModifyViewerRelationOrder(
|
||||
data class OpenSettings(
|
||||
val ctx: Id,
|
||||
val dv: Id,
|
||||
val viewer: Id
|
||||
|
|
|
@ -34,13 +34,13 @@ import com.anytypeio.anytype.domain.error.Error
|
|||
import com.anytypeio.anytype.domain.event.interactor.InterceptEvents
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.page.CloseBlock
|
||||
import com.anytypeio.anytype.domain.page.CreateNewObject
|
||||
import com.anytypeio.anytype.domain.sets.OpenObjectSet
|
||||
import com.anytypeio.anytype.domain.status.InterceptThreadStatus
|
||||
import com.anytypeio.anytype.domain.templates.GetTemplates
|
||||
import com.anytypeio.anytype.domain.unsplash.DownloadUnsplashImage
|
||||
import com.anytypeio.anytype.presentation.common.Action
|
||||
import com.anytypeio.anytype.presentation.common.Delegator
|
||||
import com.anytypeio.anytype.domain.page.CreateNewObject
|
||||
import com.anytypeio.anytype.presentation.editor.editor.Proxy
|
||||
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
|
||||
import com.anytypeio.anytype.presentation.editor.model.TextUpdate
|
||||
|
@ -891,7 +891,7 @@ class ObjectSetViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun onViewerRelationsClicked() {
|
||||
fun onViewerSettingsClicked() {
|
||||
Timber.d("onViewerRelationsClicked, ")
|
||||
if (isRestrictionPresent(DataViewRestriction.RELATION)) {
|
||||
toast(NOT_ALLOWED)
|
||||
|
@ -904,7 +904,7 @@ class ObjectSetViewModel(
|
|||
val viewer =
|
||||
dv.viewers.find { it.id == session.currentViewerId } ?: dv.viewers.first()
|
||||
dispatch(
|
||||
ObjectSetCommand.Modal.ModifyViewerRelationOrder(
|
||||
ObjectSetCommand.Modal.OpenSettings(
|
||||
ctx = context,
|
||||
dv = block.id,
|
||||
viewer = viewer.id
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.anytypeio.anytype.presentation.sets
|
|||
|
||||
import com.anytypeio.anytype.core_models.Block
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.ObjectWrapper
|
||||
import com.anytypeio.anytype.core_models.Relation
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
|
@ -23,9 +22,9 @@ import com.anytypeio.anytype.presentation.sets.model.TagView
|
|||
import com.anytypeio.anytype.presentation.sets.model.Viewer
|
||||
|
||||
fun List<ColumnView>.buildGridRow(
|
||||
showIcon: Boolean,
|
||||
record: Map<String, Any?>,
|
||||
relations: List<Relation>,
|
||||
objectTypes: List<ObjectType> = emptyList(),
|
||||
details: Map<Id, Block.Fields>,
|
||||
builder: UrlBuilder
|
||||
): Viewer.GridView.Row {
|
||||
|
@ -180,7 +179,8 @@ fun List<ColumnView>.buildGridRow(
|
|||
image = image?.let { if (it.isEmpty()) null else builder.thumbnail(it) },
|
||||
cells = cells,
|
||||
layout = layout,
|
||||
isChecked = done
|
||||
isChecked = done,
|
||||
showIcon = showIcon,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@ sealed class Viewer {
|
|||
val type: String? = null,
|
||||
val isChecked: Boolean? = null,
|
||||
val cells: List<CellView> = emptyList(),
|
||||
val layout: ObjectType.Layout? = null
|
||||
val layout: ObjectType.Layout? = null,
|
||||
val showIcon: Boolean,
|
||||
)
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -6,7 +6,11 @@ import com.anytypeio.anytype.domain.config.Gateway
|
|||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.presentation.mapper.toViewerColumns
|
||||
import com.anytypeio.anytype.presentation.relations.ObjectSetConfig
|
||||
import com.anytypeio.anytype.presentation.sets.model.*
|
||||
import com.anytypeio.anytype.presentation.sets.model.CellView
|
||||
import com.anytypeio.anytype.presentation.sets.model.ColumnView
|
||||
import com.anytypeio.anytype.presentation.sets.model.StatusView
|
||||
import com.anytypeio.anytype.presentation.sets.model.TagView
|
||||
import com.anytypeio.anytype.presentation.sets.model.Viewer
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
@ -133,13 +137,15 @@ class TagAndStatusTests {
|
|||
record = records,
|
||||
relations = dataViewRelations,
|
||||
builder = UrlBuilder(gateway),
|
||||
details = emptyMap()
|
||||
details = emptyMap(),
|
||||
showIcon = false,
|
||||
)
|
||||
|
||||
val expected = Viewer.GridView.Row(
|
||||
id = recordId,
|
||||
name = "",
|
||||
type = "Type111",
|
||||
showIcon = false,
|
||||
cells = listOf(
|
||||
CellView.Description(
|
||||
id = recordId,
|
||||
|
@ -276,13 +282,15 @@ class TagAndStatusTests {
|
|||
record = records,
|
||||
relations = dataViewRelations,
|
||||
builder = UrlBuilder(gateway),
|
||||
details = emptyMap()
|
||||
details = emptyMap(),
|
||||
showIcon = false,
|
||||
)
|
||||
|
||||
val expected = Viewer.GridView.Row(
|
||||
id = recordId,
|
||||
name = "",
|
||||
type = "Type111",
|
||||
showIcon = false,
|
||||
cells = listOf(
|
||||
CellView.Description(
|
||||
id = recordId,
|
||||
|
|
|
@ -208,7 +208,7 @@ class ObjectSetRestrictionsTest : ObjectSetViewModelTestSetup() {
|
|||
|
||||
vm.onStart(root)
|
||||
|
||||
vm.onViewerRelationsClicked()
|
||||
vm.onViewerSettingsClicked()
|
||||
|
||||
val result = vm.toasts.stream().first()
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.mockito.MockitoAnnotations
|
|||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.stub
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertIs
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
|
||||
|
@ -149,6 +150,7 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
|
|||
emoji = null,
|
||||
image = null,
|
||||
type = doc.firstRecordType,
|
||||
showIcon = true,
|
||||
cells = listOf(
|
||||
CellView.Description(
|
||||
id = doc.firstRecordId,
|
||||
|
@ -168,6 +170,7 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
|
|||
emoji = null,
|
||||
image = null,
|
||||
type = doc.secondRecordType,
|
||||
showIcon = true,
|
||||
cells = listOf(
|
||||
CellView.Description(
|
||||
id = doc.secondRecordId,
|
||||
|
@ -183,9 +186,7 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
|
|||
)
|
||||
)
|
||||
|
||||
assertTrue { valueBefore is Viewer.GridView }
|
||||
|
||||
check(valueBefore is Viewer.GridView)
|
||||
assertIs<Viewer.GridView>(valueBefore)
|
||||
|
||||
assertEquals(
|
||||
expected = expectedColumnsBefore,
|
||||
|
@ -215,6 +216,7 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
|
|||
emoji = null,
|
||||
image = null,
|
||||
type = doc.secondRecordType,
|
||||
showIcon = true,
|
||||
cells = listOf(
|
||||
CellView.Description(
|
||||
id = doc.secondRecordId,
|
||||
|
@ -229,6 +231,7 @@ class ObjectSetSettingActiveViewerTest : ObjectSetViewModelTestSetup() {
|
|||
emoji = null,
|
||||
image = null,
|
||||
type = doc.firstRecordType,
|
||||
showIcon = true,
|
||||
cells = listOf(
|
||||
CellView.Description(
|
||||
id = doc.firstRecordId,
|
||||
|
|
|
@ -133,6 +133,6 @@ class ObjectSetZeroViewTest : ObjectSetViewModelTestSetup() {
|
|||
vm.onViewerCustomizeButtonClicked()
|
||||
vm.onViewerSortsClicked()
|
||||
vm.onViewerFiltersClicked()
|
||||
vm.onViewerRelationsClicked()
|
||||
vm.onViewerSettingsClicked()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue