BIT-481: Implement primary Send UI and sharing (#510)

This commit is contained in:
David Perez
2024-01-06 10:04:49 -06:00
committed by Álison Fernandes
parent 4a39f126dd
commit e0231f511f
5 changed files with 126 additions and 17 deletions

View File

@@ -52,4 +52,15 @@ class IntentHandler(private val context: Context) {
}
startActivity(Intent(Intent.ACTION_VIEW, newUri))
}
/**
* Launches the share sheet with the given [text].
*/
fun shareText(text: String) {
val sendIntent: Intent = Intent(Intent.ACTION_SEND).apply {
putExtra(Intent.EXTRA_TEXT, text)
type = "text/plain"
}
startActivity(Intent.createChooser(sendIntent, null))
}
}

View File

@@ -29,10 +29,12 @@ import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
import com.x8bit.bitwarden.ui.platform.components.BitwardenErrorContent
import com.x8bit.bitwarden.ui.platform.components.BitwardenLoadingContent
import com.x8bit.bitwarden.ui.platform.components.BitwardenLoadingDialog
import com.x8bit.bitwarden.ui.platform.components.BitwardenMediumTopAppBar
import com.x8bit.bitwarden.ui.platform.components.BitwardenOverflowActionItem
import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold
import com.x8bit.bitwarden.ui.platform.components.BitwardenSearchActionItem
import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState
import com.x8bit.bitwarden.ui.platform.components.OverflowMenuItemData
import com.x8bit.bitwarden.ui.tools.feature.send.handlers.SendHandlers
import kotlinx.collections.immutable.persistentListOf
@@ -58,6 +60,10 @@ fun SendScreen(
intentHandler.launchUri("https://bitwarden.com/products/send".toUri())
}
is SendEvent.ShowShareSheet -> {
intentHandler.shareText(event.url)
}
is SendEvent.ShowToast -> {
Toast
.makeText(context, event.message(context.resources), Toast.LENGTH_SHORT)
@@ -66,6 +72,10 @@ fun SendScreen(
}
}
SendDialogs(
dialogState = state.dialogState,
)
val sendHandlers = remember(viewModel) { SendHandlers.create(viewModel) }
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
state = rememberTopAppBarState(),
@@ -159,3 +169,16 @@ fun SendScreen(
}
}
}
@Composable
private fun SendDialogs(
dialogState: SendState.DialogState?,
) {
when (dialogState) {
is SendState.DialogState.Loading -> BitwardenLoadingDialog(
visibilityState = LoadingDialogState.Shown(dialogState.message),
)
null -> Unit
}
}

View File

@@ -43,6 +43,7 @@ class SendViewModel @Inject constructor(
initialState = savedStateHandle[KEY_STATE]
?: SendState(
viewState = SendState.ViewState.Loading,
dialogState = null,
),
) {
@@ -81,6 +82,7 @@ class SendViewModel @Inject constructor(
viewState = SendState.ViewState.Error(
message = R.string.generic_error_message.asText(),
),
dialogState = null,
)
}
}
@@ -94,6 +96,7 @@ class SendViewModel @Inject constructor(
.environmentUrlData
.baseWebSendUrl,
),
dialogState = null,
)
}
}
@@ -112,6 +115,7 @@ class SendViewModel @Inject constructor(
.asText()
.concat(R.string.internet_connection_required_message.asText()),
),
dialogState = null,
)
}
}
@@ -154,7 +158,9 @@ class SendViewModel @Inject constructor(
}
private fun handleSyncClick() {
// TODO: Add loading dialog state BIT-481
mutableStateFlow.update {
it.copy(dialogState = SendState.DialogState.Loading(R.string.syncing.asText()))
}
vaultRepo.sync()
}
@@ -163,22 +169,21 @@ class SendViewModel @Inject constructor(
}
private fun handleSendClick(action: SendAction.SendClick) {
// TODO: Navigate to the edit send screen BIT-??
// TODO: Navigate to the edit send screen (BIT-1387)
sendEvent(SendEvent.ShowToast("Not yet implemented".asText()))
}
private fun handleShareClick(action: SendAction.ShareClick) {
// TODO: Create a link and use the share sheet BIT-??
sendEvent(SendEvent.ShowToast("Not yet implemented".asText()))
sendEvent(SendEvent.ShowShareSheet(action.sendItem.shareUrl))
}
private fun handleFileTypeClick() {
// TODO: Navigate to the file type send list screen BIT-??
// TODO: Navigate to the file type send list screen (BIT-1388)
sendEvent(SendEvent.ShowToast("Not yet implemented".asText()))
}
private fun handleTextTypeClick() {
// TODO: Navigate to the text type send list screen BIT-??
// TODO: Navigate to the text type send list screen (BIT-1388)
sendEvent(SendEvent.ShowToast("Not yet implemented".asText()))
}
}
@@ -189,6 +194,7 @@ class SendViewModel @Inject constructor(
@Parcelize
data class SendState(
val viewState: ViewState,
val dialogState: DialogState?,
) : Parcelable {
/**
@@ -259,6 +265,20 @@ data class SendState(
override val shouldDisplayFab: Boolean get() = false
}
}
/**
* Represents the current state of any dialogs on the screen.
*/
sealed class DialogState : Parcelable {
/**
* Represents a loading dialog with the given [message].
*/
@Parcelize
data class Loading(
val message: Text,
) : DialogState()
}
}
/**
@@ -353,6 +373,11 @@ sealed class SendEvent {
*/
data object NavigateToAboutSend : SendEvent()
/**
* Show a share sheet with the given content.
*/
data class ShowShareSheet(val url: String) : SendEvent()
/**
* Show a toast to the user.
*/