1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-1109 Widgets | Enhancement | Render space icon (#3039)

This commit is contained in:
Evgenii Kozlov 2023-03-23 14:20:08 +01:00 committed by GitHub
parent 326599d065
commit 32c22bb6e5
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 8 deletions

View file

@ -22,6 +22,7 @@ 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.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
@ -42,11 +43,14 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import coil.compose.rememberAsyncImagePainter
import com.anytypeio.anytype.R
import com.anytypeio.anytype.core_models.ObjectWrapper
import com.anytypeio.anytype.core_ui.extensions.throttledClick
import com.anytypeio.anytype.core_ui.foundation.noRippleClickable
import com.anytypeio.anytype.emojifier.Emojifier
import com.anytypeio.anytype.presentation.home.InteractionMode
import com.anytypeio.anytype.presentation.spaces.SpaceIcon
import com.anytypeio.anytype.presentation.widgets.DropDownMenuAction
import com.anytypeio.anytype.presentation.widgets.FromIndex
import com.anytypeio.anytype.presentation.widgets.ToIndex
@ -66,9 +70,11 @@ import org.burnoutcrew.reorderable.ReorderableItem
import org.burnoutcrew.reorderable.detectReorderAfterLongPress
import org.burnoutcrew.reorderable.rememberReorderableLazyListState
import org.burnoutcrew.reorderable.reorderable
import timber.log.Timber
@Composable
fun HomeScreen(
spaceIcon: SpaceIcon,
mode: InteractionMode,
widgets: List<WidgetView>,
onExpand: (TreePath) -> Unit,
@ -138,6 +144,7 @@ fun HomeScreen(
exit = fadeOut() + slideOutVertically { it }
) {
HomeScreenBottomToolbar(
spaceIcon = spaceIcon,
onSearchClicked = throttledClick(onSearchClicked),
onCreateNewObjectClicked = throttledClick(onCreateNewObjectClicked),
onSpaceClicked = throttledClick(onSpaceClicked),
@ -496,6 +503,7 @@ fun HomeScreenButton(
@Composable
fun HomeScreenBottomToolbar(
spaceIcon: SpaceIcon,
modifier: Modifier,
onSearchClicked: () -> Unit,
onCreateNewObjectClicked: () -> Unit,
@ -540,11 +548,40 @@ fun HomeScreenBottomToolbar(
.fillMaxSize()
.noRippleClickable { onSpaceClicked() }
) {
Image(
painter = painterResource(id = R.drawable.ic_home_widget_space),
contentDescription = "Space icon",
modifier = Modifier.align(Alignment.Center)
)
Timber.d("Binding icon: $spaceIcon")
when(spaceIcon) {
is SpaceIcon.Emoji -> {
Image(
painter = rememberAsyncImagePainter(
model = Emojifier.uri(spaceIcon.unicode),
error = painterResource(id = R.drawable.ic_home_widget_space)
),
contentDescription = "Emoji space icon",
modifier = Modifier
.size(24.dp)
.align(Alignment.Center)
)
}
is SpaceIcon.Image -> {
Image(
painter = rememberAsyncImagePainter(
model = spaceIcon.url,
error = painterResource(id = R.drawable.ic_home_widget_space)
),
contentDescription = "Custom image space icon",
modifier = Modifier
.size(24.dp)
.align(Alignment.Center)
)
}
else -> {
Image(
painter = painterResource(id = R.drawable.ic_home_widget_space),
contentDescription = "Placeholder space icon",
modifier = Modifier.align(Alignment.Center)
)
}
}
}
}
}

View file

@ -60,6 +60,7 @@ class HomeScreenFragment : BaseComposeFragment() {
)
) {
HomeScreen(
spaceIcon = vm.icon.collectAsState().value,
widgets = vm.views.collectAsState().value,
mode = vm.mode.collectAsState().value,
onExpand = { path -> vm.onExpand(path) },

View file

@ -37,7 +37,6 @@ import com.anytypeio.anytype.domain.page.CreateObject
import com.anytypeio.anytype.domain.widgets.CreateWidget
import com.anytypeio.anytype.domain.widgets.DeleteWidget
import com.anytypeio.anytype.domain.widgets.UpdateWidget
import com.anytypeio.anytype.presentation.common.ViewState
import com.anytypeio.anytype.presentation.home.Command.ChangeWidgetType.Companion.UNDEFINED_LAYOUT_CODE
import com.anytypeio.anytype.presentation.navigation.NavigationViewModel
import com.anytypeio.anytype.presentation.search.Subscriptions
@ -118,7 +117,7 @@ class HomeScreenViewModel(
// Bundled widget containing archived objects
private val bin = WidgetView.Bin(Subscriptions.SUBSCRIPTION_ARCHIVED)
val icon = MutableStateFlow<ViewState<SpaceIcon>>(ViewState.Loading)
val icon = MutableStateFlow<SpaceIcon>(SpaceIcon.Loading)
init {
val config = configStorage.get()
@ -261,7 +260,7 @@ class HomeScreenViewModel(
)
).map { result ->
val obj = result.firstOrNull()
ViewState.Success(obj?.spaceIcon(urlBuilder) ?: SpaceIcon.Placeholder)
obj?.spaceIcon(urlBuilder) ?: SpaceIcon.Placeholder
}.flowOn(appCoroutineDispatchers.io).collect {
icon.value = it
}
@ -784,6 +783,13 @@ class HomeScreenViewModel(
}
}
override fun onCleared() {
super.onCleared()
viewModelScope.launch {
unsubscriber.unsubscribe(listOf(HOME_SCREEN_SPACE_OBJECT_SUBSCRIPTION))
}
}
sealed class Navigation {
data class OpenObject(val ctx: Id) : Navigation()
data class OpenSet(val ctx: Id) : Navigation()

View file

@ -5,6 +5,7 @@ import com.anytypeio.anytype.core_models.Url
import com.anytypeio.anytype.domain.misc.UrlBuilder
sealed class SpaceIcon {
object Loading : SpaceIcon()
object Placeholder : SpaceIcon()
data class Emoji(val unicode: String) : SpaceIcon()
data class Image(val url: Url) : SpaceIcon()