Skip to content

Commit

Permalink
Collabora related customization with test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder-tsys committed Sep 25, 2024
1 parent 985d4c2 commit aab22f3
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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<String, Creator>()
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<Unit, String?> {
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()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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());
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/drawable/ic_new_txt_doc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group>
<clip-path
android:pathData="M3,1l17.9997,0l0,22l-17.9997,0z"/>
<path
android:pathData="M4.4997,20C4.4997,20.828 5.1717,21.5 5.9997,21.5L14.9997,21.5L14.9997,18.5C14.9997,17.672 15.6717,17 16.4997,17L19.4997,17L19.4997,2.5L4.4997,2.5L4.4997,20ZM5.9997,23C4.3437,23 2.9997,21.657 2.9997,20L2.9997,1L20.9997,1L20.9997,18L15.9997,23L5.9997,23Z"
android:strokeWidth="1"
android:fillColor="#262626"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
</group>
<path
android:pathData="M8.0817,14.8262C7.6757,14.8262 7.3467,14.4972 7.3467,14.0912C7.3467,13.6842 7.6757,13.3552 8.0817,13.3552L15.9187,13.3552C16.3247,13.3552 16.6537,13.6842 16.6537,14.0912C16.6537,14.4972 16.3247,14.8262 15.9187,14.8262L8.0817,14.8262Z"
android:strokeWidth="1"
android:fillColor="#262626"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
<path
android:pathData="M8.0817,11.397C7.6757,11.397 7.3467,11.068 7.3467,10.662C7.3467,10.256 7.6757,9.927 8.0817,9.927L15.9187,9.927C16.3247,9.927 16.6537,10.256 16.6537,10.662C16.6537,11.068 16.3247,11.397 15.9187,11.397L8.0817,11.397Z"
android:strokeWidth="1"
android:fillColor="#262626"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
<path
android:pathData="M8.0817,7.9678C7.6757,7.9678 7.3477,7.6388 7.3477,7.2338C7.3477,6.8278 7.6757,6.4988 8.0817,6.4988L15.9187,6.4988C16.3237,6.4988 16.6527,6.8278 16.6527,7.2338C16.6527,7.6388 16.3237,7.9678 15.9187,7.9678L8.0817,7.9678Z"
android:strokeWidth="1"
android:fillColor="#262626"
android:fillType="evenOdd"
android:strokeColor="#00000000"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
<string name="create">Erstellen</string>
<string name="create_dir_fail_msg">Verzeichnis konnte nicht erstellt werden</string>
<string name="create_new">Neu</string>
<string name="create_text_document">Neues Textdokument erstellen</string>
<string name="create_new_document">Neues Dokument</string>
<string name="create_new_folder">Neuer Ordner</string>
<string name="create_new_presentation">Neue Präsentation</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@
<string name="upload_list_resolve_conflict">Resolve conflict</string>
<string name="upload_list_delete">Delete</string>
<string name="create_new">New</string>
<string name="create_text_document">Create text document</string>
<string name="editor_placeholder" translatable="false">%1$s %2$s</string>

<string name="sync_not_enough_space_dialog_action_choose">Choose what to sync</string>
Expand Down

0 comments on commit aab22f3

Please sign in to comment.