mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-07 21:37:02 +09:00
DROID-3626 Space chat | Prohibit adding a chat widget + ui improvements (#2511)
This commit is contained in:
parent
78853bf951
commit
a4e5d16e16
4 changed files with 51 additions and 40 deletions
|
@ -6,14 +6,9 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.statusBars
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.windowInsetsPadding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
|
@ -71,9 +66,9 @@ import com.anytypeio.anytype.ui.settings.typography
|
|||
import com.anytypeio.anytype.ui.widgets.SelectWidgetSourceFragment
|
||||
import com.anytypeio.anytype.ui.widgets.SelectWidgetTypeFragment
|
||||
import com.anytypeio.anytype.ui_settings.space.new_settings.ViewerSpaceSettings
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
class HomeScreenFragment : BaseComposeFragment(),
|
||||
ObjectTypeSelectionListener,
|
||||
|
|
|
@ -3,16 +3,15 @@ package com.anytypeio.anytype.ui.home
|
|||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
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.systemBarsPadding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
|
@ -23,7 +22,7 @@ import androidx.compose.ui.unit.dp
|
|||
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.views.PreviewTitle2Medium
|
||||
import com.anytypeio.anytype.core_ui.views.ModalTitle
|
||||
import com.anytypeio.anytype.core_ui.views.Relations2
|
||||
import com.anytypeio.anytype.feature_chats.R
|
||||
import com.anytypeio.anytype.presentation.spaces.SpaceIconView
|
||||
|
@ -44,16 +43,22 @@ fun HomeScreenToolbar(
|
|||
.height(52.dp)
|
||||
) {
|
||||
|
||||
Image(
|
||||
painter = painterResource(R.drawable.ic_default_top_back),
|
||||
contentDescription = "Back button",
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(start = 16.dp)
|
||||
.fillMaxHeight()
|
||||
.width(56.dp)
|
||||
.align(Alignment.CenterStart)
|
||||
.noRippleClickable {
|
||||
onBackButtonClicked()
|
||||
}
|
||||
)
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.drawable.ic_default_top_back),
|
||||
contentDescription = "Back button",
|
||||
modifier = Modifier
|
||||
)
|
||||
}
|
||||
|
||||
SpaceIconView(
|
||||
modifier = Modifier
|
||||
|
@ -68,7 +73,7 @@ fun HomeScreenToolbar(
|
|||
|
||||
Text(
|
||||
text = name.ifEmpty { stringResource(R.string.untitled) },
|
||||
style = PreviewTitle2Medium,
|
||||
style = ModalTitle,
|
||||
color = colorResource(R.color.text_primary),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
@ -116,16 +121,22 @@ fun HomeScreenToolbar(
|
|||
}
|
||||
)
|
||||
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_vault_settings),
|
||||
contentDescription = "Settings icon",
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.width(56.dp)
|
||||
.align(Alignment.CenterEnd)
|
||||
.padding(end = 17.dp)
|
||||
.noRippleClickable {
|
||||
onSettingsClicked()
|
||||
}
|
||||
)
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.ic_vault_settings),
|
||||
contentDescription = "Settings icon",
|
||||
modifier = Modifier
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -10,6 +10,7 @@ import com.anytypeio.anytype.core_models.DVFilterCondition
|
|||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
import com.anytypeio.anytype.core_models.Relations
|
||||
import com.anytypeio.anytype.core_models.multiplayer.SpaceUxType
|
||||
import com.anytypeio.anytype.core_models.widgets.BundledWidgetSourceIds
|
||||
import com.anytypeio.anytype.domain.base.Resultat
|
||||
import com.anytypeio.anytype.domain.base.fold
|
||||
|
@ -73,13 +74,15 @@ class SelectWidgetSourceViewModel(
|
|||
var config : Config = Config.None
|
||||
|
||||
val viewState = flow {
|
||||
val hasChat = !spaceViews.get(vmParams.space)?.chatId.isNullOrEmpty()
|
||||
emitAll(
|
||||
combine(
|
||||
stateData
|
||||
.asFlow(),
|
||||
suggested.filterIsInstance<SuggestedWidgetsState.Default>()
|
||||
) { state, suggested ->
|
||||
stateData.asFlow(),
|
||||
suggested.filterIsInstance<SuggestedWidgetsState.Default>(),
|
||||
spaceViews.observe(vmParams.space)
|
||||
) { state, suggested, spaceView ->
|
||||
val hasChat = !spaceView.chatId.isNullOrEmpty()
|
||||
val isChatSpace = spaceView.spaceUxType == SpaceUxType.CHAT
|
||||
|
||||
when(state) {
|
||||
is ObjectSearchView.Success -> {
|
||||
state.copy(
|
||||
|
@ -89,7 +92,8 @@ class SelectWidgetSourceViewModel(
|
|||
resolveSuggestedResults(
|
||||
suggested = suggested,
|
||||
query = query,
|
||||
hasChat = hasChat
|
||||
hasChat = hasChat,
|
||||
isChatSpace = isChatSpace
|
||||
)
|
||||
)
|
||||
// Widgets from existing objects
|
||||
|
@ -105,7 +109,8 @@ class SelectWidgetSourceViewModel(
|
|||
resolveSuggestedResults(
|
||||
suggested = suggested,
|
||||
query = query,
|
||||
hasChat = hasChat
|
||||
hasChat = hasChat,
|
||||
isChatSpace = isChatSpace
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -135,7 +140,8 @@ class SelectWidgetSourceViewModel(
|
|||
private fun resolveSuggestedResults(
|
||||
suggested: SuggestedWidgetsState.Default,
|
||||
query: String,
|
||||
hasChat: Boolean
|
||||
hasChat: Boolean,
|
||||
isChatSpace: Boolean
|
||||
) = buildList {
|
||||
|
||||
// Adding system widgets if matched by query
|
||||
|
@ -152,7 +158,8 @@ class SelectWidgetSourceViewModel(
|
|||
if (contains(BundledWidgetSourceIds.ALL_OBJECTS)) {
|
||||
add(BundledWidgetSourceView.AllObjects)
|
||||
}
|
||||
if (contains(BundledWidgetSourceIds.CHAT) && hasChat) {
|
||||
// Chat widget can only be added if the space has chat AND is not a chat space itself
|
||||
if (contains(BundledWidgetSourceIds.CHAT) && hasChat && !isChatSpace) {
|
||||
add(BundledWidgetSourceView.Chat)
|
||||
}
|
||||
if (contains(BundledWidgetSourceIds.RECENT)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue