Skip to content

Commit 240f1c7

Browse files
committed
Collabora related customization with test cases.
1 parent e0cc413 commit 240f1c7

File tree

5 files changed

+168
-10
lines changed

5 files changed

+168
-10
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package com.nmc.android
2+
3+
import android.os.Looper
4+
import androidx.activity.result.contract.ActivityResultContract
5+
import androidx.test.espresso.Espresso.onView
6+
import androidx.test.espresso.assertion.ViewAssertions.matches
7+
import androidx.test.espresso.intent.rule.IntentsTestRule
8+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
9+
import androidx.test.espresso.matcher.ViewMatchers.withText
10+
import com.google.android.material.bottomsheet.BottomSheetBehavior
11+
import com.google.gson.Gson
12+
import com.nextcloud.client.device.DeviceInfo
13+
import com.nextcloud.client.documentscan.AppScanOptionalFeature
14+
import com.nextcloud.utils.EditorUtils
15+
import com.owncloud.android.AbstractIT
16+
import com.owncloud.android.datamodel.ArbitraryDataProvider
17+
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
18+
import com.owncloud.android.datamodel.OCFile
19+
import com.owncloud.android.lib.common.Creator
20+
import com.owncloud.android.lib.common.DirectEditing
21+
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
22+
import com.owncloud.android.ui.activity.FileDisplayActivity
23+
import com.owncloud.android.ui.fragment.OCFileListBottomSheetActions
24+
import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog
25+
import com.owncloud.android.utils.MimeTypeUtil
26+
import com.owncloud.android.utils.theme.CapabilityUtils
27+
import org.junit.Before
28+
import org.junit.Rule
29+
import org.junit.Test
30+
import org.mockito.Mock
31+
import org.mockito.MockitoAnnotations
32+
33+
class OCFileListBottomSheetDialogIT : AbstractIT() {
34+
35+
@Mock
36+
private lateinit var actions: OCFileListBottomSheetActions
37+
38+
@get:Rule
39+
val activityRule = IntentsTestRule(FileDisplayActivity::class.java, true, true)
40+
41+
@Before
42+
fun setUp() {
43+
MockitoAnnotations.initMocks(this)
44+
}
45+
46+
@Test
47+
fun validateCreateTextDocumentMenuOption() {
48+
if (Looper.myLooper() == null) {
49+
Looper.prepare()
50+
}
51+
52+
val info = DeviceInfo()
53+
val ocFile = OCFile("/test.md")
54+
55+
// add direct editing info
56+
val creatorMap = mutableMapOf<String, Creator>()
57+
creatorMap["1"] = Creator(
58+
"1",
59+
"md",
60+
"markdown file",
61+
".md",
62+
MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN,
63+
false
64+
)
65+
66+
val directEditing = DirectEditing(
67+
creators = creatorMap
68+
)
69+
70+
val json = Gson().toJson(directEditing)
71+
ArbitraryDataProviderImpl(targetContext).storeOrUpdateKeyValue(
72+
user.accountName,
73+
ArbitraryDataProvider.DIRECT_EDITING,
74+
json
75+
)
76+
77+
val capability = activityRule.activity.capabilities
78+
capability.richDocuments = CapabilityBooleanType.TRUE
79+
capability.richDocumentsDirectEditing = CapabilityBooleanType.TRUE
80+
capability.richDocumentsTemplatesAvailable = CapabilityBooleanType.TRUE
81+
capability.accountName = user.accountName
82+
CapabilityUtils.updateCapability(capability)
83+
84+
val appScanOptionalFeature: AppScanOptionalFeature = object : AppScanOptionalFeature() {
85+
override fun getScanContract(): ActivityResultContract<Unit, String?> {
86+
throw UnsupportedOperationException("Document scan is not available")
87+
}
88+
}
89+
90+
val editorUtils = EditorUtils(ArbitraryDataProviderImpl(targetContext))
91+
val sut = OCFileListBottomSheetDialog(
92+
activityRule.activity,
93+
actions,
94+
info,
95+
user,
96+
ocFile,
97+
activityRule.activity.themeUtils,
98+
activityRule.activity.viewThemeUtils,
99+
editorUtils,
100+
appScanOptionalFeature
101+
)
102+
103+
activityRule.activity.runOnUiThread { sut.show() }
104+
105+
waitForIdleSync()
106+
107+
sut.behavior.state = BottomSheetBehavior.STATE_EXPANDED
108+
109+
shortSleep()
110+
111+
onView(withText("Create text document")).check(matches(isCompletelyDisplayed()))
112+
}
113+
}

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListBottomSheetDialog.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.owncloud.android.utils.theme.ThemeUtils;
3232
import com.owncloud.android.utils.theme.ViewThemeUtils;
3333

