diff --git a/app/src/main/java/com/anytypeio/anytype/navigation/Navigator.kt b/app/src/main/java/com/anytypeio/anytype/navigation/Navigator.kt
index 99db6e8fc5..ad43609ce0 100644
--- a/app/src/main/java/com/anytypeio/anytype/navigation/Navigator.kt
+++ b/app/src/main/java/com/anytypeio/anytype/navigation/Navigator.kt
@@ -19,6 +19,7 @@ import com.anytypeio.anytype.ui.settings.RemoteFilesManageFragment
import com.anytypeio.anytype.ui.templates.EditorTemplateFragment.Companion.TYPE_TEMPLATE_EDIT
import com.anytypeio.anytype.ui.templates.EditorTemplateFragment.Companion.TYPE_TEMPLATE_SELECT
import com.anytypeio.anytype.ui.templates.TemplateSelectFragment
+import com.anytypeio.anytype.ui.types.edit.TypeEditFragment
import com.anytypeio.anytype.ui.widgets.collection.CollectionFragment
import timber.log.Timber
@@ -247,4 +248,16 @@ class Navigator : AppNavigation {
args = AllContentFragment.args(space)
)
}
+
+ override fun openTypeEditingScreen(id: Id, name: String, icon: String, readOnly: Boolean) {
+ navController?.navigate(
+ resId = R.id.openTypeEditingScreen,
+ args = TypeEditFragment.args(
+ typeName = name,
+ id = id,
+ iconUnicode = icon,
+ readOnly = readOnly
+ )
+ )
+ }
}
diff --git a/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt b/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt
index 8a049ef872..12db76978c 100644
--- a/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt
+++ b/app/src/main/java/com/anytypeio/anytype/ui/allcontent/AllContentFragment.kt
@@ -27,6 +27,7 @@ import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModel
import com.anytypeio.anytype.feature_allcontent.presentation.AllContentViewModelFactory
import com.anytypeio.anytype.feature_allcontent.ui.AllContentNavigation.ALL_CONTENT_MAIN
import com.anytypeio.anytype.feature_allcontent.ui.AllContentWrapperScreen
+import com.anytypeio.anytype.presentation.objects.ObjectIcon
import com.anytypeio.anytype.presentation.widgets.collection.Subscription
import com.anytypeio.anytype.ui.base.navigation
import com.anytypeio.anytype.ui.settings.typography
@@ -94,6 +95,19 @@ class AllContentFragment : BaseComposeFragment() {
Timber.e(it, "Failed to open bin")
}
}
+ is AllContentViewModel.Command.OpenTypeEditing -> {
+ runCatching {
+ navigation().openTypeEditingScreen(
+ id = command.item.id,
+ name = command.item.name,
+ icon = (command.item.icon as? ObjectIcon.Basic.Emoji)?.unicode ?: "",
+ readOnly = command.item.readOnly
+ )
+ }.onFailure {
+ toast("Failed to open type editing screen")
+ Timber.e(it, "Failed to open type editing screen")
+ }
+ }
}
}
}
@@ -119,6 +133,7 @@ class AllContentFragment : BaseComposeFragment() {
canPaginate = vm.canPaginate.collectAsStateWithLifecycle().value,
onUpdateLimitSearch = vm::updateLimit,
uiContentState = vm.uiContentState.collectAsStateWithLifecycle().value,
+ onTypeClicked = vm::onTypeClicked
)
}
}
diff --git a/app/src/main/java/com/anytypeio/anytype/ui/library/LibraryScreen.kt b/app/src/main/java/com/anytypeio/anytype/ui/library/LibraryScreen.kt
index c64b6cd8d8..28ebcdf936 100644
--- a/app/src/main/java/com/anytypeio/anytype/ui/library/LibraryScreen.kt
+++ b/app/src/main/java/com/anytypeio/anytype/ui/library/LibraryScreen.kt
@@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.navigationBars
+import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.pager.rememberPagerState
@@ -97,10 +98,11 @@ fun LibraryScreen(
)
}
}
- ) {
- println(it)
+ ) { paddingValues ->
Column(
- modifier = modifier.then(
+ modifier = modifier
+ .padding(paddingValues)
+ .then(
if (BuildConfig.USE_EDGE_TO_EDGE && Build.VERSION.SDK_INT >= EDGE_TO_EDGE_MIN_SDK)
Modifier.windowInsetsPadding(WindowInsets.systemBars)
else
diff --git a/app/src/main/java/com/anytypeio/anytype/ui/types/create/TypeCreationScreen.kt b/app/src/main/java/com/anytypeio/anytype/ui/types/create/TypeCreationScreen.kt
index f2b8551dba..fed77b2843 100644
--- a/app/src/main/java/com/anytypeio/anytype/ui/types/create/TypeCreationScreen.kt
+++ b/app/src/main/java/com/anytypeio/anytype/ui/types/create/TypeCreationScreen.kt
@@ -38,7 +38,8 @@ fun TypeCreationScreen(vm: CreateObjectTypeViewModel, preparedName: String) {
objectIcon = state.objectIcon,
onLeadingIconClick = vm::openEmojiPicker,
shouldMoveCursor = preparedName.trim().isNotEmpty(),
- onImeDoneClick = vm::createType
+ onImeDoneClick = vm::createType,
+ isReadOnly = false
)
}
diff --git a/app/src/main/java/com/anytypeio/anytype/ui/types/edit/TypeEditScreen.kt b/app/src/main/java/com/anytypeio/anytype/ui/types/edit/TypeEditScreen.kt
index ce6e0346a7..2e19bb2686 100644
--- a/app/src/main/java/com/anytypeio/anytype/ui/types/edit/TypeEditScreen.kt
+++ b/app/src/main/java/com/anytypeio/anytype/ui/types/edit/TypeEditScreen.kt
@@ -38,7 +38,8 @@ fun TypeEditScreen(vm: TypeEditViewModel, preparedName: String, readOnly: Boolea
onLeadingIconClick = vm::openEmojiPicker,
onImeDoneClick = vm::updateObjectDetails,
imeOptions = ImeOptions.Done,
- shouldMoveCursor = preparedName.trim().isNotEmpty()
+ shouldMoveCursor = preparedName.trim().isNotEmpty(),
+ isReadOnly = readOnly
)
}
diff --git a/app/src/main/java/com/anytypeio/anytype/ui/types/views/TypeEditWidget.kt b/app/src/main/java/com/anytypeio/anytype/ui/types/views/TypeEditWidget.kt
index a5c6be1ad5..530159ebb7 100644
--- a/app/src/main/java/com/anytypeio/anytype/ui/types/views/TypeEditWidget.kt
+++ b/app/src/main/java/com/anytypeio/anytype/ui/types/views/TypeEditWidget.kt
@@ -36,7 +36,8 @@ fun TypeEditWidget(
onLeadingIconClick: () -> Unit,
imeOptions: ImeOptions = ImeOptions.Default,
onImeDoneClick: (name: String) -> Unit = {},
- shouldMoveCursor: Boolean
+ shouldMoveCursor: Boolean,
+ isReadOnly: Boolean
) {
val focusRequester = remember { FocusRequester() }
@@ -59,6 +60,7 @@ fun TypeEditWidget(
nameValid.value = this.isNotEmpty()
}
},
+ enabled = !isReadOnly,
modifier = Modifier
.focusRequester(focusRequester)
.offset(OffsetX)
diff --git a/app/src/main/res/navigation/graph.xml b/app/src/main/res/navigation/graph.xml
index ce0e083046..217e28113b 100644
--- a/app/src/main/res/navigation/graph.xml
+++ b/app/src/main/res/navigation/graph.xml
@@ -404,7 +404,11 @@
+ android:label="AllContentScreen">
+
+
,
- val selectedTab: AllContentTab
- ) : UiTabsState()
-}
+data class UiTabsState(
+ val tabs: List = AllContentTab.entries,
+ val selectedTab: AllContentTab = DEFAULT_INITIAL_TAB
+)
// CONTENT
sealed class UiContentState {
@@ -122,6 +121,17 @@ sealed class UiContentItem {
val createdDate: Long = 0L,
) : UiContentItem()
+ data class Type(
+ override val id: Id,
+ val name: String,
+ val icon: ObjectIcon? = null,
+ val sourceObject: Id? = null,
+ val uniqueKey: Key? = null,
+ val readOnly: Boolean = true,
+ val editable: Boolean = true,
+ val dependentData: DependentData = DependentData.None
+ ) : UiContentItem()
+
companion object {
const val TODAY_ID = "TodayId"
const val YESTERDAY_ID = "YesterdayId"
@@ -209,4 +219,30 @@ fun ObjectWrapper.Basic.toAllContentItem(
createdDate = DateParser.parse(obj.getValue(Relations.CREATED_DATE)) ?: 0L
)
}
+
+fun List.toUiContentTypes(
+ urlBuilder: UrlBuilder
+): List {
+ return map { it.toAllContentType(urlBuilder) }
+}
+
+fun ObjectWrapper.Basic.toAllContentType(
+ urlBuilder: UrlBuilder,
+): UiContentItem.Type {
+ val obj = this
+ val layout = layout ?: ObjectType.Layout.BASIC
+ return UiContentItem.Type(
+ id = obj.id,
+ name = obj.name.orEmpty(),
+ icon = ObjectIcon.from(
+ obj = obj,
+ layout = layout,
+ builder = urlBuilder
+ ),
+ sourceObject = obj.map[SOURCE_OBJECT]?.toString(),
+ uniqueKey = obj.uniqueKey,
+ readOnly = obj.restrictions.contains(ObjectRestriction.DELETE),
+ editable = !obj.restrictions.contains(ObjectRestriction.DETAILS)
+ )
+}
//endregion
\ No newline at end of file
diff --git a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/models/AllContentSearchParams.kt b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/models/AllContentSearchParams.kt
index cb0e75df84..dcb1568ab2 100644
--- a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/models/AllContentSearchParams.kt
+++ b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/models/AllContentSearchParams.kt
@@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.DVFilterCondition
import com.anytypeio.anytype.core_models.DVSort
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectType
+import com.anytypeio.anytype.core_models.ObjectTypeIds
import com.anytypeio.anytype.core_models.ObjectTypeUniqueKeys
import com.anytypeio.anytype.core_models.RelationFormat
import com.anytypeio.anytype.core_models.Relations
@@ -116,8 +117,38 @@ fun AllContentTab.filtersForSubscribe(
val sorts = listOf(activeSort.toDVSort())
return filters to sorts
}
-
- AllContentTab.TYPES -> TODO()
+ AllContentTab.TYPES -> {
+ val filters = buildList {
+ addAll(buildDeletedFilter())
+ add(buildSpaceIdFilter(spaces))
+ if (limitedObjectIds.isNotEmpty()) {
+ add(buildLimitedObjectIdsFilter(limitedObjectIds = limitedObjectIds))
+ }
+ add(
+ DVFilter(
+ relation = Relations.LAYOUT,
+ condition = DVFilterCondition.NOT_EQUAL,
+ value = ObjectType.Layout.PARTICIPANT.code.toDouble()
+ )
+ )
+ add(
+ DVFilter(
+ relation = Relations.LAYOUT,
+ condition = DVFilterCondition.EQUAL,
+ value = ObjectType.Layout.OBJECT_TYPE.code.toDouble()
+ )
+ )
+ add(
+ DVFilter(
+ relation = Relations.UNIQUE_KEY,
+ condition = DVFilterCondition.NOT_EQUAL,
+ value = ObjectTypeIds.CHAT_DERIVED
+ )
+ )
+ }
+ val sorts = listOf(activeSort.toDVSort())
+ return filters to sorts
+ }
}
}
@@ -125,24 +156,14 @@ fun AllContentTab.filtersForSearch(
spaces: List
): List {
val tab = this
- when (this) {
- AllContentTab.PAGES,
- AllContentTab.LISTS,
- AllContentTab.FILES,
- AllContentTab.MEDIA,
- AllContentTab.BOOKMARKS -> {
- val filters = buildList {
- addAll(buildDeletedFilter())
- add(buildSpaceIdFilter(spaces))
- if (tab == AllContentTab.PAGES) {
- add(buildTemplateFilter())
- }
- }
- return filters
+ val filters = buildList {
+ addAll(buildDeletedFilter())
+ add(buildSpaceIdFilter(spaces))
+ if (tab == AllContentTab.PAGES) {
+ add(buildTemplateFilter())
}
-
- AllContentTab.TYPES -> TODO()
}
+ return filters
}
private fun buildLayoutFilter(layouts: List): DVFilter = DVFilter(
@@ -196,6 +217,11 @@ private fun buildDeletedFilter(): List {
relation = Relations.IS_DELETED,
condition = DVFilterCondition.NOT_EQUAL,
value = true
+ ),
+ DVFilter(
+ relation = Relations.IS_HIDDEN_DISCOVERY,
+ condition = DVFilterCondition.NOT_EQUAL,
+ value = true
)
)
}
diff --git a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt
index fa07b47701..225efdd5c6 100644
--- a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt
+++ b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/presentation/AllContentViewModel.kt
@@ -29,6 +29,7 @@ import com.anytypeio.anytype.feature_allcontent.models.createSubscriptionParams
import com.anytypeio.anytype.feature_allcontent.models.filtersForSearch
import com.anytypeio.anytype.feature_allcontent.models.mapRelationKeyToSort
import com.anytypeio.anytype.feature_allcontent.models.toUiContentItems
+import com.anytypeio.anytype.feature_allcontent.models.toUiContentTypes
import com.anytypeio.anytype.presentation.analytics.AnalyticSpaceHelperDelegate
import com.anytypeio.anytype.presentation.home.OpenObjectNavigation
import com.anytypeio.anytype.presentation.home.navigation
@@ -49,7 +50,6 @@ import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.emitAll
-import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
@@ -79,9 +79,8 @@ class AllContentViewModel(
private val searchResultIds = MutableStateFlow>(emptyList())
private val sortState = MutableStateFlow(DEFAULT_INITIAL_SORT)
-
- val uiTitleState = MutableStateFlow(UiTitleState.Hidden)
- val uiTabsState = MutableStateFlow(UiTabsState.Hidden)
+ val uiTitleState = MutableStateFlow(DEFAULT_INITIAL_MODE)
+ val uiTabsState = MutableStateFlow(UiTabsState())
val uiMenuState = MutableStateFlow(UiMenuState.Hidden)
val uiItemsState = MutableStateFlow>(emptyList())
val uiContentState = MutableStateFlow(UiContentState.Idle())
@@ -106,7 +105,7 @@ class AllContentViewModel(
*/
val canPaginate = MutableStateFlow(false)
private var itemsLimit = DEFAULT_SEARCH_LIMIT
- private val limitUpdateTrigger = MutableStateFlow(0)
+ private val restartSubscription = MutableStateFlow(0L)
private var shouldScrollToTopItems = false
@@ -119,11 +118,6 @@ class AllContentViewModel(
}
private fun setupInitialStateParams() {
- uiTitleState.value = UiTitleState.AllContent
- uiTabsState.value = UiTabsState.Default(
- tabs = AllContentTab.entries,
- selectedTab = DEFAULT_INITIAL_TAB
- )
viewModelScope.launch {
if (vmParams.useHistory) {
runCatching {
@@ -132,6 +126,7 @@ class AllContentViewModel(
)
if (!initialParams.activeSort.isNullOrEmpty()) {
sortState.value = initialParams.activeSort.mapRelationKeyToSort()
+ restartSubscription.value++
}
}.onFailure { e ->
Timber.e(e, "Error restoring state")
@@ -146,26 +141,24 @@ class AllContentViewModel(
Timber.d("New query: [$query]")
if (query.isBlank()) {
searchResultIds.value = emptyList()
+ restartSubscription.value++
} else {
val activeTab = uiTabsState.value
- if (activeTab is UiTabsState.Default) {
- resetLimit()
- val searchParams = createSearchParams(
- activeTab = activeTab.selectedTab,
- activeQuery = query
- )
- searchObjects(searchParams).process(
- success = { searchResults ->
- Timber.d("Search objects by query:[$query], size: : ${searchResults.size}")
- searchResultIds.value = searchResults.map { it.id }
- },
- failure = {
- Timber.e(it, "Error searching objects by query")
- }
- )
- } else {
- Timber.w("Unexpected tabs state: $activeTab")
- }
+ resetLimit()
+ val searchParams = createSearchParams(
+ activeTab = activeTab.selectedTab,
+ activeQuery = query
+ )
+ searchObjects(searchParams).process(
+ success = { searchResults ->
+ Timber.d("Search objects by query:[$query], size: : ${searchResults.size}")
+ searchResultIds.value = searchResults.map { it.id }
+ restartSubscription.value++
+ },
+ failure = {
+ Timber.e(it, "Error searching objects by query")
+ }
+ )
}
}
}
@@ -174,53 +167,46 @@ class AllContentViewModel(
@OptIn(ExperimentalCoroutinesApi::class)
private fun setupUiStateFlow() {
viewModelScope.launch {
- combine(
- uiTitleState,
- uiTabsState.filterIsInstance(),
- sortState,
- searchResultIds,
- limitUpdateTrigger
- ) { mode, tab, sort, limitedObjectIds, _ ->
- Result(mode, tab, sort, limitedObjectIds)
+ restartSubscription.flatMapLatest {
+ loadData()
+ }.collect { items ->
+ uiItemsState.value = items
}
- .flatMapLatest { currentState ->
- Timber.d("New params:$currentState, restart subscription")
- loadData(currentState)
- }.collect {
- uiItemsState.value = it
- }
}
}
- private fun subscriptionId() = "all_content_subscription_${vmParams.spaceId.id}"
+ //todo discuss with someone
+ private fun loadData(): Flow> = flow {
- private fun loadData(
- result: Result
- ): Flow> = flow {
-
- if (itemsLimit == DEFAULT_SEARCH_LIMIT) {
- uiContentState.value = UiContentState.InitLoading
+ uiContentState.value = if (itemsLimit == DEFAULT_SEARCH_LIMIT) {
+ UiContentState.InitLoading
} else {
- uiContentState.value = UiContentState.Paging
+ UiContentState.Paging
}
+ val activeTab = uiTabsState.value.selectedTab
+ val activeSort = sortState.value
+
val searchParams = createSubscriptionParams(
- activeTab = result.tab.selectedTab,
- activeSort = result.sort,
- limitedObjectIds = result.limitedObjectIds,
+ activeTab = activeTab,
+ activeSort = activeSort,
+ limitedObjectIds = searchResultIds.value,
limit = itemsLimit,
subscriptionId = subscriptionId(),
spaceId = vmParams.spaceId.id,
- activeMode = result.mode
+ activeMode = uiTitleState.value
)
+ Timber.d("Restart subscription: with params: $searchParams")
+
val dataFlow = storelessSubscriptionContainer.subscribe(searchParams)
emitAll(
dataFlow.map { objWrappers ->
canPaginate.value = objWrappers.size == itemsLimit
val items = mapToUiContentItems(
objectWrappers = objWrappers,
- activeSort = result.sort
+ activeSort = activeSort,
+ activeTab = activeTab
)
uiContentState.value = if (items.isEmpty()) {
UiContentState.Empty
@@ -241,22 +227,32 @@ class AllContentViewModel(
private suspend fun mapToUiContentItems(
objectWrappers: List,
- activeSort: AllContentSort
+ activeSort: AllContentSort,
+ activeTab: AllContentTab
): List {
- val items = objectWrappers.toUiContentItems(
- space = vmParams.spaceId,
- urlBuilder = urlBuilder,
- objectTypes = storeOfObjectTypes.getAll()
- )
- return when (activeSort) {
- is AllContentSort.ByDateCreated -> {
- groupItemsByDate(items = items, isSortByDateCreated = true)
- }
- is AllContentSort.ByDateUpdated -> {
- groupItemsByDate(items = items, isSortByDateCreated = false)
- }
- is AllContentSort.ByName -> {
- items
+ if (activeTab == AllContentTab.TYPES) {
+ val items = objectWrappers.toUiContentTypes(
+ urlBuilder = urlBuilder
+ )
+ return items
+ } else {
+ val items = objectWrappers.toUiContentItems(
+ space = vmParams.spaceId,
+ urlBuilder = urlBuilder,
+ objectTypes = storeOfObjectTypes.getAll()
+ )
+ return when (activeSort) {
+ is AllContentSort.ByDateCreated -> {
+ groupItemsByDate(items = items, isSortByDateCreated = true)
+ }
+
+ is AllContentSort.ByDateUpdated -> {
+ groupItemsByDate(items = items, isSortByDateCreated = false)
+ }
+
+ is AllContentSort.ByName -> {
+ items
+ }
}
}
}
@@ -342,26 +338,39 @@ class AllContentViewModel(
viewModelScope.launch {
combine(
uiTitleState,
- sortState
- ) { mode, sort ->
- mode to sort
- }.collectLatest { (mode, sort) ->
- val uiMode = listOf(
- AllContentMenuMode.AllContent(isSelected = mode == UiTitleState.AllContent),
- AllContentMenuMode.Unlinked(isSelected = mode == UiTitleState.OnlyUnlinked)
- )
- val container = MenuSortsItem.Container(sort = sort)
- val uiSorts = listOf(
- MenuSortsItem.Sort(
- sort = AllContentSort.ByName(isSelected = sort is AllContentSort.ByName)
- ),
- MenuSortsItem.Sort(
- sort = AllContentSort.ByDateUpdated(isSelected = sort is AllContentSort.ByDateUpdated)
- ),
- MenuSortsItem.Sort(
- sort = AllContentSort.ByDateCreated(isSelected = sort is AllContentSort.ByDateCreated)
+ sortState,
+ uiTabsState
+ ) { mode, sort, tabs ->
+ Triple(mode, sort, tabs)
+ }.collectLatest { (mode, sort, tabs) ->
+ val uiMode = if (tabs.selectedTab == AllContentTab.TYPES) {
+ listOf()
+ } else {
+ listOf(
+ AllContentMenuMode.AllContent(isSelected = mode == UiTitleState.AllContent),
+ AllContentMenuMode.Unlinked(isSelected = mode == UiTitleState.OnlyUnlinked)
)
- )
+ }
+ val container = MenuSortsItem.Container(sort = sort)
+ val uiSorts = if (tabs.selectedTab == AllContentTab.TYPES) {
+ listOf(
+ MenuSortsItem.Sort(
+ sort = AllContentSort.ByName(isSelected = sort is AllContentSort.ByName)
+ )
+ )
+ } else {
+ listOf(
+ MenuSortsItem.Sort(
+ sort = AllContentSort.ByName(isSelected = sort is AllContentSort.ByName)
+ ),
+ MenuSortsItem.Sort(
+ sort = AllContentSort.ByDateUpdated(isSelected = sort is AllContentSort.ByDateUpdated)
+ ),
+ MenuSortsItem.Sort(
+ sort = AllContentSort.ByDateCreated(isSelected = sort is AllContentSort.ByDateCreated)
+ )
+ )
+ }
val uiSortTypes = listOf(
MenuSortsItem.SortType(
sort = sort,
@@ -387,18 +396,15 @@ class AllContentViewModel(
fun onTabClicked(tab: AllContentTab) {
Timber.d("onTabClicked: $tab")
if (tab == AllContentTab.TYPES) {
- viewModelScope.launch {
- commands.emit(Command.SendToast("Not implemented yet"))
- }
- return
+ sortState.value = AllContentSort.ByName()
+ userInput.value = DEFAULT_QUERY
+ uiTitleState.value = UiTitleState.AllContent
}
shouldScrollToTopItems = true
resetLimit()
uiItemsState.value = emptyList()
- uiTabsState.value = UiTabsState.Default(
- tabs = AllContentTab.entries,
- selectedTab = tab
- )
+ uiTabsState.value = uiTabsState.value.copy(selectedTab = tab)
+ restartSubscription.value++
}
fun onAllContentModeClicked(mode: AllContentMenuMode) {
@@ -409,14 +415,27 @@ class AllContentViewModel(
is AllContentMenuMode.AllContent -> UiTitleState.AllContent
is AllContentMenuMode.Unlinked -> UiTitleState.OnlyUnlinked
}
+ restartSubscription.value++
}
fun onSortClicked(sort: AllContentSort) {
Timber.d("onSortClicked: $sort")
+ val newSort = when (sort) {
+ is AllContentSort.ByDateCreated -> {
+ sort.copy(isSelected = true)
+ }
+ is AllContentSort.ByDateUpdated -> {
+ sort.copy(isSelected = true)
+ }
+ is AllContentSort.ByName -> {
+ sort.copy(isSelected = true)
+ }
+ }
shouldScrollToTopItems = true
uiItemsState.value = emptyList()
- sortState.value = sort
- proceedWithSortSaving(sort)
+ sortState.value = newSort
+ proceedWithSortSaving(newSort)
+ restartSubscription.value++
}
private fun proceedWithSortSaving(sort: AllContentSort) {
@@ -480,6 +499,13 @@ class AllContentViewModel(
}
}
+ fun onTypeClicked(item: UiContentItem.Type) {
+ Timber.d("onTypeClicked: ${item.id}")
+ viewModelScope.launch {
+ commands.emit(Command.OpenTypeEditing(item))
+ }
+ }
+
fun onStop() {
Timber.d("onStop")
viewModelScope.launch {
@@ -494,7 +520,7 @@ class AllContentViewModel(
Timber.d("Update limit, canPaginate: ${canPaginate.value} uiContentState: ${uiContentState.value}")
if (canPaginate.value && uiContentState.value is UiContentState.Idle) {
itemsLimit += DEFAULT_SEARCH_LIMIT
- limitUpdateTrigger.value++
+ restartSubscription.value++
}
}
@@ -509,23 +535,19 @@ class AllContentViewModel(
itemsLimit = DEFAULT_SEARCH_LIMIT
}
+ private fun subscriptionId() = "all_content_subscription_${vmParams.spaceId.id}"
+
data class VmParams(
val spaceId: SpaceId,
val useHistory: Boolean = true
)
- internal data class Result(
- val mode: UiTitleState,
- val tab: UiTabsState.Default,
- val sort: AllContentSort,
- val limitedObjectIds: List
- )
-
sealed class Command {
data class NavigateToEditor(val id: Id, val space: Id) : Command()
data class NavigateToSetOrCollection(val id: Id, val space: Id) : Command()
data class NavigateToBin(val space: Id) : Command()
data class SendToast(val message: String) : Command()
+ data class OpenTypeEditing(val item: UiContentItem.Type) : Command()
}
companion object {
@@ -533,6 +555,7 @@ class AllContentViewModel(
//INITIAL STATE
const val DEFAULT_SEARCH_LIMIT = 100
+ val DEFAULT_INITIAL_MODE = UiTitleState.AllContent
val DEFAULT_INITIAL_TAB = AllContentTab.PAGES
val DEFAULT_INITIAL_SORT = AllContentSort.ByName()
val DEFAULT_QUERY = ""
diff --git a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentMenu.kt b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentMenu.kt
index 10b6c577ed..0a859e5606 100644
--- a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentMenu.kt
+++ b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentMenu.kt
@@ -56,7 +56,9 @@ fun AllContentMenu(
)
Divider(0.5.dp)
}
- Divider(7.5.dp)
+ if (uiMenuState.mode.isNotEmpty()) {
+ Divider(7.5.dp)
+ }
SortingBox(
modifier = Modifier
.clickable {
diff --git a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt
index 52b11dcae7..8cb19c03fe 100644
--- a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt
+++ b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentScreen.kt
@@ -55,6 +55,7 @@ import com.anytypeio.anytype.core_ui.common.DefaultPreviews
import com.anytypeio.anytype.core_ui.foundation.Divider
import com.anytypeio.anytype.core_ui.views.ButtonSize
import com.anytypeio.anytype.core_ui.views.Caption1Regular
+import com.anytypeio.anytype.core_ui.views.PreviewTitle1Medium
import com.anytypeio.anytype.core_ui.views.PreviewTitle2Medium
import com.anytypeio.anytype.core_ui.views.Relations3
import com.anytypeio.anytype.core_ui.views.UXBody
@@ -94,6 +95,7 @@ fun AllContentWrapperScreen(
onModeClick: (AllContentMenuMode) -> Unit,
onSortClick: (AllContentSort) -> Unit,
onItemClicked: (UiContentItem.Item) -> Unit,
+ onTypeClicked: (UiContentItem.Type) -> Unit,
onBinClick: () -> Unit,
canPaginate: Boolean,
onUpdateLimitSearch: () -> Unit,
@@ -131,7 +133,8 @@ fun AllContentWrapperScreen(
onBinClick = onBinClick,
uiItemsState = uiItemsState,
lazyListState = lazyListState,
- uiContentState = uiContentState
+ uiContentState = uiContentState,
+ onTypeClicked = onTypeClicked
)
}
@@ -147,6 +150,7 @@ fun AllContentMainScreen(
onModeClick: (AllContentMenuMode) -> Unit,
onSortClick: (AllContentSort) -> Unit,
onItemClicked: (UiContentItem.Item) -> Unit,
+ onTypeClicked: (UiContentItem.Type) -> Unit,
onBinClick: () -> Unit,
lazyListState: LazyListState,
uiContentState: UiContentState
@@ -169,20 +173,15 @@ fun AllContentMainScreen(
else
Modifier.fillMaxWidth()
) {
- if (uiTitleState !is UiTitleState.Hidden) {
- AllContentTopBarContainer(
- titleState = uiTitleState,
- uiMenuState = uiMenuState,
- onSortClick = onSortClick,
- onModeClick = onModeClick,
- onBinClick = onBinClick
- )
- }
-
- if (uiTabsState is UiTabsState.Default) {
- AllContentTabs(tabsViewState = uiTabsState) { tab ->
- onTabClick(tab)
- }
+ AllContentTopBarContainer(
+ titleState = uiTitleState,
+ uiMenuState = uiMenuState,
+ onSortClick = onSortClick,
+ onModeClick = onModeClick,
+ onBinClick = onBinClick
+ )
+ AllContentTabs(tabsViewState = uiTabsState) { tab ->
+ onTabClick(tab)
}
Spacer(modifier = Modifier.size(10.dp))
AllContentSearchBar(onQueryChanged = {
@@ -231,6 +230,7 @@ fun AllContentMainScreen(
ContentItems(
uiItemsState = uiItemsState,
onItemClicked = onItemClicked,
+ onTypeClicked = onTypeClicked,
uiContentState = uiContentState,
lazyListState = lazyListState
)
@@ -245,6 +245,7 @@ fun AllContentMainScreen(
private fun ContentItems(
uiItemsState: List,
onItemClicked: (UiContentItem.Item) -> Unit,
+ onTypeClicked: (UiContentItem.Type) -> Unit,
uiContentState: UiContentState,
lazyListState: LazyListState
) {
@@ -261,6 +262,7 @@ private fun ContentItems(
when (uiItemsState[index]) {
is UiContentItem.Group -> "group"
is UiContentItem.Item -> "item"
+ is UiContentItem.Type -> "type"
}
}
) { index ->
@@ -296,6 +298,19 @@ private fun ContentItems(
item = item
)
}
+
+ is UiContentItem.Type -> {
+ Type(
+ modifier = Modifier
+ .padding(horizontal = 16.dp)
+ .bottomBorder()
+ .animateItem()
+ .clickable {
+ onTypeClicked(item)
+ },
+ item = item
+ )
+ }
}
}
if (uiContentState is UiContentState.Paging) {
@@ -351,7 +366,7 @@ fun PreviewMainScreen() {
AllContentMainScreen(
uiItemsState = emptyList(),
uiTitleState = UiTitleState.AllContent,
- uiTabsState = UiTabsState.Default(tabs = listOf(AllContentTab.PAGES, AllContentTab.TYPES, AllContentTab.LISTS), selectedTab = AllContentTab.LISTS),
+ uiTabsState = UiTabsState(tabs = listOf(AllContentTab.PAGES, AllContentTab.TYPES, AllContentTab.LISTS), selectedTab = AllContentTab.LISTS),
uiMenuState = UiMenuState.Hidden,
onTabClick = {},
onQueryChanged = {},
@@ -360,7 +375,8 @@ fun PreviewMainScreen() {
onItemClicked = {},
onBinClick = {},
lazyListState = rememberLazyListState(),
- uiContentState = UiContentState.Error("Error message")
+ uiContentState = UiContentState.Error("Error message"),
+ onTypeClicked = {}
)
}
@@ -421,9 +437,37 @@ private fun Item(
}
}
+@Composable
+private fun Type(
+ modifier: Modifier,
+ item: UiContentItem.Type
+) {
+ Row(
+ modifier = modifier.fillMaxWidth(),
+ verticalAlignment = CenterVertically
+ ) {
+ Box(
+ modifier = Modifier
+ .padding(start = 0.dp, top = 14.dp, end = 14.dp, bottom = 14.dp)
+ .wrapContentSize()
+ ) {
+ AllContentItemIcon(icon = item.icon, modifier = Modifier, iconSize = 24.dp)
+ }
+ val name = item.name.trim().ifBlank { stringResource(R.string.untitled) }
+
+ Text(
+ text = name,
+ style = PreviewTitle1Medium,
+ color = colorResource(id = R.color.text_primary),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis
+ )
+ }
+}
+
@Composable
fun AllContentItemIcon(
- icon: ObjectIcon,
+ icon: ObjectIcon?,
modifier: Modifier,
iconSize: Dp = 48.dp,
onTaskIconClicked: (Boolean) -> Unit = {},
diff --git a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentTopToolbar.kt b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentTopToolbar.kt
index e72e69cbda..2cffb535b3 100644
--- a/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentTopToolbar.kt
+++ b/feature-all-content/src/main/java/com/anytypeio/anytype/feature_allcontent/ui/AllContentTopToolbar.kt
@@ -160,7 +160,6 @@ private fun AllContentTopBarContainerPreview() {
@Composable
fun AllContentTitle(state: UiTitleState) {
when (state) {
- UiTitleState.Hidden -> return
UiTitleState.AllContent -> {
Text(
modifier = Modifier
@@ -202,7 +201,7 @@ fun AllContentMenuButton(onClick: () -> Unit) {
//region AllContentTabs
@Composable
fun AllContentTabs(
- tabsViewState: UiTabsState.Default,
+ tabsViewState: UiTabsState,
onClick: (AllContentTab) -> Unit
) {
val scrollState = rememberLazyListState()
@@ -270,7 +269,7 @@ private fun getTabText(tab: AllContentTab): String {
@Composable
private fun AllContentTabsPreview() {
AllContentTabs(
- tabsViewState = UiTabsState.Default(
+ tabsViewState = UiTabsState(
tabs = listOf(
AllContentTab.PAGES,
AllContentTab.FILES,
diff --git a/localization/src/main/res/values/strings.xml b/localization/src/main/res/values/strings.xml
index 4d6eb6639f..e823eaae0c 100644
--- a/localization/src/main/res/values/strings.xml
+++ b/localization/src/main/res/values/strings.xml
@@ -1759,7 +1759,7 @@ Please provide specific details of your needs here.
Media
Bookmarks
Files
- Object Types
+ Types
Sort by
Z → A
diff --git a/presentation/src/main/java/com/anytypeio/anytype/presentation/navigation/AppNavigation.kt b/presentation/src/main/java/com/anytypeio/anytype/presentation/navigation/AppNavigation.kt
index 5d93f30dc1..9a4b9fd4cd 100644
--- a/presentation/src/main/java/com/anytypeio/anytype/presentation/navigation/AppNavigation.kt
+++ b/presentation/src/main/java/com/anytypeio/anytype/presentation/navigation/AppNavigation.kt
@@ -52,6 +52,7 @@ interface AppNavigation {
fun openTemplatesModal(typeId: Id)
fun openAllContent(space: Id)
+ fun openTypeEditingScreen(id: Id, name: String, icon: String, readOnly: Boolean)
sealed class Command {