Search in sources :

Example 21 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.

the class FileOperationsHelper method sendShareFile.

public void sendShareFile(OCFile file, boolean hideNcSharingOptions) {
    // Show dialog
    FragmentManager fm = fileActivity.getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.addToBackStack(null);
    OCCapability capability = fileActivity.getStorageManager().getCapability(fileActivity.getAccount().name);
    SendShareDialog mSendShareDialog = SendShareDialog.newInstance(file, hideNcSharingOptions, capability);
    mSendShareDialog.setFileOperationsHelper(this);
    mSendShareDialog.show(ft, "TAG_SEND_SHARE_DIALOG");
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) SendShareDialog(com.owncloud.android.ui.dialog.SendShareDialog)

Example 22 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.

the class FileOperationsHelper method openFile.

public void openFile(OCFile file) {
    if (file != null) {
        final Intent openFileWithIntent = createOpenFileIntent(file);
        List<ResolveInfo> launchables = fileActivity.getPackageManager().queryIntentActivities(openFileWithIntent, PackageManager.GET_RESOLVED_FILTER);
        if (launchables.isEmpty()) {
            Optional<User> optionalUser = fileActivity.getUser();
            if (optionalUser.isPresent() && FileMenuFilter.isEditorAvailable(fileActivity.getContentResolver(), optionalUser.get(), file.getMimeType())) {
                openFileWithTextEditor(file, fileActivity);
            } else {
                Account account = fileActivity.getAccount();
                OCCapability capability = fileActivity.getStorageManager().getCapability(account.name);
                if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) && capability.getRichDocumentsDirectEditing().isTrue()) {
                    openFileAsRichDocument(file, fileActivity);
                    return;
                } else {
                    DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
                    return;
                }
            }
        }
        fileActivity.showLoadingDialog(fileActivity.getResources().getString(R.string.sync_in_progress));
        new Thread(new Runnable() {

            @Override
            public void run() {
                User user = currentAccount.getUser();
                FileDataStorageManager storageManager = new FileDataStorageManager(user, fileActivity.getContentResolver());
                // a fresh object is needed; many things could have occurred to the file
                // since it was registered to observe again, assuming that local files
                // are linked to a remote file AT MOST, SOMETHING TO BE DONE;
                SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, user, true, fileActivity, storageManager);
                RemoteOperationResult result = sfo.execute(fileActivity);
                fileActivity.dismissLoadingDialog();
                if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
                    // ISSUE 5: if the user is not running the app (this is a service!),
                    // this can be very intrusive; a notification should be preferred
                    Intent intent = ConflictsResolveActivity.createIntent(file, user, -1, Intent.FLAG_ACTIVITY_NEW_TASK, fileActivity);
                    fileActivity.startActivity(intent);
                } else {
                    if (!launchables.isEmpty()) {
                        try {
                            if (!result.isSuccess()) {
                                DisplayUtils.showSnackMessage(fileActivity, R.string.file_not_synced);
                                try {
                                    Thread.sleep(3000);
                                } catch (InterruptedException e) {
                                    Log.e(TAG, "Failed to sleep");
                                }
                            }
                            openFileWithIntent.setFlags(openFileWithIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                            fileActivity.startActivity(openFileWithIntent);
                        } catch (ActivityNotFoundException exception) {
                            DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
                        }
                    } else {
                        DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
                    }
                }
            }
        }).start();
    } else {
        Log_OC.e(TAG, "Trying to open a NULL OCFile");
    }
}
Also used : Account(android.accounts.Account) User(com.nextcloud.client.account.User) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) SynchronizeFileOperation(com.owncloud.android.operations.SynchronizeFileOperation)

Example 23 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.

the class GallerySearchTask method doInBackground.

@Override
protected GallerySearchTask.Result doInBackground(Void... voids) {
    if (photoFragmentWeakReference.get() == null) {
        return new Result(false, false, -1);
    }
    GalleryFragment photoFragment = photoFragmentWeakReference.get();
    if (isCancelled()) {
        return new Result(false, false, -1);
    } else {
        OCCapability ocCapability = storageManager.getCapability(user.getAccountName());
        SearchRemoteOperation searchRemoteOperation = new SearchRemoteOperation("", SearchRemoteOperation.SearchType.GALLERY_SEARCH, false, ocCapability);
        searchRemoteOperation.setLimit(limit);
        searchRemoteOperation.setStartDate(startDate);
        searchRemoteOperation.setEndDate(endDate);
        if (photoFragment.getContext() != null) {
            Log_OC.d(this, "Start gallery search with " + new Date(startDate * 1000L) + " - " + new Date(endDate * 1000L) + " with limit: " + limit);
            RemoteOperationResult result = searchRemoteOperation.execute(user.toPlatformAccount(), photoFragment.getContext());
            boolean emptySearch = parseMedia(startDate, endDate, result.getData());
            long lastTimeStamp = findLastTimestamp(result.getData());
            photoFragment.getAdapter().showAllGalleryItems(storageManager);
            return new Result(result.isSuccess(), emptySearch, lastTimeStamp);
        } else {
            return new Result(false, false, -1);
        }
    }
}
Also used : GalleryFragment(com.owncloud.android.ui.fragment.GalleryFragment) SearchRemoteOperation(com.owncloud.android.lib.resources.files.SearchRemoteOperation) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Date(java.util.Date) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 24 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.

the class FileDetailActivitiesFragment method setupView.

