use of com.owncloud.android.lib.common.Creator 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.Creator 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()));
}
Aggregations