mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2376 Multiplayer | Enhancement | Show warning when attempting to stop space sharing (#1068)
This commit is contained in:
parent
dd53903e10
commit
ce15843313
4 changed files with 99 additions and 6 deletions
|
@ -23,6 +23,7 @@ import com.anytypeio.anytype.core_utils.ext.toast
|
|||
import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetComposeFragment
|
||||
import com.anytypeio.anytype.di.common.componentManager
|
||||
import com.anytypeio.anytype.presentation.multiplayer.ShareSpaceViewModel
|
||||
import com.anytypeio.anytype.presentation.multiplayer.ShareSpaceViewModel.Command
|
||||
import com.anytypeio.anytype.ui.settings.typography
|
||||
import javax.inject.Inject
|
||||
import timber.log.Timber
|
||||
|
@ -83,9 +84,9 @@ class ShareSpaceFragment : BaseBottomSheetComposeFragment() {
|
|||
expand()
|
||||
}
|
||||
|
||||
private fun proceedWithCommand(command: ShareSpaceViewModel.Command) {
|
||||
private fun proceedWithCommand(command: Command) {
|
||||
when (command) {
|
||||
is ShareSpaceViewModel.Command.ShareInviteLink -> {
|
||||
is Command.ShareInviteLink -> {
|
||||
val intent = Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_TEXT, command.link)
|
||||
|
@ -93,7 +94,8 @@ class ShareSpaceFragment : BaseBottomSheetComposeFragment() {
|
|||
}
|
||||
startActivity(Intent.createChooser(intent, null))
|
||||
}
|
||||
is ShareSpaceViewModel.Command.ShareQrCode -> {
|
||||
|
||||
is Command.ShareQrCode -> {
|
||||
runCatching {
|
||||
findNavController().navigate(
|
||||
resId = R.id.shareSpaceInviteQrCodeScreen,
|
||||
|
@ -105,7 +107,8 @@ class ShareSpaceFragment : BaseBottomSheetComposeFragment() {
|
|||
Timber.d(it, "Error while navigation")
|
||||
}
|
||||
}
|
||||
is ShareSpaceViewModel.Command.ViewJoinRequest -> {
|
||||
|
||||
is Command.ViewJoinRequest -> {
|
||||
runCatching {
|
||||
findNavController().navigate(
|
||||
resId = R.id.spaceJoinRequestScreen,
|
||||
|
@ -118,14 +121,33 @@ class ShareSpaceFragment : BaseBottomSheetComposeFragment() {
|
|||
Timber.e(it, "Error while navigation")
|
||||
}
|
||||
}
|
||||
is ShareSpaceViewModel.Command.ShowHowToShareSpace -> {
|
||||
|
||||
is Command.ShowHowToShareSpace -> {
|
||||
runCatching {
|
||||
findNavController().navigate(R.id.howToShareSpaceScreen)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while navigation")
|
||||
}
|
||||
}
|
||||
is ShareSpaceViewModel.Command.Dismiss -> {
|
||||
|
||||
is Command.ShowStopSharingWarning -> {
|
||||
runCatching {
|
||||
val dialog = StopSharingWarning()
|
||||
dialog.onAccepted = {
|
||||
vm.onStopSharingAccepted().also {
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
dialog.onCancelled = {
|
||||
// Do nothing.
|
||||
}
|
||||
dialog.show(childFragmentManager, null)
|
||||
}.onFailure {
|
||||
Timber.e(it, "Error while navigation")
|
||||
}
|
||||
}
|
||||
|
||||
is Command.Dismiss -> {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.anytypeio.anytype.ui.multiplayer
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import com.anytypeio.anytype.R
|
||||
import com.anytypeio.anytype.core_ui.foundation.Warning
|
||||
import com.anytypeio.anytype.core_utils.ui.BaseBottomSheetComposeFragment
|
||||
import com.anytypeio.anytype.ui.settings.typography
|
||||
|
||||
class StopSharingWarning : BaseBottomSheetComposeFragment() {
|
||||
|
||||
var onAccepted: () -> Unit = {}
|
||||
var onCancelled: () -> Unit = {}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
return ComposeView(requireContext()).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
setContent {
|
||||
MaterialTheme(typography = typography) {
|
||||
Warning(
|
||||
actionButtonText = stringResource(R.string.multiplayer_space_stop_sharing),
|
||||
cancelButtonText = stringResource(R.string.cancel),
|
||||
title = stringResource(R.string.multiplayer_space_stop_sharing),
|
||||
subtitle = stringResource(R.string.multiplayer_space_stop_sharing_space_description),
|
||||
onNegativeClick = {
|
||||
onCancelled()
|
||||
dismiss()
|
||||
},
|
||||
onPositiveClick = { onAccepted() },
|
||||
isInProgress = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun injectDependencies() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
override fun releaseDependencies() {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
|
@ -1330,6 +1330,8 @@
|
|||
<string name="multiplayer_remove_member">Remove member</string>
|
||||
<string name="multiplayer_request_sent_toast">Request sent</string>
|
||||
<string name="multiplayer_space_stop_sharing">Stop sharing</string>
|
||||
<string name="multiplayer_space_stop_sharing_space">Stop sharing the space</string>
|
||||
<string name="multiplayer_space_stop_sharing_space_description">Participants will no longer sync to this space and the share link will be deactivated.</string>
|
||||
<string name="multiplayer_more_info">More info</string>
|
||||
<string name="multiplayer_sharing">Sharing</string>
|
||||
<string name="multiplayer_share">Share</string>
|
||||
|
|
|
@ -305,6 +305,19 @@ class ShareSpaceViewModel(
|
|||
|
||||
fun onStopSharingSpaceClicked() {
|
||||
Timber.d("onStopSharingClicked")
|
||||
viewModelScope.launch {
|
||||
if (isCurrentUserOwner.value && shareLinkViewState.value is ShareLinkViewState.Shared) {
|
||||
viewModelScope.launch {
|
||||
commands.emit(Command.ShowStopSharingWarning)
|
||||
}
|
||||
} else {
|
||||
Timber.w("Something wrong with permissions.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onStopSharingAccepted() {
|
||||
Timber.d("onStopSharingAccepted")
|
||||
viewModelScope.launch {
|
||||
if (isCurrentUserOwner.value && shareLinkViewState.value is ShareLinkViewState.Shared) {
|
||||
stopSharingSpace.async(
|
||||
|
@ -387,6 +400,7 @@ class ShareSpaceViewModel(
|
|||
data class ShareQrCode(val link: String) : Command()
|
||||
data class ViewJoinRequest(val space: SpaceId, val member: Id) : Command()
|
||||
data object ShowHowToShareSpace: Command()
|
||||
data object ShowStopSharingWarning: Command()
|
||||
data object Dismiss : Command()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue