Skip to content

Commit

Permalink
Merge pull request #4160 from owncloud/feature/share_to_allows_only_u…
Browse files Browse the repository at this point in the history
…pload_personal_space_1

[FEATURE REQUEST] OCIS: "Share to" allows only upload to personal "space"
  • Loading branch information
Aitorbp authored and jesmrec committed Oct 20, 2023
2 parents 1223427 + ce30b56 commit f78735d
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 110 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/4160
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: "Share to" in oCIS accounts allows upload to any space

With this improvement, shared stuff from other apps can be uploaded to any space and not only the personal one in oCIS accounts.

https://github.com/owncloud/android/issues/4088
https://github.com/owncloud/android/pull/4160
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

package com.owncloud.android.dependecyinjection

import android.accounts.Account

import com.owncloud.android.MainApp
import com.owncloud.android.domain.files.model.FileListOption
import com.owncloud.android.domain.files.model.OCFile
Expand Down Expand Up @@ -85,7 +85,6 @@ val viewModelModule = module {
viewModelOf(::SettingsVideoUploadsViewModel)
viewModelOf(::SettingsViewModel)

viewModel { (account: Account, showPersonalSpace: Boolean) -> SpacesListViewModel(get(), get(), get(), get(), get(), account, showPersonalSpace) }
viewModel { (accountName: String) -> CapabilityViewModel(accountName, get(), get(), get()) }
viewModel { (action: PasscodeAction) -> PassCodeViewModel(get(), get(), action) }
viewModel { (filePath: String, accountName: String) ->
Expand All @@ -100,4 +99,9 @@ val viewModelModule = module {
viewModel { FileOperationsViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { MigrationViewModel(MainApp.dataFolder, get(), get(), get(), get(), get(), get(), get()) }
viewModel { TransfersViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get()) }
viewModel { ReceiveExternalFilesViewModel(get(), get(), get()) }
viewModel { AccountsManagementViewModel(get()) }
viewModel { (accountName: String, showPersonalSpace: Boolean) ->
SpacesListViewModel(get(), get(), get(), get(), get(), accountName, showPersonalSpace)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,24 @@ import com.owncloud.android.extensions.showErrorInSnackbar
import com.owncloud.android.extensions.toDrawableRes
import com.owncloud.android.extensions.toSubtitleStringRes
import com.owncloud.android.extensions.toTitleStringRes
import com.owncloud.android.presentation.authentication.AccountUtils
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf

class SpacesListFragment(
val showPersonalSpace: Boolean = false,
) : SpacesListAdapter.SpacesListAdapterListener, Fragment() {
class SpacesListFragment : SpacesListAdapter.SpacesListAdapterListener, Fragment() {
private var _binding: SpacesListFragmentBinding? = null
private val binding get() = _binding!!


private val spacesListViewModel: SpacesListViewModel by viewModel {
parametersOf(
AccountUtils.getCurrentOwnCloudAccount(context),
showPersonalSpace
requireArguments().getString(BUNDLE_ACCOUNT_NAME),
requireArguments().getBoolean(BUNDLE_SHOW_PERSONAL_SPACE),
)
}

private lateinit var spacesListAdapter: SpacesListAdapter


override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -125,5 +124,17 @@ class SpacesListFragment(
companion object {
const val REQUEST_KEY_CLICK_SPACE = "REQUEST_KEY_CLICK_SPACE"
const val BUNDLE_KEY_CLICK_SPACE = "BUNDLE_KEY_CLICK_SPACE"
const val BUNDLE_SHOW_PERSONAL_SPACE = "showPersonalSpace"
const val BUNDLE_ACCOUNT_NAME = "accountName"
fun newInstance(
showPersonalSpace: Boolean,
accountName: String
): SpacesListFragment {
val args = Bundle().apply {
putBoolean(BUNDLE_SHOW_PERSONAL_SPACE, showPersonalSpace)
putString(BUNDLE_ACCOUNT_NAME, accountName)
}
return SpacesListFragment().apply { arguments = args }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package com.owncloud.android.presentation.spaces

import android.accounts.Account

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.owncloud.android.domain.UseCaseResult
Expand All @@ -43,7 +43,7 @@ class SpacesListViewModel(
private val getProjectSpacesWithSpecialsForAccountAsStreamUseCase: GetProjectSpacesWithSpecialsForAccountAsStreamUseCase,
private val getFileByRemotePathUseCase: GetFileByRemotePathUseCase,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
private val account: Account,
private val accountName: String,
private val showPersonalSpace: Boolean,
) : ViewModel() {

Expand All @@ -55,9 +55,9 @@ class SpacesListViewModel(
viewModelScope.launch(coroutinesDispatcherProvider.io) {
refreshSpacesFromServer()
val spacesListFlow = if (showPersonalSpace) getPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase.execute(
GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase.Params(accountName = account.name)
GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase.Params(accountName = accountName)
) else getProjectSpacesWithSpecialsForAccountAsStreamUseCase.execute(
GetProjectSpacesWithSpecialsForAccountAsStreamUseCase.Params(accountName = account.name)
GetProjectSpacesWithSpecialsForAccountAsStreamUseCase.Params(accountName = accountName)
)
spacesListFlow.collect { spaces ->
_spacesList.update { it.copy(spaces = spaces) }
Expand All @@ -68,7 +68,7 @@ class SpacesListViewModel(
fun refreshSpacesFromServer() {
viewModelScope.launch(coroutinesDispatcherProvider.io) {
_spacesList.update { it.copy(refreshing = true) }
when (val result = refreshSpacesFromServerAsyncUseCase.execute(RefreshSpacesFromServerAsyncUseCase.Params(account.name))) {
when (val result = refreshSpacesFromServerAsyncUseCase.execute(RefreshSpacesFromServerAsyncUseCase.Params(accountName))) {
is UseCaseResult.Success -> _spacesList.update { it.copy(refreshing = false, error = null) }
is UseCaseResult.Error -> _spacesList.update { it.copy(refreshing = false, error = result.throwable) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,32 @@ package com.owncloud.android.ui

import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.domain.spaces.model.OCSpace
import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase
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 com.owncloud.android.usecases.synchronization.SynchronizeFolderUseCase
import kotlinx.coroutines.launch

class ReceiveExternalFilesViewModel(
private val synchronizeFolderUseCase: SynchronizeFolderUseCase,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
private val getPersonalSpaceForAccountUseCase: GetPersonalSpaceForAccountUseCase,
) : ViewModel() {

private val _syncFolderLiveData = MediatorLiveData<Event<UIResult<Unit>>>()
val syncFolderLiveData: LiveData<Event<UIResult<Unit>>> = _syncFolderLiveData

private val _personalSpaceLiveData = MutableLiveData<OCSpace?>()
val personalSpaceLiveData: LiveData<OCSpace?> = _personalSpaceLiveData


fun refreshFolderUseCase(
folderToSync: OCFile,
) = runUseCaseWithResult(
Expand All @@ -49,4 +59,17 @@ class ReceiveExternalFilesViewModel(
syncMode = SynchronizeFolderUseCase.SyncFolderMode.REFRESH_FOLDER
)
)

fun getPersonalSpaceForAccount(accountName: String) {
viewModelScope.launch(coroutinesDispatcherProvider.io) {
val result = getPersonalSpaceForAccountUseCase.execute(
GetPersonalSpaceForAccountUseCase.Params(
accountName = accountName
)
)
_personalSpaceLiveData.postValue(result)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class FileDisplayActivity : FileActivity(),
}

private fun initAndShowListOfSpaces() {
val listOfSpaces = SpacesListFragment()
val listOfSpaces = SpacesListFragment.newInstance(showPersonalSpace = false, accountName = com.owncloud.android.presentation.authentication.AccountUtils.getCurrentOwnCloudAccount(applicationContext).name)
this.fileListOption = FileListOption.SPACES_LIST
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.left_fragment_container, listOfSpaces, TAG_LIST_OF_SPACES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.domain.files.model.FileListOption
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.domain.spaces.model.OCSpace
import com.owncloud.android.presentation.authentication.AccountUtils
import com.owncloud.android.presentation.files.filelist.MainFileListFragment
import com.owncloud.android.presentation.spaces.SpacesListFragment
import com.owncloud.android.ui.fragment.FileFragment
Expand Down Expand Up @@ -248,7 +249,7 @@ open class FolderPickerActivity : FileActivity(),
}

private fun initAndShowListOfSpaces() {
val listOfSpaces = SpacesListFragment(showPersonalSpace = true)
val listOfSpaces = SpacesListFragment.newInstance(showPersonalSpace = true, accountName = AccountUtils.getCurrentOwnCloudAccount(applicationContext).name)
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragment_container, listOfSpaces)
transaction.commit()
Expand Down
Loading

0 comments on commit f78735d

Please sign in to comment.