From 9dcdd1de96e96a8d2b81c7094a64f2706ab294d5 Mon Sep 17 00:00:00 2001 From: A117870935 Date: Thu, 20 Apr 2023 23:00:20 +0530 Subject: [PATCH] Collabora related customization with test cases. --- .../android/OCFileListBottomSheetDialogIT.kt | 113 ++++++++++++++++++ .../fragment/OCFileListBottomSheetDialog.java | 29 +++-- app/src/main/res/drawable/ic_new_txt_doc.xml | 34 ++++++ app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 app/src/androidTest/java/com/nmc/android/OCFileListBottomSheetDialogIT.kt create mode 100644 app/src/main/res/drawable/ic_new_txt_doc.xml diff --git a/app/src/androidTest/java/com/nmc/android/OCFileListBottomSheetDialogIT.kt b/app/src/androidTest/java/com/nmc/android/OCFileListBottomSheetDialogIT.kt new file mode 100644 index 000000000000..a0200d2a1a75 --- /dev/null +++ b/app/src/androidTest/java/com/nmc/android/OCFileListBottomSheetDialogIT.kt @@ -0,0 +1,113 @@ +package com.nmc.android + +import android.os.Looper +import androidx.activity.result.contract.ActivityResultContract +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.intent.rule.IntentsTestRule +import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withText +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.gson.Gson +import com.nextcloud.client.device.DeviceInfo +import com.nextcloud.client.documentscan.AppScanOptionalFeature +import com.nextcloud.utils.EditorUtils +import com.owncloud.android.AbstractIT +import com.owncloud.android.datamodel.ArbitraryDataProvider +import com.owncloud.android.datamodel.ArbitraryDataProviderImpl +import com.owncloud.android.datamodel.OCFile +import com.owncloud.android.lib.common.Creator +import com.owncloud.android.lib.common.DirectEditing +import com.owncloud.android.lib.resources.status.CapabilityBooleanType +import com.owncloud.android.ui.activity.FileDisplayActivity +import com.owncloud.android.ui.fragment.OCFileListBottomSheetActions +import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog +import com.owncloud.android.utils.MimeTypeUtil +import com.owncloud.android.utils.theme.CapabilityUtils +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.mockito.Mock +import org.mockito.MockitoAnnotations + +class OCFileListBottomSheetDialogIT : AbstractIT() { + + @Mock + private lateinit var actions: OCFileListBottomSheetActions + + @get:Rule + val activityRule = IntentsTestRule(FileDisplayActivity::class.java, true, true) + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + } + + @Test + fun validateCreateTextDocumentMenuOption() { + if (Looper.myLooper() == null) { + Looper.prepare() + } + + val info = DeviceInfo() + val ocFile = OCFile("/test.md") + + // add direct editing info + val creatorMap = mutableMapOf() + creatorMap["1"] = Creator( + "1", + "md", + "markdown file", + ".md", + MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN, + false + ) + + val directEditing = DirectEditing( + creators = creatorMap + ) + + val json = Gson().toJson(directEditing) + ArbitraryDataProviderImpl(targetContext).storeOrUpdateKeyValue( + user.accountName, + ArbitraryDataProvider.DIRECT_EDITING, + json + ) + + val capability = activityRule.activity.capabilities + capability.richDocuments = CapabilityBooleanType.TRUE + capability.richDocumentsDirectEditing = CapabilityBooleanType.TRUE + capability.richDocumentsTemplatesAvailable = CapabilityBooleanType.TRUE + capability.accountName = user.accountName + CapabilityUtils.updateCapability(capability) + + val appScanOptionalFeature: AppScanOptionalFeature = object : AppScanOptionalFeature() { + override fun getScanContract(): ActivityResultContract { + throw UnsupportedOperationException("Document scan is not available") + } + } + + val editorUtils = EditorUtils(ArbitraryDataProviderImpl(targetContext)) + val sut = OCFileListBottomSheetDialog( + activityRule.activity, + actions, + info, + user, + ocFile, + activityRule.activity.themeUtils, + activityRule.activity.viewThemeUtils, + editorUtils, + appScanOptionalFeature + ) + + activityRule.activity.runOnUiThread { sut.show() } + + waitForIdleSync() + + sut.behavior.state = BottomSheetBehavior.STATE_EXPANDED + + shortSleep() + + onView(withText("Create text document")).check(matches(isCompletelyDisplayed())) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java index 95701987ab50..87080d877ac8 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java @@ -44,6 +44,8 @@ import com.owncloud.android.utils.theme.ThemeUtils; import com.owncloud.android.utils.theme.ViewThemeUtils; +import androidx.core.content.ContextCompat; + /** * FAB menu {@link android.app.Dialog} styled as a bottom sheet for main actions. */ @@ -124,16 +126,23 @@ protected void onCreate(Bundle savedInstanceState) { 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(), - creatorViewBinding.creatorThumbnail.getContext(), - viewThemeUtils)); + //for NMC we have different text and icon for Markdown(.md) menu + if (creator.getMimetype().equalsIgnoreCase(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)) { + creatorViewBinding.creatorName.setText(fileActivity.getString(R.string.create_text_document)); + creatorViewBinding.creatorThumbnail.setImageDrawable(ContextCompat.getDrawable(getContext(), + R.drawable.ic_new_txt_doc)); + } else { + 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(), + creatorViewBinding.creatorThumbnail.getContext(), + viewThemeUtils)); + } creatorView.setOnClickListener(v -> { actions.showTemplate(creator, creatorViewBinding.creatorName.getText().toString()); diff --git a/app/src/main/res/drawable/ic_new_txt_doc.xml b/app/src/main/res/drawable/ic_new_txt_doc.xml new file mode 100644 index 000000000000..2b0783479d48 --- /dev/null +++ b/app/src/main/res/drawable/ic_new_txt_doc.xml @@ -0,0 +1,34 @@ + + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 3a266a3d111e..7d96df2dd73f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -178,6 +178,7 @@ Erstellen Verzeichnis konnte nicht erstellt werden Neu erstellen + Neues Textdokument erstellen Neues Dokument erstellen Neuen Ordner erstellen Neue Präsentation erstellen diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7fc2bcfbbc2e..7bd0e82d4864 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -924,6 +924,7 @@ Resolve conflict Delete Create new + Create text document %1$s %2$s Choose what to sync