use of com.owncloud.android.lib.resources.shares.ShareeUser in project android by nextcloud.
the class OCFileListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof OCFileListFooterViewHolder) {
OCFileListFooterViewHolder footerViewHolder = (OCFileListFooterViewHolder) holder;
footerViewHolder.binding.footerText.setText(getFooterText());
footerViewHolder.binding.loadingProgressBar.getIndeterminateDrawable().setColorFilter(ThemeColorUtils.primaryColor(activity), PorterDuff.Mode.SRC_IN);
footerViewHolder.binding.loadingProgressBar.setVisibility(ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
} else if (holder instanceof OCFileListHeaderViewHolder) {
OCFileListHeaderViewHolder headerViewHolder = (OCFileListHeaderViewHolder) holder;
String text = currentDirectory.getRichWorkspace();
PreviewTextFragment.setText(headerViewHolder.binding.headerText, text, null, activity, true, true);
headerViewHolder.binding.headerView.setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());
} else {
ListGridImageViewHolder gridViewHolder = (ListGridImageViewHolder) holder;
OCFile file = getItem(position);
boolean gridImage = MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file);
gridViewHolder.getThumbnail().setTag(file.getFileId());
setThumbnail(file, gridViewHolder.getThumbnail(), user, mStorageManager, asyncTasks, gridView, activity, gridViewHolder.getShimmerThumbnail(), preferences);
if (highlightedItem != null && file.getFileId() == highlightedItem.getFileId()) {
gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.selected_item_background));
} else if (isCheckedFile(file)) {
gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.selected_item_background));
gridViewHolder.getCheckbox().setImageDrawable(ThemeDrawableUtils.tintDrawable(R.drawable.ic_checkbox_marked, ThemeColorUtils.primaryColor(activity)));
} else {
gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.bg_default));
gridViewHolder.getCheckbox().setImageResource(R.drawable.ic_checkbox_blank_outline);
}
gridViewHolder.getItemLayout().setOnClickListener(v -> ocFileListFragmentInterface.onItemClicked(file));
if (!hideItemOptions) {
gridViewHolder.getItemLayout().setLongClickable(true);
gridViewHolder.getItemLayout().setOnLongClickListener(v -> ocFileListFragmentInterface.onLongItemClicked(file));
}
// unread comments
if (file.getUnreadCommentsCount() > 0) {
gridViewHolder.getUnreadComments().setVisibility(View.VISIBLE);
gridViewHolder.getUnreadComments().setOnClickListener(view -> ocFileListFragmentInterface.showActivityDetailView(file));
} else {
gridViewHolder.getUnreadComments().setVisibility(View.GONE);
}
if (holder instanceof ListItemViewHolder) {
ListItemViewHolder itemViewHolder = (ListItemViewHolder) holder;
if ((file.isSharedWithMe() || file.isSharedWithSharee()) && !multiSelect && !gridView && !hideItemOptions) {
itemViewHolder.getSharedAvatars().setVisibility(View.VISIBLE);
itemViewHolder.getSharedAvatars().removeAllViews();
String fileOwner = file.getOwnerId();
List<ShareeUser> sharees = file.getSharees();
// use fileOwner if not oneself, then add at first
ShareeUser fileOwnerSharee = new ShareeUser(fileOwner, file.getOwnerDisplayName(), ShareType.USER);
if (!TextUtils.isEmpty(fileOwner) && !fileOwner.equals(userId) && !sharees.contains(fileOwnerSharee)) {
sharees.add(fileOwnerSharee);
}
Collections.reverse(sharees);
Log_OC.d(this, "sharees of " + file.getFileName() + ": " + sharees);
itemViewHolder.getSharedAvatars().setAvatars(user, sharees);
itemViewHolder.getSharedAvatars().setOnClickListener(view -> ocFileListFragmentInterface.onShareIconClick(file));
} else {
itemViewHolder.getSharedAvatars().setVisibility(View.GONE);
itemViewHolder.getSharedAvatars().removeAllViews();
}
// npe fix: looks like file without local storage path somehow get here
final String storagePath = file.getStoragePath();
if (onlyOnDevice && storagePath != null) {
File localFile = new File(storagePath);
long localSize;
if (localFile.isDirectory()) {
localSize = FileStorageUtils.getFolderSize(localFile);
} else {
localSize = localFile.length();
}
itemViewHolder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(localSize));
} else {
itemViewHolder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
}
itemViewHolder.getLastModification().setText(DisplayUtils.getRelativeTimestamp(activity, file.getModificationTimestamp()));
if (multiSelect || gridView || hideItemOptions) {
itemViewHolder.getOverflowMenu().setVisibility(View.GONE);
} else {
itemViewHolder.getOverflowMenu().setVisibility(View.VISIBLE);
itemViewHolder.getOverflowMenu().setOnClickListener(view -> ocFileListFragmentInterface.onOverflowIconClicked(file, view));
}
}
// default first
gridViewHolder.getLocalFileIndicator().setVisibility(View.INVISIBLE);
if (showMetadata) {
OperationsService.OperationsServiceBinder operationsServiceBinder = transferServiceGetter.getOperationsServiceBinder();
FileDownloader.FileDownloaderBinder fileDownloaderBinder = transferServiceGetter.getFileDownloaderBinder();
FileUploader.FileUploaderBinder fileUploaderBinder = transferServiceGetter.getFileUploaderBinder();
if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user, file)) {
// synchronizing
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user, file)) {
// downloading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user, file)) {
// uploading
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (file.getEtagInConflict() != null) {
// conflict
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing_error);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
} else if (file.isDown()) {
gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synced);
gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
}
gridViewHolder.getFavorite().setVisibility(file.isFavorite() ? View.VISIBLE : View.GONE);
}
if (multiSelect) {
gridViewHolder.getCheckbox().setVisibility(View.VISIBLE);
} else {
gridViewHolder.getCheckbox().setVisibility(View.GONE);
}
if (holder instanceof ListGridItemViewHolder) {
ListGridItemViewHolder gridItemViewHolder = (ListGridItemViewHolder) holder;
gridItemViewHolder.getFileName().setText(file.getDecryptedFileName());
if (gridView && gridImage) {
gridItemViewHolder.getFileName().setVisibility(View.GONE);
} else {
if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
gridItemViewHolder.getFileName().setVisibility(View.GONE);
} else {
gridItemViewHolder.getFileName().setVisibility(View.VISIBLE);
}
}
}
if (gridView || hideItemOptions || (file.isFolder() && !file.canReshare())) {
gridViewHolder.getShared().setVisibility(View.GONE);
} else {
showShareIcon(gridViewHolder, file);
}
}
}
use of com.owncloud.android.lib.resources.shares.ShareeUser in project android by nextcloud.
the class AvatarGroupLayout method setAvatars.
public void setAvatars(@NonNull User user, @NonNull List<ShareeUser> sharees) {
@NonNull Context context = getContext();
removeAllViews();
RelativeLayout.LayoutParams avatarLayoutParams;
int avatarCount;
int shareeSize = Math.min(sharees.size(), MAX_AVATAR_COUNT);
Resources resources = context.getResources();
float avatarRadius = resources.getDimension(R.dimen.list_item_avatar_icon_radius);
ShareeUser sharee;
for (avatarCount = 0; avatarCount < shareeSize; avatarCount++) {
avatarLayoutParams = new RelativeLayout.LayoutParams(avatarSize, avatarSize);
avatarLayoutParams.setMargins(0, 0, avatarCount * overlapPx, 0);
avatarLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
final ImageView avatar = new ImageView(context);
avatar.setLayoutParams(avatarLayoutParams);
avatar.setPadding(avatarBorderSize, avatarBorderSize, avatarBorderSize, avatarBorderSize);
avatar.setBackground(borderDrawable);
addView(avatar);
avatar.requestLayout();
if (avatarCount == 0 && sharees.size() > MAX_AVATAR_COUNT) {
avatar.setImageResource(R.drawable.ic_people);
ThemeDrawableUtils.setIconColor(avatar.getDrawable());
} else {
sharee = sharees.get(avatarCount);
switch(sharee.getShareType()) {
case GROUP:
case EMAIL:
case ROOM:
case CIRCLE:
ThemeAvatarUtils.createAvatar(sharee.getShareType(), avatar, context);
break;
case FEDERATED:
showFederatedShareAvatar(context, sharee.getUserId(), avatarRadius, resources, avatar);
break;
default:
avatar.setTag(sharee);
DisplayUtils.setAvatar(user, sharee.getUserId(), sharee.getDisplayName(), this, avatarRadius, resources, avatar, context);
break;
}
}
}
// Recalculate container size based on avatar count
int size = overlapPx * (avatarCount - 1) + avatarSize;
ViewGroup.LayoutParams rememberParam = getLayoutParams();
rememberParam.width = size;
setLayoutParams(rememberParam);
}
use of com.owncloud.android.lib.resources.shares.ShareeUser in project android by nextcloud.
the class FileDataStorageManager method createFileInstance.
private OCFile createFileInstance(Cursor cursor) {
OCFile ocFile = null;
if (cursor != null) {
ocFile = new OCFile(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PATH)));
ocFile.setDecryptedRemotePath(getString(cursor, ProviderTableMeta.FILE_PATH_DECRYPTED));
ocFile.setFileId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta._ID)));
ocFile.setParentId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PARENT)));
ocFile.setMimeType(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_TYPE)));
ocFile.setStoragePath(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_STORAGE_PATH)));
if (ocFile.getStoragePath() == null) {
// try to find existing file and bind it with current account;
// with the current update of SynchronizeFolderOperation, this won't be
// necessary anymore after a full synchronization of the account
File file = new File(FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile));
if (file.exists()) {
ocFile.setStoragePath(file.getAbsolutePath());
ocFile.setLastSyncDateForData(file.lastModified());
}
}
ocFile.setFileLength(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_LENGTH)));
ocFile.setCreationTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CREATION)));
ocFile.setModificationTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MODIFIED)));
ocFile.setModificationTimestampAtLastSyncForData(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
ocFile.setLastSyncDateForProperties(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
ocFile.setLastSyncDateForData(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
ocFile.setEtag(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG)));
ocFile.setEtagOnServer(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_ON_SERVER)));
ocFile.setSharedViaLink(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1);
ocFile.setSharedWithSharee(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
ocFile.setPermissions(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PERMISSIONS)));
ocFile.setRemoteId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_REMOTE_ID)));
ocFile.setUpdateThumbnailNeeded(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
ocFile.setDownloading(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1);
ocFile.setEtagInConflict(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
ocFile.setFavorite(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_FAVORITE)) == 1);
ocFile.setEncrypted(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_ENCRYPTED)) == 1);
// if (ocFile.isEncrypted()) {
// ocFile.setFileName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NAME)));
// }
ocFile.setMountType(WebdavEntry.MountType.values()[cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MOUNT_TYPE))]);
ocFile.setPreviewAvailable(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_HAS_PREVIEW)) == 1);
ocFile.setUnreadCommentsCount(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT)));
ocFile.setOwnerId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_ID)));
ocFile.setOwnerDisplayName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)));
ocFile.setNote(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NOTE)));
ocFile.setRichWorkspace(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_RICH_WORKSPACE)));
String sharees = cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHAREES));
if (sharees == null || NULL_STRING.equals(sharees) || sharees.isEmpty()) {
ocFile.setSharees(new ArrayList<>());
} else {
try {
ShareeUser[] shareesArray = new Gson().fromJson(sharees, ShareeUser[].class);
ocFile.setSharees(new ArrayList<>(Arrays.asList(shareesArray)));
} catch (JsonSyntaxException e) {
// ignore saved value due to api change
ocFile.setSharees(new ArrayList<>());
}
}
}
return ocFile;
}
Aggregations