Skip to content

Commit 9e6a4b0

Browse files
committed
1 parent c57d536 commit 9e6a4b0

File tree

3 files changed

+71
-13
lines changed

3 files changed

+71
-13
lines changed

app/src/main/java/com/anytypeio/anytype/ui/chats/ChatFragment.kt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import com.anytypeio.anytype.core_models.Id
4343
import com.anytypeio.anytype.core_models.primitives.Space
4444
import com.anytypeio.anytype.core_models.primitives.SpaceId
4545
import com.anytypeio.anytype.core_ui.features.multiplayer.ShareSpaceQrCodeScreen
46+
import com.anytypeio.anytype.core_ui.foundation.AlertConfig
47+
import com.anytypeio.anytype.core_ui.foundation.BUTTON_SECONDARY
48+
import com.anytypeio.anytype.core_ui.foundation.BUTTON_WARNING
49+
import com.anytypeio.anytype.core_ui.foundation.GenericAlert
4650
import com.anytypeio.anytype.core_ui.views.BaseAlertDialog
4751
import com.anytypeio.anytype.core_utils.ext.arg
4852
import com.anytypeio.anytype.core_utils.ext.openAppSettings
@@ -111,9 +115,13 @@ class ChatFragment : Fragment() {
111115
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
112116
val notificationsSheetState =
113117
rememberModalBottomSheetState(skipPartiallyExpanded = true)
118+
val moveToBinSheetState =
119+
rememberModalBottomSheetState(skipPartiallyExpanded = true)
114120
var showGlobalSearchBottomSheet by remember { mutableStateOf(false) }
115121
val showNotificationPermissionDialog =
116122
vm.showNotificationPermissionDialog.collectAsStateWithLifecycle().value
123+
val showMoveToBinDialog =
124+
vm.showMoveToBinDialog.collectAsStateWithLifecycle().value
117125

118126
ErrorScreen()
119127

@@ -134,8 +142,8 @@ class ChatFragment : Fragment() {
134142
onSpaceIconClicked = vm::onSpaceIconClicked,
135143
onInviteMembersClicked = vm::onInviteMembersClicked,
136144
onEditInfo = vm::onEditInfo,
137-
onPin = vm::onPin,
138-
onCopyLink = vm::onCopyLink,
145+
onPin = vm::onPinChatAsWidget,
146+
onCopyLink = vm::onCopyChatLink,
139147
onMoveToBin = vm::onMoveToBin
140148
)
141149
}
@@ -233,6 +241,30 @@ class ChatFragment : Fragment() {
233241
}
234242
}
235243