private void setupView() {
    FileDataStorageManager storageManager = new FileDataStorageManager(user, contentResolver);
    operationsHelper = ((ComponentsGetter) requireActivity()).getFileOperationsHelper();
    OCCapability capability = storageManager.getCapability(user.getAccountName());
    restoreFileVersionSupported = capability.getFilesVersioning().isTrue();
    binding.emptyList.emptyListIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_activity, null));
    binding.emptyList.emptyListView.setVisibility(View.GONE);
    adapter = new ActivityAndVersionListAdapter(getContext(), accountManager, this, this, clientFactory);
    binding.list.setAdapter(adapter);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
    binding.list.setLayoutManager(layoutManager);
    binding.list.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int visibleItemCount = recyclerView.getChildCount();
            int totalItemCount = layoutManager.getItemCount();
            int firstVisibleItemIndex = layoutManager.findFirstVisibleItemPosition();
            // synchronize loading state when item count changes
            if (!isLoadingActivities && (totalItemCount - visibleItemCount) <= (firstVisibleItemIndex + 5) && lastGiven > 0) {
                // Almost reached the end, continue to load new activities
                fetchAndSetData(lastGiven);
            }
        }
    });
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) ActivityAndVersionListAdapter(com.owncloud.android.ui.adapter.ActivityAndVersionListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 25 with OCCapability

use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.

the class OCFileListBottomSheetDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = FileListActionsBottomSheetFragmentBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    if (getWindow() != null) {
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
    int primaryColor = ThemeColorUtils.primaryColor(getContext(), true);
    ThemeDrawableUtils.tintDrawable(binding.menuIconUploadFiles.getDrawable(), primaryColor);
    ThemeDrawableUtils.tintDrawable(binding.menuIconUploadFromApp.getDrawable(), primaryColor);
    ThemeDrawableUtils.tintDrawable(binding.menuIconDirectCameraUpload.getDrawable(), primaryColor);
    ThemeDrawableUtils.tintDrawable(binding.menuIconMkdir.getDrawable(), primaryColor);
    binding.addToCloud.setText(getContext().getResources().getString(R.string.add_to_cloud, ThemeUtils.getDefaultDisplayNameForRootFolder(getContext())));
    OCCapability capability = fileActivity.getCapabilities();
    if (capability != null && capability.getRichDocuments().isTrue() && capability.getRichDocumentsDirectEditing().isTrue() && capability.getRichDocumentsTemplatesAvailable().isTrue() && !file.isEncrypted()) {
        binding.templates.setVisibility(View.VISIBLE);
    }
    String json = new ArbitraryDataProvider(getContext().getContentResolver()).getValue(user, ArbitraryDataProvider.DIRECT_EDITING);
    if (!json.isEmpty() && !file.isEncrypted()) {
        DirectEditing directEditing = new Gson().fromJson(json, DirectEditing.class);
        if (!directEditing.getCreators().isEmpty()) {
            binding.creatorsContainer.setVisibility(View.VISIBLE);
            for (Creator creator : directEditing.getCreators().values()) {
                FileListActionsBottomSheetCreatorBinding creatorViewBinding = FileListActionsBottomSheetCreatorBinding.inflate(getLayoutInflater());
                View creatorView = creatorViewBinding.getRoot();
                creatorViewBinding.creatorName.setText(String.format(fileActivity.getString(R.string.editor_placeholder), fileActivity.getString(R.string.create_new), creator.getName()));
                creatorViewBinding.creatorThumbnail.setImageDrawable(MimeTypeUtil.getFileTypeIcon(creator.getMimetype(), creator.getExtension(), user, getContext()));
                creatorView.setOnClickListener(v -> {
                    actions.showTemplate(creator, creatorViewBinding.creatorName.getText().toString());
                    dismiss();
                });
                binding.creators.addView(creatorView);
            }
        }
    }
    if (!deviceInfo.hasCamera(getContext())) {
        binding.menuDirectCameraUpload.setVisibility(View.GONE);
    }
    // create rich workspace
    if (FileMenuFilter.isEditorAvailable(getContext().getContentResolver(), user, MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN) && file != null && !file.isEncrypted()) {
        // != "": info set -> hide button
        if (file.getRichWorkspace() == null || !"".equals(file.getRichWorkspace())) {
            binding.menuCreateRichWorkspace.setVisibility(View.GONE);
        } else {
            binding.menuCreateRichWorkspace.setVisibility(View.VISIBLE);
        }
    } else {
        binding.menuCreateRichWorkspace.setVisibility(View.GONE);
    }
    setupClickListener();
    setOnShowListener(d -> BottomSheetBehavior.from((View) binding.getRoot().getParent()).setPeekHeight(binding.getRoot().getMeasuredHeight()));
}
Also used : OCCapability(com.owncloud.android.lib.resources.status.OCCapability) DirectEditing(com.owncloud.android.lib.common.DirectEditing) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Gson(com.google.gson.Gson) Creator(com.owncloud.android.lib.common.Creator) View(android.view.View) FileListActionsBottomSheetCreatorBinding(com.owncloud.android.databinding.FileListActionsBottomSheetCreatorBinding)

Aggregations

OCCapability (com.owncloud.android.lib.resources.status.OCCapability)26 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)9 User (com.nextcloud.client.account.User)6 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)6 Account (android.accounts.Account)5 AccountManager (android.accounts.AccountManager)3 Intent (android.content.Intent)3 UserAccountManager (com.nextcloud.client.account.UserAccountManager)3 FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)3 Test (org.junit.Test)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Cursor (android.database.Cursor)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 LayerDrawable (android.graphics.drawable.LayerDrawable)2 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)2 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)2 Gson (com.google.gson.Gson)2 RegisteredUser (com.nextcloud.client.account.RegisteredUser)2 Server (com.nextcloud.client.account.Server)2