use of com.owncloud.android.datamodel.VirtualFolderType in project android by nextcloud.
the class PreviewImageActivity method initViewPager.
private void initViewPager() {
// virtual folder
if (getIntent().getSerializableExtra(EXTRA_VIRTUAL_TYPE) != null) {
VirtualFolderType type = (VirtualFolderType) getIntent().getSerializableExtra(EXTRA_VIRTUAL_TYPE);
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), type, getAccount(), getStorageManager());
} else {
// get parent from path
OCFile parentFolder = getStorageManager().getFileById(getFile().getParentId());
if (parentFolder == null) {
// should not be necessary
parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
}
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), parentFolder, getAccount(), getStorageManager(), MainApp.isOnlyOnDevice(), this);
}
mViewPager = findViewById(R.id.fragmentPager);
int position = mHasSavedPosition ? mSavedPosition : mPreviewImagePagerAdapter.getFilePosition(getFile());
position = (position >= 0) ? position : 0;
mViewPager.setAdapter(mPreviewImagePagerAdapter);
mViewPager.setOnPageChangeListener(this);
mViewPager.setCurrentItem(position);
if (position == 0 && !getFile().isDown()) {
// this is necessary because mViewPager.setCurrentItem(0) just after setting the
// adapter does not result in a call to #onPageSelected(0)
mRequestWaitingForBinder = true;
}
}
use of com.owncloud.android.datamodel.VirtualFolderType in project android by nextcloud.
the class OCFileListFragment method onItemClicked.
@Override
public void onItemClicked(OCFile file) {
if (getAdapter().isMultiSelect()) {
toggleItemToCheckedList(file);
} else {
if (file != null) {
int position = mAdapter.getItemPosition(file);
if (file.isFolder()) {
resetHeaderScrollingState();
if (file.isEncrypted()) {
User user = ((FileActivity) mContainerActivity).getUser().orElseThrow(RuntimeException::new);
// check if e2e app is enabled
OCCapability ocCapability = mContainerActivity.getStorageManager().getCapability(user.getAccountName());
if (ocCapability.getEndToEndEncryption().isFalse() || ocCapability.getEndToEndEncryption().isUnknown()) {
Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_not_enabled, Snackbar.LENGTH_LONG).show();
return;
}
// check if keys are stored
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
if (publicKey.isEmpty() || privateKey.isEmpty()) {
Log_OC.d(TAG, "no public key for " + user.getAccountName());
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
dialog.show(getFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
} else {
// update state and view of this fragment
searchFragment = false;
mHideFab = false;
if (mContainerActivity instanceof FolderPickerActivity && ((FolderPickerActivity) mContainerActivity).isDoNotEnterEncryptedFolder()) {
Snackbar.make(getRecyclerView(), R.string.copy_move_to_encrypted_folder_not_supported, Snackbar.LENGTH_LONG).show();
} else {
listDirectory(file, MainApp.isOnlyOnDevice(), false);
// then, notify parent activity to let it update its state and view
mContainerActivity.onBrowsedDownTo(file);
// save index and top position
saveIndexAndTopPosition(position);
}
}
} else {
// update state and view of this fragment
searchFragment = false;
setEmptyListLoadingMessage();
listDirectory(file, MainApp.isOnlyOnDevice(), false);
// then, notify parent activity to let it update its state and view
mContainerActivity.onBrowsedDownTo(file);
// save index and top position
saveIndexAndTopPosition(position);
}
} else if (mFileSelectable) {
Intent intent = new Intent();
intent.putExtra(FolderPickerActivity.EXTRA_FILES, file);
getActivity().setResult(Activity.RESULT_OK, intent);
getActivity().finish();
} else if (!mOnlyFoldersClickable) {
// Click on a file
if (PreviewImageFragment.canBePreviewed(file)) {
// preview image - it handles the download, if needed
if (searchFragment) {
VirtualFolderType type;
switch(currentSearchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
break;
default:
type = VirtualFolderType.NONE;
break;
}
((FileDisplayActivity) mContainerActivity).startImagePreview(file, type, !file.isDown());
} else {
((FileDisplayActivity) mContainerActivity).startImagePreview(file, !file.isDown());
}
} else if (file.isDown() && MimeTypeUtil.isVCard(file)) {
((FileDisplayActivity) mContainerActivity).startContactListFragment(file);
} else if (file.isDown() && MimeTypeUtil.isPDF(file)) {
((FileDisplayActivity) mContainerActivity).startPdfPreview(file);
} else if (PreviewTextFileFragment.canBePreviewed(file)) {
setFabVisible(false);
resetHeaderScrollingState();
((FileDisplayActivity) mContainerActivity).startTextPreview(file, false);
} else if (file.isDown()) {
if (PreviewMediaFragment.canBePreviewed(file)) {
// media preview
setFabVisible(false);
resetHeaderScrollingState();
((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, false);
} else {
mContainerActivity.getFileOperationsHelper().openFile(file);
}
} else {
// file not downloaded, check for streaming, remote editing
User account = accountManager.getUser();
OCCapability capability = mContainerActivity.getStorageManager().getCapability(account.getAccountName());
if (PreviewMediaFragment.canBePreviewed(file) && !file.isEncrypted()) {
// stream media preview on >= NC14
setFabVisible(false);
resetHeaderScrollingState();
((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, true);
} else if (FileMenuFilter.isEditorAvailable(requireContext().getContentResolver(), accountManager.getUser(), file.getMimeType()) && !file.isEncrypted()) {
mContainerActivity.getFileOperationsHelper().openFileWithTextEditor(file, getContext());
} else if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) && capability.getRichDocumentsDirectEditing().isTrue() && !file.isEncrypted()) {
mContainerActivity.getFileOperationsHelper().openFileAsRichDocument(file, getContext());
} else {
// automatic download, preview on finish
((FileDisplayActivity) mContainerActivity).startDownloadForPreview(file);
}
}
}
} else {
Log_OC.d(TAG, "Null object in ListAdapter!");
}
}
}
use of com.owncloud.android.datamodel.VirtualFolderType in project android by nextcloud.
the class OCFileListAdapter method parseVirtuals.
private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
VirtualFolderType type;
boolean onlyImages = false;
switch(searchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case PHOTO_SEARCH:
type = VirtualFolderType.PHOTOS;
onlyImages = true;
break;
default:
type = VirtualFolderType.NONE;
break;
}
mStorageManager.deleteVirtuals(type);
List<ContentValues> contentValues = new ArrayList<>();
for (int i = 0; i < objects.size(); i++) {
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
searchForLocalFileInDefaultPath(ocFile);
try {
ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);
if (!onlyImages || MimeTypeUtil.isImage(ocFile)) {
mFiles.add(ocFile);
}
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
contentValues.add(cv);
} catch (RemoteOperationFailedException e) {
Log_OC.e(TAG, "Error saving file with parent" + e.getMessage(), e);
}
}
mStorageManager.saveVirtuals(type, contentValues);
}
use of com.owncloud.android.datamodel.VirtualFolderType in project android by nextcloud.
the class OCFileListAdapter method setData.
public void setData(List<Object> objects, SearchType searchType, FileDataStorageManager storageManager, @Nullable OCFile folder, boolean clear) {
if (storageManager != null && mStorageManager == null) {
mStorageManager = storageManager;
showShareAvatar = mStorageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported();
}
if (mStorageManager == null) {
mStorageManager = new FileDataStorageManager(user, activity.getContentResolver());
}
if (clear) {
mFiles.clear();
resetLastTimestamp();
preferences.setPhotoSearchTimestamp(0);
VirtualFolderType type;
switch(searchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
break;
default:
type = VirtualFolderType.NONE;
break;
}
if (type != VirtualFolderType.GALLERY) {
mStorageManager.deleteVirtuals(type);
}
}
// early exit
if (objects.size() > 0 && mStorageManager != null) {
if (searchType == SearchType.SHARED_FILTER) {
parseShares(objects);
} else {
if (searchType != SearchType.GALLERY_SEARCH) {
parseVirtuals(objects, searchType);
}
}
}
if (searchType != SearchType.GALLERY_SEARCH && searchType != SearchType.RECENTLY_MODIFIED_SEARCH) {
FileSortOrder sortOrder = preferences.getSortOrderByFolder(folder);
mFiles = sortOrder.sortCloudFiles(mFiles);
} else {
mFiles = FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);
}
mFilesAll.clear();
mFilesAll.addAll(mFiles);
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
}
use of com.owncloud.android.datamodel.VirtualFolderType in project android by nextcloud.
the class OCFileListAdapter method parseVirtuals.
private void parseVirtuals(List<Object> objects, SearchType searchType) {
VirtualFolderType type;
boolean onlyMedia = false;
switch(searchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
onlyMedia = true;
int lastPosition = objects.size() - 1;
if (lastPosition < 0) {
lastTimestamp = -1;
break;
}
RemoteFile lastFile = (RemoteFile) objects.get(lastPosition);
lastTimestamp = lastFile.getModifiedTimestamp() / 1000;
break;
default:
type = VirtualFolderType.NONE;
break;
}
List<ContentValues> contentValues = new ArrayList<>();
for (Object remoteFile : objects) {
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) remoteFile);
FileStorageUtils.searchForLocalFileInDefaultPath(ocFile, user.getAccountName());
try {
ocFile = mStorageManager.saveFileWithParent(ocFile, activity);
if (SearchType.GALLERY_SEARCH != searchType) {
// also sync folder content
if (ocFile.isFolder()) {
long currentSyncTime = System.currentTimeMillis();
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(ocFile, currentSyncTime, true, false, mStorageManager, user, activity);
refreshFolderOperation.execute(user.toPlatformAccount(), activity);
}
}
if (!onlyMedia || MimeTypeUtil.isImage(ocFile) || MimeTypeUtil.isVideo(ocFile)) {
mFiles.add(ocFile);
}
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, type.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());
contentValues.add(cv);
} catch (RemoteOperationFailedException e) {
Log_OC.e(TAG, "Error saving file with parent" + e.getMessage(), e);
}
}
preferences.setPhotoSearchTimestamp(System.currentTimeMillis());
mStorageManager.saveVirtuals(contentValues);
}
Aggregations