Skip to content

Commit 7299fa1

Browse files
committed
feat: show "+" icon for adding new members only for space managers
1 parent 5027e36 commit 7299fa1

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @author Jorge Aguado Recio
55
*
6-
* Copyright (C) 2025 ownCloud GmbH.
6+
* Copyright (C) 2026 ownCloud GmbH.
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU General Public License version 2,
@@ -96,6 +96,20 @@ class SpaceMembersFragment : Fragment() {
9696
}
9797
}
9898

99+
collectLatestLifecycleFlow(spaceMembersViewModel.spacePermissions) { event ->
100+
event?.let {
101+
when (val uiResult = event.peekContent()) {
102+
is UIResult.Success -> {
103+
uiResult.data?.let { spacePermissions ->
104+
if (DRIVES_CREATE_PERMISSION in spacePermissions) { binding.addMemberButton.visibility = View.VISIBLE }
105+
}
106+
}
107+
is UIResult.Loading -> { }
108+
is UIResult.Error -> { }
109+
}
110+
}
111+
}
112+
99113
val currentSpace = requireArguments().getParcelable<OCSpace>(ARG_CURRENT_SPACE) ?: return
100114
binding.apply {
101115
itemName.text = currentSpace.name
@@ -118,6 +132,7 @@ class SpaceMembersFragment : Fragment() {
118132
companion object {
119133
private const val ARG_CURRENT_SPACE = "CURRENT_SPACE"
120134
private const val ARG_ACCOUNT_NAME = "ACCOUNT_NAME"
135+
private const val DRIVES_CREATE_PERMISSION = "libre.graph/driveItem/permissions/create"
121136

122137
fun newInstance(
123138
accountName: String,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @author Jorge Aguado Recio
55
*
6-
* Copyright (C) 2025 ownCloud GmbH.
6+
* Copyright (C) 2026 ownCloud GmbH.
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU General Public License version 2,
@@ -26,6 +26,7 @@ import com.owncloud.android.domain.spaces.model.OCSpace
2626
import com.owncloud.android.domain.spaces.model.SpaceMembers
2727
import com.owncloud.android.domain.spaces.usecases.GetSpaceMembersUseCase
2828
import com.owncloud.android.domain.roles.usecases.GetRolesAsyncUseCase
29+
import com.owncloud.android.domain.spaces.usecases.GetSpacePermissionsAsyncUseCase
2930
import com.owncloud.android.domain.utils.Event
3031
import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult
3132
import com.owncloud.android.presentation.common.UIResult
@@ -36,6 +37,7 @@ import kotlinx.coroutines.flow.StateFlow
3637
class SpaceMembersViewModel(
3738
private val getRolesAsyncUseCase: GetRolesAsyncUseCase,
3839
private val getSpaceMembersUseCase: GetSpaceMembersUseCase,
40+
private val getSpacePermissionsAsyncUseCase: GetSpacePermissionsAsyncUseCase,
3941
private val accountName: String,
4042
private val space: OCSpace,
4143
private val coroutineDispatcherProvider: CoroutinesDispatcherProvider
@@ -47,6 +49,9 @@ class SpaceMembersViewModel(
4749
private val _spaceMembers = MutableStateFlow<Event<UIResult<SpaceMembers>>?>(null)
4850
val spaceMembers: StateFlow<Event<UIResult<SpaceMembers>>?> = _spaceMembers
4951

52+
private val _spacePermissions = MutableStateFlow<Event<UIResult<List<String>>>?>(null)
53+
val spacePermissions: StateFlow<Event<UIResult<List<String>>>?> = _spacePermissions
54+
5055
init {
5156
runUseCaseWithResult(
5257
coroutineDispatcher = coroutineDispatcherProvider.io,
@@ -56,6 +61,16 @@ class SpaceMembersViewModel(
5661
showLoading = false,
5762
requiresConnection = true
5863
)
64+
65+
runUseCaseWithResult(
66+
coroutineDispatcher = coroutineDispatcherProvider.io,
67+
flow = _spacePermissions,
68+
useCase = getSpacePermissionsAsyncUseCase,
69+
useCaseParams = GetSpacePermissionsAsyncUseCase.Params(accountName = accountName, spaceId = space.id),
70+
showLoading = false,
71+
requiresConnection = true
72+
)
73+
5974
}
6075

6176
fun getSpaceMembers() = runUseCaseWithResult(

owncloudApp/src/main/res/layout/members_fragment.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?><!--
22
ownCloud Android client application
33
4-
Copyright (C) 2025 ownCloud GmbH.
4+
Copyright (C) 2026 ownCloud GmbH.
55
66
This program is free software: you can redistribute it and/or modify
77
it under the terms of the GNU General Public License version 2,
@@ -98,6 +98,21 @@
9898
app:layout_constraintStart_toStartOf="parent"
9999
app:layout_constraintTop_toTopOf="parent"/>
100100

101+
<ImageButton
102+
android:id="@+id/add_member_button"
103+
android:layout_width="48dp"
104+
android:layout_height="48dp"
105+
android:padding="12dp"
106+
android:background="@color/transparent"
107+
android:src="@drawable/ic_add"
108+
android:contentDescription="@string/content_description_add_member"
109+
android:visibility="gone"
110+
android:focusable="true"
111+
android:clickable="true"
112+
app:layout_constraintEnd_toEndOf="parent"
113+
app:layout_constraintTop_toTopOf="parent"
114+
tools:visibility="visible"/>
115+
101116
</androidx.constraintlayout.widget.ConstraintLayout>
102117

103118
<androidx.recyclerview.widget.RecyclerView

owncloudApp/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@
830830
<string name="content_description_member_user">User %1$s</string>
831831
<string name="content_description_member_group">Group %1$s</string>
832832
<string name="content_description_member_expiration_date">Expires %1$s</string>
833+
<string name="content_description_add_member">Add new member</string>
833834

834835
<string name="create_shortcut_dialog_title">Create a shortcut</string>
835836
<string name="create_shortcut_dialog_url">URL</string>

0 commit comments

Comments
 (0)