Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class SpaceSettingsFragment : Fragment(), ObjectTypeSelectionListener {
NewSpaceSettingsScreen(
uiState = vm.uiState.collectAsStateWithLifecycle().value,
uiWallpaperState = vm.spaceWallpapers.collectAsStateWithLifecycle().value,
chatsWithCustomNotifications = vm.chatsWithCustomNotifications.collectAsStateWithLifecycle().value,
locale = locale,
uiEvent = vm::onUiEvent
)
Expand Down Expand Up @@ -208,6 +209,16 @@ class SpaceSettingsFragment : Fragment(), ObjectTypeSelectionListener {
}
}

override fun onStart() {
super.onStart()
vm.onStart()
}

override fun onStop() {
super.onStop()
vm.onStop()
}

private suspend fun observeCommands(
showNotificationPermissionDialog: MutableState<Boolean>,
showWallpaperPicker: MutableState<Boolean>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M7,7L12,12L7,17"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="@color/control_secondary"
android:strokeLineCap="round"/>
<path
android:pathData="M17,7L12,12L17,17"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="@color/control_secondary"
android:strokeLineCap="round"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.anytypeio.anytype.core_ui.views.Caption1Regular
import com.anytypeio.anytype.core_ui.views.HeadlineHeading
import com.anytypeio.anytype.core_ui.views.PreviewTitle1Medium
import com.anytypeio.anytype.core_utils.insets.EDGE_TO_EDGE_MIN_SDK
import com.anytypeio.anytype.presentation.spaces.ChatNotificationItem
import com.anytypeio.anytype.presentation.spaces.UiEvent
import com.anytypeio.anytype.presentation.spaces.UiEvent.OnChangeSpaceType.*
import com.anytypeio.anytype.presentation.spaces.UiEvent.OnDefaultObjectTypeClicked
Expand All @@ -68,6 +69,7 @@ import timber.log.Timber
fun NewSpaceSettingsScreen(
uiState: UiSpaceSettingsState,
uiWallpaperState: List<WallpaperView>,
chatsWithCustomNotifications: List<ChatNotificationItem>,
locale: Locale?,
uiEvent: (UiEvent) -> Unit
) {
Expand Down Expand Up @@ -586,10 +588,8 @@ fun NewSpaceSettingsScreen(
NotificationsPreferenceSheet(
targetSpaceId = uiState.targetSpaceId,
currentState = uiState.notificationState,
uiEvent = {
showNotificationsSettings = false
uiEvent(it)
},
chatsWithCustomNotifications = chatsWithCustomNotifications,
uiEvent = uiEvent,
onDismiss = {
showNotificationsSettings = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ package com.anytypeio.anytype.ui_settings.space.new_settings
import android.os.Build
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
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.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
Expand All @@ -22,22 +30,31 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.anytypeio.anytype.core_models.chats.NotificationState
import com.anytypeio.anytype.core_ui.R
import com.anytypeio.anytype.core_ui.common.DefaultPreviews
import com.anytypeio.anytype.core_ui.foundation.Divider
import com.anytypeio.anytype.core_ui.foundation.Dragger
import com.anytypeio.anytype.core_ui.foundation.noRippleClickable
import com.anytypeio.anytype.core_ui.views.BodyRegular
import com.anytypeio.anytype.core_ui.views.Caption1Medium
import com.anytypeio.anytype.core_ui.views.Relations3
import com.anytypeio.anytype.core_ui.views.Title1
import com.anytypeio.anytype.core_ui.views.Title2
import com.anytypeio.anytype.core_ui.widgets.ListWidgetObjectIcon
import com.anytypeio.anytype.core_utils.insets.EDGE_TO_EDGE_MIN_SDK
import com.anytypeio.anytype.presentation.objects.ObjectIcon
import com.anytypeio.anytype.presentation.spaces.ChatNotificationItem
import com.anytypeio.anytype.presentation.spaces.UiEvent

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NotificationsPreferenceSheet(
targetSpaceId: String?,
currentState: NotificationState,
chatsWithCustomNotifications: List<ChatNotificationItem>,
uiEvent: (UiEvent) -> Unit,
onDismiss: () -> Unit
) {
Expand All @@ -57,45 +74,109 @@ fun NotificationsPreferenceSheet(
dragHandle = {},
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
) {
Column(
modifier = Modifier.fillMaxWidth()
LazyColumn(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Dragger(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(vertical = 6.dp)
)
Text(
text = stringResource(R.string.notifications_title),
style = Title1,
color = colorResource(id = R.color.text_primary),
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(horizontal = 24.dp, vertical = 8.dp)
)
NotificationOption(
title = stringResource(R.string.notifications_all),
checked = currentState == NotificationState.ALL,
onClick = { uiEvent(UiEvent.OnNotificationsSetting.All(targetSpaceId)) }
)
Divider(
paddingStart = 16.dp,
paddingEnd = 16.dp,
)
NotificationOption(
title = stringResource(R.string.notifications_mentions),
checked = currentState == NotificationState.MENTIONS,
onClick = { uiEvent(UiEvent.OnNotificationsSetting.Mentions(targetSpaceId)) }
)
Divider(
paddingStart = 16.dp,
paddingEnd = 16.dp,
)
NotificationOption(
title = stringResource(R.string.notifications_disable),
checked = currentState == NotificationState.DISABLE,
onClick = { uiEvent(UiEvent.OnNotificationsSetting.None(targetSpaceId)) }
)
item {
Dragger(
modifier = Modifier
.padding(vertical = 6.dp)
)
}
item {
Text(
text = stringResource(R.string.notifications_title),
style = Title1,
color = colorResource(id = R.color.text_primary),
modifier = Modifier
.padding(horizontal = 24.dp, vertical = 12.dp)
)
}
item {
Box(
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
) {
Text(
text = stringResource(R.string.notify_me_about),
style = Caption1Medium,
color = colorResource(id = R.color.text_secondary),
modifier = Modifier
.align(Alignment.BottomStart)
.padding(start = 16.dp, bottom = 12.dp)
)
}
}
item {
NotificationOption(
title = stringResource(R.string.notifications_all),
checked = currentState == NotificationState.ALL,
onClick = { uiEvent(UiEvent.OnNotificationsSetting.All(targetSpaceId)) }
)
}
item {
Divider(
paddingStart = 16.dp,
paddingEnd = 16.dp,
)
}
item {
NotificationOption(
title = stringResource(R.string.notifications_mentions),
checked = currentState == NotificationState.MENTIONS,
onClick = { uiEvent(UiEvent.OnNotificationsSetting.Mentions(targetSpaceId)) }
)
}
item {
Divider(
paddingStart = 16.dp,
paddingEnd = 16.dp,
)
}
item {
NotificationOption(
title = stringResource(R.string.notifications_disable),
checked = currentState == NotificationState.DISABLE,
onClick = { uiEvent(UiEvent.OnNotificationsSetting.None(targetSpaceId)) }
)
}

// Show chats with custom notification settings
if (chatsWithCustomNotifications.isNotEmpty()) {
item {
Box(
modifier = Modifier
.fillMaxWidth()
.height(52.dp)
) {
Text(
text = stringResource(R.string.chat_specific_notifications),
style = Caption1Medium,
color = colorResource(id = R.color.text_secondary),
modifier = Modifier
.align(Alignment.BottomStart)
.padding(start = 16.dp, bottom = 12.dp)
)
}
}
items(chatsWithCustomNotifications) { chatItem ->
ChatNotificationItem(
chatItem = chatItem,
onResetClick = {
uiEvent(UiEvent.OnResetChatNotification(chatItem.id))
}
)
Divider(
paddingStart = 16.dp,
paddingEnd = 16.dp,
)
}
item {
Spacer(modifier = Modifier.height(16.dp))
}
}
}
}
}
Expand All @@ -110,7 +191,7 @@ fun NotificationOption(
modifier = Modifier
.fillMaxWidth()
.clickable { onClick() }
.padding(horizontal = 24.dp, vertical = 16.dp),
.padding(horizontal = 16.dp, vertical = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
Expand All @@ -128,12 +209,82 @@ fun NotificationOption(
}
}

@Composable
fun ChatNotificationItem(
chatItem: ChatNotificationItem,
onResetClick: () -> Unit
) {
Column(
modifier = Modifier
.height(72.dp)
.fillMaxWidth(),
verticalArrangement = Arrangement.Center
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
ListWidgetObjectIcon(
icon = chatItem.icon,
modifier = Modifier.padding(end = 12.dp),
iconSize = 48.dp,
)
Column(
modifier = Modifier.weight(1f)
) {
Text(
text = chatItem.name,
style = Title2,
color = colorResource(id = R.color.text_primary),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = when (chatItem.customState) {
NotificationState.ALL -> stringResource(R.string.notifications_all_short)
NotificationState.MENTIONS -> stringResource(R.string.notifications_mentions_short)
NotificationState.DISABLE -> stringResource(R.string.notifications_disable_short)
},
style = Relations3,
color = colorResource(id = R.color.text_secondary)
)
}
Icon(
painter = painterResource(id = R.drawable.ic_notification_status_clear_24),
contentDescription = "Reset to space default",
tint = colorResource(id = R.color.control_secondary),
modifier = Modifier
.size(24.dp)
.noRippleClickable {
onResetClick()
}
)
}
}
}

@DefaultPreviews
@Composable
fun NotificationsPreferenceSheetPreview() {
NotificationsPreferenceSheet(
targetSpaceId = "space_view_id",
currentState = NotificationState.ALL,
chatsWithCustomNotifications = listOf(
ChatNotificationItem(
id = "chat1",
name = "Team Chat",
customState = NotificationState.MENTIONS,
icon = ObjectIcon.TypeIcon.Default.DEFAULT
),
ChatNotificationItem(
id = "chat2",
name = "Project Discussion",
customState = NotificationState.DISABLE,
icon = ObjectIcon.TypeIcon.Default.DEFAULT
)
),
uiEvent = {},
onDismiss = {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fun NewSpaceSettingsScreenPreview() {
WallpaperView.SolidColor(isSelected = false, code = WallpaperColor.PURPLE.code),
WallpaperView.SolidColor(isSelected = false, code = WallpaperColor.RED.code),
),
chatsWithCustomNotifications = emptyList(),
locale = Locale.getDefault()
)
}
6 changes: 4 additions & 2 deletions localization/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2239,9 +2239,9 @@ Please provide specific details of your needs here.</string>
<string name="chat_camera_permission_denied">Camera permission denied</string>

<string name="notifications_title">Notifications</string>
<string name="notifications_all">All activity</string>
<string name="notifications_all">All new messages</string>
<string name="notifications_mentions">Mentions only</string>
<string name="notifications_disable">Disable notifications</string>
<string name="notifications_disable">Nothing</string>
<string name="notifications_all_short">All</string>
<string name="notifications_mentions_short">Mentions</string>
<string name="notifications_disable_short">Disable</string>
Expand Down Expand Up @@ -2347,5 +2347,7 @@ Please provide specific details of your needs here.</string>
<string name="chat_edit_info_upload_image">Upload Image</string>
<string name="chat_notifications_receive_all">Receive all</string>
<string name="chat_notifications_mute_all">Mute all</string>
<string name="chat_specific_notifications">Chat specific notifications</string>
<string name="notify_me_about">Notify me about</string>

</resources>
Loading