Skip to content

Commit a5263f7

Browse files
committed
refactor: run password update only after successful link edit
1 parent e818d2e commit a5263f7

3 files changed

Lines changed: 39 additions & 12 deletions

File tree

owncloudApp/src/main/java/com/owncloud/android/presentation/spaces/links/AddPublicLinkFragment.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ class AddPublicLinkFragment: Fragment(), SetPasswordDialogFragment.SetPasswordLi
140140
event?.peekContent()?.let { uiResult ->
141141
when (uiResult) {
142142
is UIResult.Loading -> { }
143-
is UIResult.Success -> parentFragmentManager.popBackStack()
144-
is UIResult.Error -> showErrorInSnackbar(R.string.public_link_edit_failed, uiResult.error)
143+
is UIResult.Success -> {
144+
selectedPublicLink?.let { spaceLinksViewModel.editPasswordPublicLink(it.id) }
145+
parentFragmentManager.popBackStack()
146+
}
147+
is UIResult.Error -> {
148+
showErrorInSnackbar(R.string.public_link_edit_failed, uiResult.error)
149+
}
145150
}
146151
}
147152
}

owncloudApp/src/main/java/com/owncloud/android/presentation/spaces/links/SpaceLinksViewModel.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class SpaceLinksViewModel(
6565
private val _editLinkResultFlow = MutableStateFlow<Event<UIResult<Unit>>?>(null)
6666
val editLinkResultFlow: StateFlow<Event<UIResult<Unit>>?> = _editLinkResultFlow
6767

68+
private val _editPasswordLinkResultFlow = MutableStateFlow<Event<UIResult<Unit>>?>(null)
69+
val editPasswordLinkResultFlow: StateFlow<Event<UIResult<Unit>>?> = _editPasswordLinkResultFlow
70+
6871
private var capabilities: OCCapability? = null
6972

7073
init {
@@ -132,16 +135,22 @@ class SpaceLinksViewModel(
132135
expirationDate = _addPublicLinkUIState.value?.selectedExpirationDate,
133136
)
134137
)
135-
if (_addPublicLinkUIState.value?.wasPasswordChanged == true) {
136-
viewModelScope.launch(coroutineDispatcherProvider.io) {
137-
editPasswordLinkUseCase(EditPasswordLinkUseCase.Params(
138-
accountName = accountName,
139-
spaceId = space.id,
140-
linkId = linkId,
141-
password = _addPublicLinkUIState.value?.selectedPassword
142-
))
143-
}
144-
}
138+
}
139+
}
140+
141+
fun editPasswordPublicLink(linkId: String) {
142+
if (_addPublicLinkUIState.value?.wasPasswordChanged == true) {
143+
runUseCaseWithResult(
144+
coroutineDispatcher = coroutineDispatcherProvider.io,
145+
flow = _editLinkResultFlow,
146+
useCase = editPasswordLinkUseCase,
147+
useCaseParams = EditPasswordLinkUseCase.Params(
148+
accountName = accountName,
149+
spaceId = space.id,
150+
linkId = linkId,
151+
password = _addPublicLinkUIState.value?.selectedPassword
152+
)
153+
)
145154
}
146155
}
147156

owncloudApp/src/main/java/com/owncloud/android/presentation/spaces/members/SpaceMembersFragment.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ class SpaceMembersFragment : Fragment(), SpaceMembersAdapter.SpaceMembersAdapter
220220
observeAddLinkResult()
221221
observeRemoveLinkResult()
222222
observeEditLinkResult()
223+
observeEditPasswordLinkResult()
223224
}
224225

225226
private fun observeRoles() {
@@ -385,6 +386,18 @@ class SpaceMembersFragment : Fragment(), SpaceMembersAdapter.SpaceMembersAdapter
385386
}
386387
}
387388

389+
private fun observeEditPasswordLinkResult() {
390+
collectLatestLifecycleFlow(spaceLinksViewModel.editPasswordLinkResultFlow) { event ->
391+
event?.peekContent()?.let { uiResult ->
392+
when (uiResult) {
393+
is UIResult.Loading -> { }
394+
is UIResult.Success -> spaceLinksViewModel.resetViewModel()
395+
is UIResult.Error -> showErrorInSnackbar(R.string.public_link_edit_failed, uiResult.error)
396+
}
397+
}
398+
}
399+
}
400+
388401
private fun checkPermissions(spacePermissions: List<String>) {
389402
val hasCreatePermission = DRIVES_CREATE_PERMISSION in spacePermissions
390403
canRemoveMembersAndLinks = DRIVES_DELETE_PERMISSION in spacePermissions

0 commit comments

Comments
 (0)