use of com.owncloud.android.databinding.ShareActivityBinding in project android by nextcloud.
the class ShareActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ShareActivityBinding binding = ShareActivityBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
OCFile file = getFile();
Optional<User> optionalUser = getUser();
if (!optionalUser.isPresent()) {
finish();
return;
}
// Icon
if (file.isFolder()) {
binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType(), this));
} else {
binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(), optionalUser.get(), this));
if (MimeTypeUtil.isImage(file)) {
String remoteId = String.valueOf(file.getRemoteId());
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId);
if (thumbnail != null) {
binding.shareFileIcon.setImageBitmap(thumbnail);
}
}
}
// Name
binding.shareFileName.setText(getResources().getString(R.string.share_file, file.getFileName()));
binding.shareHeaderDivider.getBackground().setColorFilter(ThemeColorUtils.primaryAccentColor(this), PorterDuff.Mode.SRC_ATOP);
// Size
binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
Activity activity = this;
new Thread(() -> {
RemoteOperationResult result = new ReadFileRemoteOperation(getFile().getRemotePath()).execute(optionalUser.get().toPlatformAccount(), activity);
if (result.isSuccess()) {
RemoteFile remoteFile = (RemoteFile) result.getData().get(0);
long length = remoteFile.getLength();
getFile().setFileLength(length);
runOnUiThread(() -> binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(length)));
}
}).start();
if (savedInstanceState == null) {
// Add Share fragment on first creation
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment fragment = FileDetailSharingFragment.newInstance(getFile(), optionalUser.get());
ft.replace(R.id.share_fragment_container, fragment, TAG_SHARE_FRAGMENT);
ft.commit();
}
}
Aggregations