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());
}
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;
}
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()));
}
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);
}
Aggregations