Skip to content

Commit

Permalink
feat: hack to retrieve only personal spaces in multi-personal accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
JuancaG05 committed Nov 26, 2024
1 parent 639484f commit 8c75995
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import com.owncloud.android.domain.sharing.shares.usecases.RefreshSharesFromServ
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesForAccountUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalSpaceForAccountUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.GetProjectSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.GetSpaceByIdForAccountUseCase
import com.owncloud.android.domain.spaces.usecases.GetSpaceWithSpecialsByIdForAccountUseCase
Expand Down Expand Up @@ -218,6 +219,7 @@ val useCaseModule = module {
factoryOf(::GetPersonalAndProjectSpacesForAccountUseCase)
factoryOf(::GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase)
factoryOf(::GetPersonalSpaceForAccountUseCase)
factoryOf(::GetPersonalSpacesWithSpecialsForAccountAsStreamUseCase)
factoryOf(::GetProjectSpacesWithSpecialsForAccountAsStreamUseCase)
factoryOf(::GetSpaceWithSpecialsByIdForAccountUseCase)
factoryOf(::GetSpacesFromEveryAccountUseCaseAsStream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ val viewModelModule = module {
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 { (accountName: String, showPersonalSpace: Boolean) ->
SpacesListViewModel(get(), get(), get(), get(), get(), accountName, showPersonalSpace)
viewModel { (accountName: String, showPersonalSpace: Boolean, isMultiPersonal: Boolean) ->
SpacesListViewModel(get(), get(), get(), get(), get(), get(), accountName, showPersonalSpace, isMultiPersonal)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class MainFileListFragment : Fragment(),
parametersOf(
requireArguments().getString(ARG_ACCOUNT_NAME),
false,
false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.owncloud.android.utils.PreferenceUtils

class SpacesListAdapter(
private val listener: SpacesListAdapterListener,
private val isMultiPersonal: Boolean,
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private val spacesList = mutableListOf<OCSpace>()
Expand All @@ -59,7 +60,7 @@ class SpacesListAdapter(
}
spacesListItemCard.setAccessibilityRole(className = Button::class.java)

if (space.isPersonal) {
if (space.isPersonal && !isMultiPersonal) {
spacesListItemName.text = holder.itemView.context.getString(R.string.bottom_nav_personal)
spacesListItemImage.apply {
dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SpacesListFragment : SpacesListAdapter.SpacesListAdapterListener, Fragment
parametersOf(
requireArguments().getString(BUNDLE_ACCOUNT_NAME),
requireArguments().getBoolean(BUNDLE_SHOW_PERSONAL_SPACE),
true,
)
}

Expand All @@ -78,7 +79,7 @@ class SpacesListFragment : SpacesListAdapter.SpacesListAdapterListener, Fragment

val spacesListLayoutManager = GridLayoutManager(requireContext(), 2)
binding.recyclerSpacesList.layoutManager = spacesListLayoutManager
spacesListAdapter = SpacesListAdapter(this)
spacesListAdapter = SpacesListAdapter(this, true)
binding.recyclerSpacesList.adapter = spacesListAdapter

binding.swipeRefreshSpacesList.setOnRefreshListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

package com.owncloud.android.presentation.spaces


import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.owncloud.android.domain.UseCaseResult
Expand All @@ -30,6 +29,7 @@ import com.owncloud.android.domain.files.model.OCFile.Companion.ROOT_PATH
import com.owncloud.android.domain.files.usecases.GetFileByRemotePathUseCase
import com.owncloud.android.domain.spaces.model.OCSpace
import com.owncloud.android.domain.spaces.usecases.GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.GetPersonalSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.GetProjectSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.RefreshSpacesFromServerAsyncUseCase
import com.owncloud.android.providers.CoroutinesDispatcherProvider
Expand All @@ -40,12 +40,14 @@ import kotlinx.coroutines.launch

class SpacesListViewModel(
private val refreshSpacesFromServerAsyncUseCase: RefreshSpacesFromServerAsyncUseCase,
private val getPersonalSpacesWithSpecialsForAccountAsStreamUseCase: GetPersonalSpacesWithSpecialsForAccountAsStreamUseCase,
private val getPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase: GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase,
private val getProjectSpacesWithSpecialsForAccountAsStreamUseCase: GetProjectSpacesWithSpecialsForAccountAsStreamUseCase,
private val getFileByRemotePathUseCase: GetFileByRemotePathUseCase,
private val coroutinesDispatcherProvider: CoroutinesDispatcherProvider,
private val accountName: String,
private val showPersonalSpace: Boolean,
private val isMultiPersonal: Boolean,
) : ViewModel() {

private val _spacesList: MutableStateFlow<SpacesListUiState> =
Expand All @@ -55,7 +57,9 @@ class SpacesListViewModel(
init {
viewModelScope.launch(coroutinesDispatcherProvider.io) {
refreshSpacesFromServer()
val spacesListFlow = if (showPersonalSpace) getPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase(
val spacesListFlow = if (isMultiPersonal) getPersonalSpacesWithSpecialsForAccountAsStreamUseCase(
GetPersonalSpacesWithSpecialsForAccountAsStreamUseCase.Params(accountName = accountName)
) else if (showPersonalSpace) getPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase(
GetPersonalAndProjectSpacesWithSpecialsForAccountAsStreamUseCase.Params(accountName = accountName)
) else getProjectSpacesWithSpecialsForAccountAsStreamUseCase(
GetProjectSpacesWithSpecialsForAccountAsStreamUseCase.Params(accountName = accountName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class FileDisplayActivity : FileActivity(),
}
}

spacesListViewModel = getViewModel { parametersOf(account.name, false) }
spacesListViewModel = getViewModel { parametersOf(account.name, false, false) }
spacesListViewModel.refreshSpacesFromServer()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class PreviewImageActivity : FileActivity(),
is UIResult.Success -> {

// Refresh the spaces and update the quota
val spacesListViewModel: SpacesListViewModel by viewModel { parametersOf(account.name, false) }
val spacesListViewModel: SpacesListViewModel by viewModel { parametersOf(account.name, false, false) }
spacesListViewModel.refreshSpacesFromServer()

dismissLoadingDialog()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay
is UIResult.Success -> {

// Refresh the spaces and update the quota
val spacesListViewModel: SpacesListViewModel by viewModel { parametersOf(account?.name, false) }
val spacesListViewModel: SpacesListViewModel by viewModel { parametersOf(account?.name, false, false) }
spacesListViewModel.refreshSpacesFromServer()

dismissLoadingDialog()
Expand Down
2 changes: 1 addition & 1 deletion owncloudApp/src/main/res/layout/spaces_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
android:id="@+id/spaces_list_item_image"
android:layout_width="match_parent"
android:layout_height="@dimen/spaces_thumbnail_height"
android:scaleType="centerCrop"
android:scaleType="fitCenter"
android:src="@drawable/ic_spaces" />

<View
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* ownCloud Android client application
*
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2024 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.domain.spaces.usecases

import com.owncloud.android.domain.BaseUseCase
import com.owncloud.android.domain.spaces.SpacesRepository
import com.owncloud.android.domain.spaces.model.OCSpace
import kotlinx.coroutines.flow.Flow

class GetPersonalSpacesWithSpecialsForAccountAsStreamUseCase(
private val spacesRepository: SpacesRepository
) : BaseUseCase<Flow<List<OCSpace>>, GetPersonalSpacesWithSpecialsForAccountAsStreamUseCase.Params>() {

override fun run(params: Params) = spacesRepository.getSpacesByDriveTypeWithSpecialsForAccountAsFlow(
accountName = params.accountName,
filterDriveTypes = setOf(OCSpace.DRIVE_TYPE_PERSONAL),
)

data class Params(
val accountName: String
)
}

0 comments on commit 8c75995

Please sign in to comment.