Search in sources :

Example 1 with ShareActivityBinding

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();
    }
}
Also used : User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ShareActivityBinding(com.owncloud.android.databinding.ShareActivityBinding) Activity(android.app.Activity) FileDetailSharingFragment(com.owncloud.android.ui.fragment.FileDetailSharingFragment) Fragment(androidx.fragment.app.Fragment) OCFile(com.owncloud.android.datamodel.OCFile) Bitmap(android.graphics.Bitmap) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile)

Aggregations

Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1 Fragment (androidx.fragment.app.Fragment)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 User (com.nextcloud.client.account.User)1 ShareActivityBinding (com.owncloud.android.databinding.ShareActivityBinding)1 OCFile (com.owncloud.android.datamodel.OCFile)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 ReadFileRemoteOperation (com.owncloud.android.lib.resources.files.ReadFileRemoteOperation)1 RemoteFile (com.owncloud.android.lib.resources.files.model.RemoteFile)1 FileDetailSharingFragment (com.owncloud.android.ui.fragment.FileDetailSharingFragment)1