mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2951 Vault | Enhancement | Support loading state of space hub cards (#1806)
This commit is contained in:
parent
18f85ad533
commit
3fba26facd
3 changed files with 86 additions and 16 deletions
|
@ -14,7 +14,9 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.systemBars
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.windowInsetsPadding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
|
@ -47,6 +49,7 @@ import com.anytypeio.anytype.core_models.Relations
|
|||
import com.anytypeio.anytype.core_models.Wallpaper
|
||||
import com.anytypeio.anytype.core_models.ext.EMPTY_STRING_VALUE
|
||||
import com.anytypeio.anytype.core_models.multiplayer.SpaceAccessType
|
||||
import com.anytypeio.anytype.core_ui.common.DefaultPreviews
|
||||
import com.anytypeio.anytype.core_ui.features.SpaceIconView
|
||||
import com.anytypeio.anytype.core_ui.foundation.noRippleClickable
|
||||
import com.anytypeio.anytype.core_ui.foundation.util.DraggableItem
|
||||
|
@ -130,18 +133,22 @@ fun VaultScreen(
|
|||
Spacer(modifier = Modifier.height(4.dp))
|
||||
}
|
||||
DraggableItem(dragDropState = dragDropState, index = idx) {
|
||||
VaultSpaceCard(
|
||||
title = item.space.name.orEmpty(),
|
||||
subtitle = when (item.space.spaceAccessType) {
|
||||
SpaceAccessType.PRIVATE -> stringResource(id = R.string.space_type_private_space)
|
||||
SpaceAccessType.DEFAULT -> stringResource(id = R.string.space_type_default_space)
|
||||
SpaceAccessType.SHARED -> stringResource(id = R.string.space_type_shared_space)
|
||||
else -> EMPTY_STRING_VALUE
|
||||
},
|
||||
wallpaper = item.wallpaper,
|
||||
onCardClicked = { onSpaceClicked(item) },
|
||||
icon = item.icon
|
||||
)
|
||||
if (item.space.isLoading) {
|
||||
LoadingSpaceCard()
|
||||
} else {
|
||||
VaultSpaceCard(
|
||||
title = item.space.name.orEmpty(),
|
||||
subtitle = when (item.space.spaceAccessType) {
|
||||
SpaceAccessType.PRIVATE -> stringResource(id = R.string.space_type_private_space)
|
||||
SpaceAccessType.DEFAULT -> stringResource(id = R.string.space_type_default_space)
|
||||
SpaceAccessType.SHARED -> stringResource(id = R.string.space_type_shared_space)
|
||||
else -> EMPTY_STRING_VALUE
|
||||
},
|
||||
wallpaper = item.wallpaper,
|
||||
onCardClicked = { onSpaceClicked(item) },
|
||||
icon = item.icon
|
||||
)
|
||||
}
|
||||
}
|
||||
if (idx == spaces.lastIndex && spaces.size < SelectSpaceViewModel.MAX_SPACE_COUNT) {
|
||||
VaultSpaceAddCard(
|
||||
|
@ -330,6 +337,59 @@ fun VaultSpaceAddCard(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LoadingSpaceCard() {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(96.dp)
|
||||
.padding(horizontal = 8.dp)
|
||||
.background(
|
||||
color = colorResource(R.color.shape_tertiary),
|
||||
shape = RoundedCornerShape(20.dp)
|
||||
)
|
||||
.clip(RoundedCornerShape(20.dp))
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(start = 16.dp)
|
||||
.size(64.dp)
|
||||
.align(Alignment.CenterStart)
|
||||
.background(
|
||||
color = colorResource(R.color.shape_primary),
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
)
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(start = 96.dp, top = 30.dp)
|
||||
.height(12.dp)
|
||||
.width(160.dp)
|
||||
.background(
|
||||
color = colorResource(R.color.shape_primary)
|
||||
)
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(start = 96.dp, bottom = 30.dp)
|
||||
.height(8.dp)
|
||||
.width(96.dp)
|
||||
.align(Alignment.BottomStart)
|
||||
.background(
|
||||
color = colorResource(R.color.shape_primary)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@DefaultPreviews
|
||||
@Composable
|
||||
fun LoadingSpaceCardPreview() {
|
||||
LoadingSpaceCard()
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES, name = "Light Mode")
|
||||
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO, name = "Dark Mode")
|
||||
|
|
|
@ -296,6 +296,19 @@ sealed class ObjectWrapper {
|
|||
return value?.toInt() ?: 0
|
||||
}
|
||||
|
||||
val isLoading: Boolean
|
||||
get() {
|
||||
return spaceLocalStatus == SpaceStatus.LOADING
|
||||
&& spaceAccountStatus != SpaceStatus.SPACE_REMOVING
|
||||
&& spaceAccountStatus != SpaceStatus.SPACE_DELETED
|
||||
}
|
||||
|
||||
val isActive: Boolean
|
||||
get() {
|
||||
return spaceLocalStatus == SpaceStatus.OK
|
||||
&& spaceAccountStatus != SpaceStatus.SPACE_REMOVING
|
||||
&& spaceAccountStatus != SpaceStatus.SPACE_DELETED
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T> getValue(relation: Key): T? {
|
||||
|
|
|
@ -82,10 +82,7 @@ class VaultViewModel(
|
|||
}
|
||||
.combine(observeVaultSettings.flow()) { spaces, settings ->
|
||||
spaces
|
||||
.filter { space ->
|
||||
space.spaceLocalStatus == SpaceStatus.OK
|
||||
&& !space.spaceAccountStatus.isDeletedOrRemoving()
|
||||
}
|
||||
.filter { space -> space.isActive }
|
||||
.distinctBy { it.id }
|
||||
.map { space ->
|
||||
VaultSpaceView(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue