Skip to content

Commit

Permalink
Merge pull request #3843 from owncloud/spaces/fetch_spaces
Browse files Browse the repository at this point in the history
[SPACES] Create new "Spaces" view
  • Loading branch information
JuancaG05 authored Jan 11, 2023
2 parents f5b234d + 2edfe5d commit 65b5050
Show file tree
Hide file tree
Showing 34 changed files with 1,631 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.owncloud.android.R;
import com.owncloud.android.domain.files.model.OCFile;
import com.owncloud.android.domain.files.usecases.DisableThumbnailsForFileUseCase;
import com.owncloud.android.domain.spaces.model.SpaceSpecial;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.SingleSessionManager;
Expand Down Expand Up @@ -75,6 +76,7 @@ public class ThumbnailsCacheManager {
private static OwnCloudClient mClient = null;

private static final String PREVIEW_URI = "%s/remote.php/dav/files/%s%s?x=%d&y=%d&c=%s&preview=1";
private static final String SPACE_SPECIAL_URI = "%s?scalingup=0&a=1&x=%d&y=%d&c=%s&preview=1";

public static Bitmap mDefaultImg =
BitmapFactory.decodeResource(
Expand Down Expand Up @@ -186,6 +188,8 @@ protected Bitmap doInBackground(Object... params) {
thumbnail = doOCFileInBackground();
} else if (mFile instanceof File) {
thumbnail = doFileInBackground();
} else if (mFile instanceof SpaceSpecial) {
thumbnail = doSpaceImageInBackground();
//} else { do nothing
}

Expand All @@ -210,6 +214,8 @@ protected void onPostExecute(Bitmap bitmap) {
tagId = String.valueOf(((OCFile) mFile).getId());
} else if (mFile instanceof File) {
tagId = String.valueOf(mFile.hashCode());
} else if (mFile instanceof SpaceSpecial) {
tagId = ((SpaceSpecial) mFile).getId();
}
if (String.valueOf(imageView.getTag()).equals(tagId)) {
imageView.setImageBitmap(bitmap);
Expand Down Expand Up @@ -349,6 +355,61 @@ private Bitmap doFileInBackground() {
return thumbnail;
}

private String getSpaceSpecialUri(SpaceSpecial spaceSpecial) {
return String.format(Locale.ROOT,
SPACE_SPECIAL_URI,
spaceSpecial.getWebDavUrl(),
getThumbnailDimension(),
getThumbnailDimension(),
spaceSpecial.getETag());
}

private Bitmap doSpaceImageInBackground() {
SpaceSpecial spaceSpecial = (SpaceSpecial) mFile;

final String imageKey = spaceSpecial.getId();

// Check disk cache in background thread
Bitmap thumbnail = getBitmapFromDiskCache(imageKey);

// Not found in disk cache
if (thumbnail == null) { // TODO: Check if the current thumbnail is outdated
int px = getThumbnailDimension();

// Download thumbnail from server
if (mClient != null) {
GetMethod get;
try {
String uri = getSpaceSpecialUri(spaceSpecial);
Timber.d("URI: %s", uri);
get = new GetMethod(new URL(uri));
int status = mClient.executeHttpMethod(get);
if (status == HttpConstants.HTTP_OK) {
InputStream inputStream = get.getResponseBodyAsStream();
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);

// Handle PNG
if (spaceSpecial.getFile().getMimeType().equalsIgnoreCase("image/png")) {
thumbnail = handlePNG(thumbnail, px);
}

// Add thumbnail to cache
if (thumbnail != null) {
addBitmapToCache(imageKey, thumbnail);
}
} else {
mClient.exhaustResponse(get.getResponseBodyAsStream());
}
} catch (Exception e) {
Timber.e(e);
}
}
}

return thumbnail;

}
}

public static boolean cancelPotentialThumbnailWork(Object file, ImageView imageView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import com.owncloud.android.data.preferences.datasources.SharedPreferencesProvid
import com.owncloud.android.data.preferences.datasources.implementation.OCSharedPreferencesProvider
import com.owncloud.android.data.sharing.shares.datasources.LocalShareDataSource
import com.owncloud.android.data.sharing.shares.datasources.implementation.OCLocalShareDataSource
import com.owncloud.android.data.spaces.datasources.LocalSpacesDataSource
import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource
import com.owncloud.android.data.storage.LocalStorageProvider
import com.owncloud.android.data.storage.ScopedStorageProvider
import com.owncloud.android.data.transfers.datasources.LocalTransferDataSource
Expand All @@ -56,6 +58,7 @@ val localDataSourceModule = module {
single { OwncloudDatabase.getDatabase(androidContext()).userDao() }
single { OwncloudDatabase.getDatabase(androidContext()).folderBackUpDao() }
single { OwncloudDatabase.getDatabase(androidContext()).transferDao() }
single { OwncloudDatabase.getDatabase(androidContext()).spacesDao() }

single<SharedPreferencesProvider> { OCSharedPreferencesProvider(get()) }
single<LocalStorageProvider> { ScopedStorageProvider(dataFolder, androidContext()) }
Expand All @@ -67,4 +70,5 @@ val localDataSourceModule = module {
factory<LocalUserDataSource> { OCLocalUserDataSource(get()) }
factory<FolderBackupLocalDataSource> { OCFolderBackupLocalDataSource(get()) }
factory<LocalTransferDataSource> { OCLocalTransferDataSource(get()) }
factory<LocalSpacesDataSource> { OCLocalSpacesDataSource(get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package com.owncloud.android.dependecyinjection

import com.owncloud.android.MainApp
import com.owncloud.android.R
import com.owncloud.android.presentation.authentication.AccountUtils
import com.owncloud.android.data.ClientManager
import com.owncloud.android.data.authentication.datasources.RemoteAuthenticationDataSource
import com.owncloud.android.data.authentication.datasources.implementation.OCRemoteAuthenticationDataSource
Expand All @@ -40,6 +39,8 @@ import com.owncloud.android.data.sharing.sharees.datasources.mapper.RemoteSharee
import com.owncloud.android.data.sharing.shares.datasources.RemoteShareDataSource
import com.owncloud.android.data.sharing.shares.datasources.implementation.OCRemoteShareDataSource
import com.owncloud.android.data.sharing.shares.datasources.mapper.RemoteShareMapper
import com.owncloud.android.data.spaces.datasources.RemoteSpacesDataSource
import com.owncloud.android.data.spaces.datasources.implementation.OCRemoteSpacesDataSource
import com.owncloud.android.data.user.datasources.RemoteUserDataSource
import com.owncloud.android.data.user.datasources.implementation.OCRemoteUserDataSource
import com.owncloud.android.data.webfinger.datasources.WebfingerRemoteDatasource
Expand All @@ -57,12 +58,15 @@ import com.owncloud.android.lib.resources.shares.services.ShareService
import com.owncloud.android.lib.resources.shares.services.ShareeService
import com.owncloud.android.lib.resources.shares.services.implementation.OCShareService
import com.owncloud.android.lib.resources.shares.services.implementation.OCShareeService
import com.owncloud.android.lib.resources.spaces.services.OCSpacesService
import com.owncloud.android.lib.resources.spaces.services.SpacesService
import com.owncloud.android.lib.resources.status.services.CapabilityService
import com.owncloud.android.lib.resources.status.services.ServerInfoService
import com.owncloud.android.lib.resources.status.services.implementation.OCCapabilityService
import com.owncloud.android.lib.resources.status.services.implementation.OCServerInfoService
import com.owncloud.android.lib.resources.webfinger.services.WebfingerService
import com.owncloud.android.lib.resources.webfinger.services.implementation.OCWebfingerService
import com.owncloud.android.presentation.authentication.AccountUtils
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module

Expand All @@ -81,6 +85,7 @@ val remoteDataSourceModule = module {
single<OIDCService> { OCOIDCService() }
single<ShareService> { OCShareService(get()) }
single<ShareeService> { OCShareeService(get()) }
single<SpacesService> { OCSpacesService(get()) }
single<WebfingerService> { OCWebfingerService() }

factory<RemoteAuthenticationDataSource> { OCRemoteAuthenticationDataSource(get()) }
Expand All @@ -90,6 +95,7 @@ val remoteDataSourceModule = module {
factory<RemoteServerInfoDataSource> { OCRemoteServerInfoDataSource(get(), get()) }
factory<RemoteShareDataSource> { OCRemoteShareDataSource(get(), get()) }
factory<RemoteShareeDataSource> { OCRemoteShareeDataSource(get(), get()) }
factory<RemoteSpacesDataSource> { OCRemoteSpacesDataSource(get()) }
factory<RemoteUserDataSource> {
OCRemoteUserDataSource(get(), androidContext().resources.getDimension(R.dimen.file_avatar_size).toInt())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.owncloud.android.data.oauth.repository.OCOAuthRepository
import com.owncloud.android.data.server.repository.OCServerInfoRepository
import com.owncloud.android.data.sharing.sharees.repository.OCShareeRepository
import com.owncloud.android.data.sharing.shares.repository.OCShareRepository
import com.owncloud.android.data.spaces.repository.OCSpacesRepository
import com.owncloud.android.data.transfers.repository.OCTransferRepository
import com.owncloud.android.data.user.repository.OCUserRepository
import com.owncloud.android.data.webfinger.repository.OCWebfingerRepository
Expand All @@ -41,6 +42,7 @@ import com.owncloud.android.domain.files.FileRepository
import com.owncloud.android.domain.server.ServerInfoRepository
import com.owncloud.android.domain.sharing.sharees.ShareeRepository
import com.owncloud.android.domain.sharing.shares.ShareRepository
import com.owncloud.android.domain.spaces.SpacesRepository
import com.owncloud.android.domain.transfers.TransferRepository
import com.owncloud.android.domain.user.UserRepository
import com.owncloud.android.domain.webfinger.WebfingerRepository
Expand All @@ -53,6 +55,7 @@ val repositoryModule = module {
factory<ServerInfoRepository> { OCServerInfoRepository(get()) }
factory<ShareRepository> { OCShareRepository(get(), get()) }
factory<ShareeRepository> { OCShareeRepository(get()) }
factory<SpacesRepository> { OCSpacesRepository(get(), get()) }
factory<UserRepository> { OCUserRepository(get(), get()) }
factory<OAuthRepository> { OCOAuthRepository(get()) }
factory<FolderBackupRepository> { OCFolderBackupRepository(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ import com.owncloud.android.domain.sharing.shares.usecases.EditPublicShareAsyncU
import com.owncloud.android.domain.sharing.shares.usecases.GetShareAsLiveDataUseCase
import com.owncloud.android.domain.sharing.shares.usecases.GetSharesAsLiveDataUseCase
import com.owncloud.android.domain.sharing.shares.usecases.RefreshSharesFromServerAsyncUseCase
import com.owncloud.android.domain.spaces.usecases.GetProjectSpacesWithSpecialsForAccountAsStreamUseCase
import com.owncloud.android.domain.spaces.usecases.RefreshSpacesFromServerAsyncUseCase
import com.owncloud.android.domain.transfers.usecases.ClearSuccessfulTransfersUseCase
import com.owncloud.android.domain.transfers.usecases.GetAllTransfersAsLiveDataUseCase
import com.owncloud.android.domain.transfers.usecases.GetAllTransfersUseCase
Expand All @@ -91,10 +93,10 @@ import com.owncloud.android.usecases.accounts.RemoveAccountUseCase
import com.owncloud.android.usecases.synchronization.SynchronizeFileUseCase
import com.owncloud.android.usecases.synchronization.SynchronizeFolderUseCase
import com.owncloud.android.usecases.transfers.downloads.CancelDownloadForFileUseCase
import com.owncloud.android.usecases.transfers.downloads.CancelDownloadsRecursivelyUseCase
import com.owncloud.android.usecases.transfers.downloads.DownloadFileUseCase
import com.owncloud.android.usecases.transfers.downloads.GetLiveDataForDownloadingFileUseCase
import com.owncloud.android.usecases.transfers.downloads.GetLiveDataForFinishedDownloadsFromAccountUseCase
import com.owncloud.android.usecases.transfers.downloads.CancelDownloadsRecursivelyUseCase
import com.owncloud.android.usecases.transfers.uploads.CancelTransfersFromAccountUseCase
import com.owncloud.android.usecases.transfers.uploads.CancelUploadForFileUseCase
import com.owncloud.android.usecases.transfers.uploads.CancelUploadUseCase
Expand Down Expand Up @@ -172,6 +174,10 @@ val useCaseModule = module {
factory { GetSharesAsLiveDataUseCase(get()) }
factory { RefreshSharesFromServerAsyncUseCase(get()) }

// Spaces
factory { RefreshSpacesFromServerAsyncUseCase(get()) }
factory { GetProjectSpacesWithSpecialsForAccountAsStreamUseCase(get()) }

// Transfers
factory { CancelDownloadForFileUseCase(get()) }
factory { CancelDownloadsRecursivelyUseCase(get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,34 @@ package com.owncloud.android.dependecyinjection
import com.owncloud.android.MainApp
import com.owncloud.android.domain.files.model.FileListOption
import com.owncloud.android.domain.files.model.OCFile
import com.owncloud.android.presentation.files.details.FileDetailsViewModel
import com.owncloud.android.presentation.files.filelist.MainFileListViewModel
import com.owncloud.android.presentation.files.operations.FileOperationsViewModel
import com.owncloud.android.presentation.security.passcode.PasscodeAction
import com.owncloud.android.presentation.accounts.AccountsManagementViewModel
import com.owncloud.android.presentation.accounts.RemoveAccountDialogViewModel
import com.owncloud.android.presentation.authentication.AuthenticationViewModel
import com.owncloud.android.presentation.authentication.oauth.OAuthViewModel
import com.owncloud.android.presentation.capabilities.CapabilityViewModel
import com.owncloud.android.presentation.conflicts.ConflictsResolveViewModel
import com.owncloud.android.presentation.common.DrawerViewModel
import com.owncloud.android.presentation.conflicts.ConflictsResolveViewModel
import com.owncloud.android.presentation.files.details.FileDetailsViewModel
import com.owncloud.android.presentation.files.filelist.MainFileListViewModel
import com.owncloud.android.presentation.files.operations.FileOperationsViewModel
import com.owncloud.android.presentation.logging.LogListViewModel
import com.owncloud.android.presentation.migration.MigrationViewModel
import com.owncloud.android.presentation.authentication.oauth.OAuthViewModel
import com.owncloud.android.presentation.releasenotes.ReleaseNotesViewModel
import com.owncloud.android.presentation.security.biometric.BiometricViewModel
import com.owncloud.android.presentation.security.passcode.PassCodeViewModel
import com.owncloud.android.presentation.security.passcode.PasscodeAction
import com.owncloud.android.presentation.security.pattern.PatternViewModel
import com.owncloud.android.presentation.settings.SettingsViewModel
import com.owncloud.android.presentation.settings.advanced.SettingsAdvancedViewModel
import com.owncloud.android.presentation.settings.autouploads.SettingsPictureUploadsViewModel
import com.owncloud.android.presentation.settings.autouploads.SettingsVideoUploadsViewModel
import com.owncloud.android.presentation.settings.logging.SettingsLogsViewModel
import com.owncloud.android.presentation.settings.more.SettingsMoreViewModel
import com.owncloud.android.presentation.settings.autouploads.SettingsPictureUploadsViewModel
import com.owncloud.android.presentation.settings.security.SettingsSecurityViewModel
import com.owncloud.android.presentation.settings.autouploads.SettingsVideoUploadsViewModel
import com.owncloud.android.presentation.settings.SettingsViewModel
import com.owncloud.android.presentation.sharing.ShareViewModel
import com.owncloud.android.presentation.spaces.SpacesListViewModel
import com.owncloud.android.presentation.transfers.TransfersViewModel
import com.owncloud.android.presentation.accounts.AccountsManagementViewModel
import com.owncloud.android.ui.ReceiveExternalFilesViewModel
import com.owncloud.android.presentation.accounts.RemoveAccountDialogViewModel
import com.owncloud.android.ui.preview.PreviewImageViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module
Expand Down Expand Up @@ -112,4 +113,5 @@ val viewModelModule = module {
viewModel { (ocFile: OCFile) -> ConflictsResolveViewModel(get(), get(), get(), get(), get(), ocFile) }
viewModel { ReceiveExternalFilesViewModel(get(), get()) }
viewModel { AccountsManagementViewModel(get()) }
viewModel { SpacesListViewModel(get(), get(), get(), get()) }
}
Loading

0 comments on commit 65b5050

Please sign in to comment.