34+
import androidx.core.content.ContextCompat;
35+
3436
/**
3537
* FAB menu {@link android.app.Dialog} styled as a bottom sheet for main actions.
3638
*/
@@ -111,16 +113,23 @@ protected void onCreate(Bundle savedInstanceState) {
111113

112114
View creatorView = creatorViewBinding.getRoot();
113115

114-
creatorViewBinding.creatorName.setText(
115-
String.format(fileActivity.getString(R.string.editor_placeholder),
116-
fileActivity.getString(R.string.create_new),
117-
creator.getName()));
118-
119-
creatorViewBinding.creatorThumbnail.setImageDrawable(
120-
MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
121-
creator.getExtension(),
122-
creatorViewBinding.creatorThumbnail.getContext(),
123-
viewThemeUtils));
116+
//for NMC we have different text and icon for Markdown(.md) menu
117+
if (creator.getMimetype().equalsIgnoreCase(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)) {
118+
creatorViewBinding.creatorName.setText(fileActivity.getString(R.string.create_text_document));
119+
creatorViewBinding.creatorThumbnail.setImageDrawable(ContextCompat.getDrawable(getContext(),
120+
R.drawable.ic_new_txt_doc));
121+
} else {
122+
creatorViewBinding.creatorName.setText(
123+
String.format(fileActivity.getString(R.string.editor_placeholder),
124+
fileActivity.getString(R.string.create_new),
125+
creator.getName()));
126+
127+
creatorViewBinding.creatorThumbnail.setImageDrawable(
128+
MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
129+
creator.getExtension(),
130+
creatorViewBinding.creatorThumbnail.getContext(),
131+
viewThemeUtils));
132+
}
124133

125134
creatorView.setOnClickListener(v -> {
126135
actions.showTemplate(creator, creatorViewBinding.creatorName.getText().toString());
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<group>
7+
<clip-path
8+
android:pathData="M3,1l17.9997,0l0,22l-17.9997,0z"/>
9+
<path
10+
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"
11+
android:strokeWidth="1"
12+
android:fillColor="#262626"
13+
android:fillType="evenOdd"
14+
android:strokeColor="#00000000"/>
15+
</group>
16+
<path
17+
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"
18+
android:strokeWidth="1"
19+
android:fillColor="#262626"
20+
android:fillType="evenOdd"
21+
android:strokeColor="#00000000"/>
22+
<path
23+
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"
24+
android:strokeWidth="1"
25+
android:fillColor="#262626"
26+
android:fillType="evenOdd"
27+
android:strokeColor="#00000000"/>
28+
<path
29+
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"
30+
android:strokeWidth="1"
31+
android:fillColor="#262626"
32+
android:fillType="evenOdd"
33+
android:strokeColor="#00000000"/>
34+
</vector>

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
<string name="create">Erstellen</string>
207207
<string name="create_dir_fail_msg">Verzeichnis konnte nicht erstellt werden</string>
208208
<string name="create_new">Neu</string>
209+
<string name="create_text_document">Neues Textdokument erstellen</string>
209210
<string name="create_new_document">Neues Dokument</string>
210211
<string name="create_new_folder">Neuer Ordner</string>
211212
<string name="create_new_presentation">Neue Präsentation</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@
10141014
<string name="upload_list_resolve_conflict">Resolve conflict</string>
10151015
<string name="upload_list_delete">Delete</string>
10161016
<string name="create_new">New</string>
1017+
<string name="create_text_document">Create text document</string>
10171018
<string name="editor_placeholder" translatable="false">%1$s %2$s</string>
10181019

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

0 commit comments

Comments
 (0)