244+
if (showMoveToBinDialog) {
245+
ModalBottomSheet(
246+
onDismissRequest = { vm.onMoveToBinCancelled() },
247+
sheetState = moveToBinSheetState,
248+
containerColor = colorResource(id = R.color.background_secondary),
249+
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
250+
dragHandle = null
251+
) {
252+
GenericAlert(
253+
config = AlertConfig.WithTwoButtons(
254+
title = "Move chat to Bin?",
255+
description = "This chat and all its attachments will be moved to Bin. No one will be able to send new messages. You can restore it from Bin until it's permanently cleared.",
256+
firstButtonText = "Cancel",
257+
secondButtonText = "Move To Bin",
258+
firstButtonType = BUTTON_SECONDARY,
259+
secondButtonType = BUTTON_WARNING,
260+
icon = R.drawable.ic_popup_question_56
261+
),
262+
onFirstButtonClicked = { vm.onMoveToBinCancelled() },
263+
onSecondButtonClicked = { vm.onMoveToBinConfirmed() }
264+
)
265+
}
266+
}
267+
236268
if (showGlobalSearchBottomSheet) {
237269
ModalBottomSheet(
238270
onDismissRequest = {

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/presentation/ChatViewModel.kt

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import com.anytypeio.anytype.core_utils.common.DefaultFileInfo
3131
import com.anytypeio.anytype.core_utils.ext.cancel
3232
import com.anytypeio.anytype.domain.auth.interactor.GetAccount
3333
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
34-
import com.anytypeio.anytype.domain.base.fold
3534
import com.anytypeio.anytype.domain.base.onFailure
3635
import com.anytypeio.anytype.domain.base.onSuccess
3736
import com.anytypeio.anytype.domain.chats.AddChatMessage
@@ -54,6 +53,7 @@ import com.anytypeio.anytype.domain.notifications.NotificationBuilder
5453
import com.anytypeio.anytype.domain.`object`.GetObject
5554
import com.anytypeio.anytype.domain.objects.CreateObjectFromUrl
5655
import com.anytypeio.anytype.domain.objects.ObjectWatcher
56+
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
5757
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
5858
import com.anytypeio.anytype.domain.objects.getTypeOfObject
5959
import com.anytypeio.anytype.domain.page.CreateObject
@@ -72,12 +72,8 @@ import com.anytypeio.anytype.presentation.objects.ObjectIcon
7272
import com.anytypeio.anytype.presentation.objects.SpaceMemberIconView
7373
import com.anytypeio.anytype.presentation.search.GlobalSearchItemView
7474
import com.anytypeio.anytype.presentation.spaces.SpaceIconView
75-
import com.anytypeio.anytype.presentation.spaces.SpaceSettingsViewModel.Command.ShareInviteLink
7675
import com.anytypeio.anytype.presentation.spaces.UiSpaceQrCodeState
7776
import com.anytypeio.anytype.presentation.spaces.UiSpaceQrCodeState.SpaceInvite
78-
import com.anytypeio.anytype.presentation.spaces.UiSpaceSettingsItem.Icon
79-
import com.anytypeio.anytype.presentation.spaces.UiSpaceSettingsItem.Name
80-
import com.anytypeio.anytype.presentation.spaces.UiSpaceSettingsState
8177
import com.anytypeio.anytype.presentation.spaces.spaceIcon
8278
import com.anytypeio.anytype.presentation.util.CopyFileToCacheDirectory
8379
import com.anytypeio.anytype.presentation.vault.ExitToVaultDelegate
@@ -132,7 +128,8 @@ class ChatViewModel @Inject constructor(
132128
private val analytics: Analytics,
133129
private val spaceInviteLinkStore: SpaceInviteLinkStore,
134130
private val getCurrentInviteAccessLevel: GetCurrentInviteAccessLevel,
135-
private val pinObjectAsWidgetDelegate: PinObjectAsWidgetDelegate
131+
private val pinObjectAsWidgetDelegate: PinObjectAsWidgetDelegate,
132+
private val setObjectListIsArchived: SetObjectListIsArchived
136133
) : BaseViewModel(),
137134
ExitToVaultDelegate by exitToVaultDelegate,
138135
PinObjectAsWidgetDelegate by pinObjectAsWidgetDelegate {
@@ -154,6 +151,9 @@ class ChatViewModel @Inject constructor(
154151
val chatBoxMode = MutableStateFlow<ChatBoxMode>(ChatBoxMode.Default())
155152
val mentionPanelState = MutableStateFlow<MentionPanelState>(MentionPanelState.Hidden)
156153
val showNotificationPermissionDialog = MutableStateFlow(false)
154+
val showMoveToBinDialog = MutableStateFlow(false)
155+
156+
157157
val canCreateInviteLink = MutableStateFlow(false)
158158
private val spaceAccessType = MutableStateFlow<SpaceAccessType?>(null)
159159
val errorState = MutableStateFlow<UiErrorState>(UiErrorState.Hidden)
@@ -1523,7 +1523,7 @@ class ChatViewModel @Inject constructor(
15231523
// TODO: Implement edit info functionality
15241524
}
15251525

1526-
fun onPin() {
1526+
fun onPinChatAsWidget() {
15271527
viewModelScope.launch(dispatchers.io) {
15281528
pinChat(
15291529
space = vmParams.space,
@@ -1536,12 +1536,35 @@ class ChatViewModel @Inject constructor(
15361536
}
15371537
}
15381538

1539-
fun onCopyLink() {
1539+
fun onCopyChatLink() {
15401540
// TODO: Implement copy link functionality
15411541
}
15421542

15431543
fun onMoveToBin() {
1544-
// TODO: Implement move to bin functionality
1544+
showMoveToBinDialog.value = true
1545+
}
1546+
1547+
fun onMoveToBinConfirmed() {
1548+
viewModelScope.launch {
1549+
setObjectListIsArchived.async(
1550+
SetObjectListIsArchived.Params(
1551+
targets = listOf(vmParams.ctx),
1552+
isArchived = true
1553+
)
1554+
).onSuccess {
1555+
Timber.d("Successfully moved chat to bin")
1556+
showMoveToBinDialog.value = false
1557+
onBackButtonPressed(isExitingVault = false)
1558+
}.onFailure { e ->
1559+
Timber.e(e, "Error while moving chat to bin")
1560+
sendToast("Failed to move chat to bin")
1561+
showMoveToBinDialog.value = false
1562+
}
1563+
}
1564+
}
1565+
1566+
fun onMoveToBinCancelled() {
1567+
showMoveToBinDialog.value = false
15451568
}
15461569

15471570
fun onMediaPreview(objects: List<Id>, index: Int) {

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/presentation/ChatViewModelFactory.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.anytypeio.anytype.domain.notifications.NotificationBuilder
2424
import com.anytypeio.anytype.domain.`object`.GetObject
2525
import com.anytypeio.anytype.domain.objects.CreateObjectFromUrl
2626
import com.anytypeio.anytype.domain.objects.ObjectWatcher
27+
import com.anytypeio.anytype.domain.objects.SetObjectListIsArchived
2728
import com.anytypeio.anytype.domain.objects.StoreOfObjectTypes
2829
import com.anytypeio.anytype.domain.page.CreateObject
2930
import com.anytypeio.anytype.feature_chats.tools.ClearChatsTempFolder
@@ -63,7 +64,8 @@ class ChatViewModelFactory @Inject constructor(
6364
private val analytics: Analytics,
6465
private val spaceInviteLinkStore: SpaceInviteLinkStore,
6566
private val getCurrentInviteAccessLevel: GetCurrentInviteAccessLevel,
66-
private val pinObjectAsWidgetDelegate: PinObjectAsWidgetDelegate
67+
private val pinObjectAsWidgetDelegate: PinObjectAsWidgetDelegate,
68+
private val setObjectListIsArchived: SetObjectListIsArchived
6769
) : ViewModelProvider.Factory {
6870
@Suppress("UNCHECKED_CAST")
6971
override fun <T : ViewModel> create(modelClass: Class<T>): T = ChatViewModel(
@@ -96,6 +98,7 @@ class ChatViewModelFactory @Inject constructor(
9698
discardPreloadedFile = discardPreloadedFile,
9799
spaceInviteLinkStore = spaceInviteLinkStore,
98100
getCurrentInviteAccessLevel = getCurrentInviteAccessLevel,
99-
pinObjectAsWidgetDelegate = pinObjectAsWidgetDelegate
101+
pinObjectAsWidgetDelegate = pinObjectAsWidgetDelegate,
102+
setObjectListIsArchived = setObjectListIsArchived
100103
) as T
101104
}

0 commit comments

Comments
 (0)