Repository navigation
feat: implement UI for listing oCIS shares #4945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f75dab9
feat: implement UI for listing oCIS shares
joragua 6194edf
feat: implement methods for oCIS shares listing
joragua d40a8b7
feat: add pull-to-refresh to the oCIS shares list
joragua 8341da7
test: create new tests for OCRemoteShareDataSource and OCShareRepository
joragua 75c6caf
refactor: rename permission models to clarify
joragua f075a4c
refactor: rename Ocis prefix to Graph in new share classes
joragua 8a2ef01
chore: add calens file
joragua 97cbde3
feat: add release note
joragua 6f129f9
fix: validate file data before retrieving shares
joragua 2efadba
fix: sort shares by type and display name
joragua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Enhancement: List shares for oCIS accounts | ||
|
|
||
| A new UI has been implemented to list and show information about the | ||
| shares of a file or folder on oCIS accounts (using Graph API) | ||
|
|
||
| https://github.com/owncloud/android/issues/4876 | ||
| https://github.com/owncloud/android/pull/4945 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/GraphShareFragment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /** | ||
| * ownCloud Android client application | ||
| * | ||
| * @author Jorge Aguado Recio | ||
| * | ||
| * Copyright (C) 2026 ownCloud GmbH. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.owncloud.android.presentation.sharing | ||
|
|
||
| import android.os.Bundle | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.core.view.isVisible | ||
| import androidx.fragment.app.Fragment | ||
| import androidx.recyclerview.widget.LinearLayoutManager | ||
| import com.owncloud.android.R | ||
| import com.owncloud.android.databinding.MembersFragmentBinding | ||
| import com.owncloud.android.domain.files.model.OCFile | ||
| import com.owncloud.android.domain.roles.model.OCRole | ||
| import com.owncloud.android.extensions.collectLatestLifecycleFlow | ||
| import com.owncloud.android.extensions.showErrorInSnackbar | ||
| import com.owncloud.android.presentation.common.UIResult | ||
| import org.koin.androidx.viewmodel.ext.android.viewModel | ||
| import org.koin.core.parameter.parametersOf | ||
| import timber.log.Timber | ||
|
|
||
| class GraphShareFragment : Fragment() { | ||
| private var _binding: MembersFragmentBinding? = null | ||
| private val binding get() = _binding!! | ||
|
|
||
| private val graphShareViewModel by viewModel<GraphShareViewModel> { | ||
| parametersOf( | ||
| requireArguments().getString(ARG_ACCOUNT_NAME), | ||
| requireArguments().getParcelable<OCFile>(ARG_FILE) | ||
| ) | ||
| } | ||
|
|
||
| private lateinit var graphSharesAdapter: GraphSharesAdapter | ||
|
|
||
| private var roles: List<OCRole> = emptyList() | ||
|
|
||
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
| _binding = MembersFragmentBinding.inflate(inflater, container, false) | ||
| return binding.root | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| binding.membersTitle.text = getString(R.string.share_with_people_title) | ||
|
|
||
| graphSharesAdapter = GraphSharesAdapter() | ||
| binding.membersRecyclerView.apply { | ||
| layoutManager = LinearLayoutManager(requireContext()) | ||
| adapter = graphSharesAdapter | ||
| } | ||
|
|
||
| binding.swipeRefreshMembers.setOnRefreshListener { | ||
| graphShareViewModel.getGraphShares() | ||
| } | ||
|
|
||
| subscribeToViewModels() | ||
| } | ||
|
|
||
| override fun onDestroyView() { | ||
| super.onDestroyView() | ||
| _binding = null | ||
| } | ||
|
|
||
| private fun subscribeToViewModels() { | ||
| observeRoles() | ||
| observeShares() | ||
| } | ||
|
|
||
| private fun observeRoles() { | ||
| collectLatestLifecycleFlow(graphShareViewModel.roles) { event -> | ||
| event?.let { | ||
| when (val uiResult = event.peekContent()) { | ||
| is UIResult.Success -> { | ||
| uiResult.data?.let { | ||
| roles = it | ||
| graphShareViewModel.getGraphShares() | ||
| } | ||
| } | ||
| is UIResult.Loading -> { } | ||
| is UIResult.Error -> { | ||
| showErrorInSnackbar(R.string.share_sync_failed, uiResult.error) | ||
| Timber.e(uiResult.error, "Failed to retrieve platform roles") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun observeShares() { | ||
| collectLatestLifecycleFlow(graphShareViewModel.shares) { event -> | ||
| event?.let { | ||
| when (val uiResult = event.peekContent()) { | ||
| is UIResult.Success -> { | ||
| uiResult.data?.let { | ||
| val hasMembers = it.members.isNotEmpty() | ||
| binding.membersRecyclerView.isVisible = hasMembers | ||
| binding.noSharesMessage.isVisible = !hasMembers | ||
| graphSharesAdapter.setShares(it.members, it.roles) | ||
| binding.swipeRefreshMembers.isRefreshing = false | ||
| } | ||
| } | ||
| is UIResult.Loading -> { binding.swipeRefreshMembers.isRefreshing = true } | ||
| is UIResult.Error -> { | ||
| binding.swipeRefreshMembers.isRefreshing = false | ||
| showErrorInSnackbar(R.string.share_sync_failed, uiResult.error) | ||
| Timber.e(uiResult.error, "Failed to retrieve shares") | ||
|
jesmrec marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private const val ARG_FILE = "FILE" | ||
| private const val ARG_ACCOUNT_NAME = "ACCOUNT_NAME" | ||
|
|
||
| fun newInstance(file: OCFile, accountName: String): GraphShareFragment { | ||
| val args = Bundle().apply { | ||
| putParcelable(ARG_FILE, file) | ||
| putString(ARG_ACCOUNT_NAME, accountName) | ||
| } | ||
| return GraphShareFragment().apply { | ||
| arguments = args | ||
| } | ||
| } | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
owncloudApp/src/main/java/com/owncloud/android/presentation/sharing/GraphShareViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * ownCloud Android client application | ||
| * | ||
| * @author Jorge Aguado Recio | ||
| * | ||
| * Copyright (C) 2026 ownCloud GmbH. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License version 2, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.owncloud.android.presentation.sharing | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import com.owncloud.android.domain.exceptions.IncompleteFileDataException | ||
| import com.owncloud.android.domain.files.model.OCFile | ||
| import com.owncloud.android.domain.roles.model.OCRole | ||
| import com.owncloud.android.domain.roles.usecases.GetRolesAsyncUseCase | ||
| import com.owncloud.android.domain.sharing.shares.usecases.GetGraphSharesAsyncUseCase | ||
| import com.owncloud.android.domain.sharing.shares.model.OCPermissions | ||
| import com.owncloud.android.domain.utils.Event | ||
| import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult | ||
| import com.owncloud.android.presentation.common.UIResult | ||
| import com.owncloud.android.providers.CoroutinesDispatcherProvider | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
| import kotlinx.coroutines.flow.update | ||
|
|
||
| class GraphShareViewModel( | ||
| private val getRolesAsyncUseCase: GetRolesAsyncUseCase, | ||
| private val getGraphSharesAsyncUseCase: GetGraphSharesAsyncUseCase, | ||
| private val accountName: String, | ||
| private val file: OCFile, | ||
| private val coroutineDispatcherProvider: CoroutinesDispatcherProvider, | ||
| ) : ViewModel() { | ||
|
|
||
| private val _roles = MutableStateFlow<Event<UIResult<List<OCRole>>>?>(null) | ||
| val roles: StateFlow<Event<UIResult<List<OCRole>>>?> = _roles | ||
|
|
||
| private val _shares = MutableStateFlow<Event<UIResult<OCPermissions>>?>(null) | ||
| val shares: StateFlow<Event<UIResult<OCPermissions>>?> = _shares | ||
|
|
||
| init { | ||
| runUseCaseWithResult( | ||
| coroutineDispatcher = coroutineDispatcherProvider.io, | ||
| flow = _roles, | ||
| useCase = getRolesAsyncUseCase, | ||
| useCaseParams = GetRolesAsyncUseCase.Params(accountName = accountName), | ||
| ) | ||
| } | ||
|
|
||
| fun getGraphShares() { | ||
| val spaceId = file.spaceId | ||
| val itemId = file.remoteId | ||
| if (spaceId == null || itemId == null) { | ||
| _shares.update { Event(UIResult.Error(error = IncompleteFileDataException())) } | ||
| return | ||
| } | ||
|
|
||
| runUseCaseWithResult( | ||
| coroutineDispatcher = coroutineDispatcherProvider.io, | ||
| showLoading = true, | ||
| flow = _shares, | ||
| useCase = getGraphSharesAsyncUseCase, | ||
| useCaseParams = GetGraphSharesAsyncUseCase.Params( | ||
| accountName = accountName, | ||
| spaceId = spaceId, | ||
| itemId = itemId | ||
| ) | ||
| ) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.