Search in sources :

Example 1 with DirectEditing

use of com.owncloud.android.lib.common.DirectEditing in project android by nextcloud.

the class DialogFragmentIT method testBottomSheet.

@Test
@ScreenshotTest
public void testBottomSheet() {
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    OCFileListBottomSheetActions action = new OCFileListBottomSheetActions() {

        @Override
        public void createFolder() {
        }

        @Override
        public void uploadFromApp() {
        }

        @Override
        public void uploadFiles() {
        }

        @Override
        public void newDocument() {
        }

        @Override
        public void newSpreadsheet() {
        }

        @Override
        public void newPresentation() {
        }

        @Override
        public void directCameraUpload() {
        }

        @Override
        public void scanDocUpload() {
        }

        @Override
        public void showTemplate(Creator creator, String headline) {
        }

        @Override
        public void createRichWorkspace() {
        }
    };
    DeviceInfo info = new DeviceInfo();
    OCFile ocFile = new OCFile("/test.md");
    Intent intent = new Intent(targetContext, FileDisplayActivity.class);
    FileDisplayActivity fda = activityRule.launchActivity(intent);
    // add direct editing info
    DirectEditing directEditing = new DirectEditing();
    directEditing.getCreators().put("1", new Creator("1", "text", "text file", ".md", "application/octet-stream", false));
    directEditing.getCreators().put("2", new Creator("2", "md", "markdown file", ".md", "application/octet-stream", false));
    directEditing.getEditors().put("text", new Editor("1", "Text", new ArrayList<>(Collections.singletonList(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)), new ArrayList<>(), false));
    String json = new Gson().toJson(directEditing);
    new ArbitraryDataProvider(targetContext.getContentResolver()).storeOrUpdateKeyValue(user.getAccountName(), ArbitraryDataProvider.DIRECT_EDITING, json);
    // activate templates
    OCCapability capability = fda.getCapabilities();
    capability.setRichDocuments(CapabilityBooleanType.TRUE);
    capability.setRichDocumentsDirectEditing(CapabilityBooleanType.TRUE);
    capability.setRichDocumentsTemplatesAvailable(CapabilityBooleanType.TRUE);
    OCFileListBottomSheetDialog sut = new OCFileListBottomSheetDialog(fda, action, info, user, ocFile);
    fda.runOnUiThread(sut::show);
    waitForIdleSync();
    screenshot(sut.getWindow().getDecorView());
}
Also used : DirectEditing(com.owncloud.android.lib.common.DirectEditing) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) OCFileListBottomSheetDialog(com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog) ArrayList(java.util.ArrayList) OCFileListBottomSheetActions(com.owncloud.android.ui.fragment.OCFileListBottomSheetActions) Gson(com.google.gson.Gson) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent) Creator(com.owncloud.android.lib.common.Creator) OCFile(com.owncloud.android.datamodel.OCFile) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) DeviceInfo(com.nextcloud.client.device.DeviceInfo) Editor(com.owncloud.android.lib.common.Editor) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 2 with DirectEditing

use of com.owncloud.android.lib.common.DirectEditing in project android by nextcloud.

the class FileMenuFilter method getEditor.

@Nullable
public static Editor getEditor(ContentResolver contentResolver, User user, String mimeType) {
    String json = new ArbitraryDataProvider(contentResolver).getValue(user, ArbitraryDataProvider.DIRECT_EDITING);
    if (json.isEmpty()) {
        return null;
    }
    DirectEditing directEditing = new Gson().fromJson(json, DirectEditing.class);
    for (Editor editor : directEditing.getEditors().values()) {
        if (editor.getMimetypes().contains(mimeType)) {
            return editor;
        }
    }
    for (Editor editor : directEditing.getEditors().values()) {
        if (editor.getOptionalMimetypes().contains(mimeType)) {
            return editor;
        }
    }
    return null;
}
Also used : DirectEditing(com.owncloud.android.lib.common.DirectEditing) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Gson(com.google.gson.Gson) Editor(com.owncloud.android.lib.common.Editor) Nullable(androidx.annotation.Nullable)

Example 3 with DirectEditing

use of com.owncloud.android.lib.common.DirectEditing 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)

Example 4 with DirectEditing

use of com.owncloud.android.lib.common.DirectEditing in project android by nextcloud.

the class RefreshFolderOperation method updateDirectEditing.

private void updateDirectEditing(ArbitraryDataProvider arbitraryDataProvider, String newDirectEditingEtag) {
    RemoteOperationResult<DirectEditing> result = new DirectEditingObtainRemoteOperation().execute(user.toPlatformAccount(), mContext);
    if (result.isSuccess()) {
        DirectEditing directEditing = result.getResultData();
        String json = new Gson().toJson(directEditing);
        arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), ArbitraryDataProvider.DIRECT_EDITING, json);
    } else {
        arbitraryDataProvider.deleteKeyForAccount(user.getAccountName(), ArbitraryDataProvider.DIRECT_EDITING);
    }
    arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), ArbitraryDataProvider.DIRECT_EDITING_ETAG, newDirectEditingEtag);
}
Also used : DirectEditingObtainRemoteOperation(com.nextcloud.android.lib.resources.directediting.DirectEditingObtainRemoteOperation) DirectEditing(com.owncloud.android.lib.common.DirectEditing) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)4 DirectEditing (com.owncloud.android.lib.common.DirectEditing)4 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)3 Creator (com.owncloud.android.lib.common.Creator)2 Editor (com.owncloud.android.lib.common.Editor)2 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)2 Intent (android.content.Intent)1 View (android.view.View)1 Nullable (androidx.annotation.Nullable)1 DirectEditingObtainRemoteOperation (com.nextcloud.android.lib.resources.directediting.DirectEditingObtainRemoteOperation)1 DeviceInfo (com.nextcloud.client.device.DeviceInfo)1 FileListActionsBottomSheetCreatorBinding (com.owncloud.android.databinding.FileListActionsBottomSheetCreatorBinding)1 OCFile (com.owncloud.android.datamodel.OCFile)1 FileDisplayActivity (com.owncloud.android.ui.activity.FileDisplayActivity)1 OCFileListBottomSheetActions (com.owncloud.android.ui.fragment.OCFileListBottomSheetActions)1 OCFileListBottomSheetDialog (com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog)1 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1