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 2deb69e0537d..f27ec61ed254 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 @@ -31,6 +31,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. */ @@ -111,16 +113,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 a3630de1da2c..3f3ba0de299f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -208,6 +208,7 @@ Erstellen Verzeichnis konnte nicht erstellt werden Neu + Neues Textdokument erstellen Neues Dokument Neuer Ordner Neue Präsentation diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ef43fd179651..f663bb52ec67 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1015,6 +1015,7 @@ Resolve conflict Delete New + Create text document %1$s %2$s Choose what to sync