Skip to content

Commit a3a9084

Browse files
committed
Collabora related customization with test cases.
1 parent 2e55cc5 commit a3a9084

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
@@ -44,6 +44,8 @@
4444
import com.owncloud.android.utils.theme.ThemeUtils;
4545
import com.owncloud.android.utils.theme.ViewThemeUtils;
4646

47+
import androidx.core.content.ContextCompat;
48+
4749
/**
4850
* FAB menu {@link android.app.Dialog} styled as a bottom sheet for main actions.
4951
*/
@@ -124,16 +126,23 @@ protected void onCreate(Bundle savedInstanceState) {
124126

125127
View creatorView = creatorViewBinding.getRoot();
126128

127-
creatorViewBinding.creatorName.setText(
128-
String.format(fileActivity.getString(R.string.editor_placeholder),
129-
fileActivity.getString(R.string.create_new),
130-
creator.getName()));
131-
132-
creatorViewBinding.creatorThumbnail.setImageDrawable(
133-
MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
134-
creator.getExtension(),
135-
creatorViewBinding.creatorThumbnail.getContext(),
136-
viewThemeUtils));
129+
//for NMC we have different text and icon for Markdown(.md) menu
130+
if (creator.getMimetype().equalsIgnoreCase(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)) {
131+
creatorViewBinding.creatorName.setText(fileActivity.getString(R.string.create_text_document));
132+
creatorViewBinding.creatorThumbnail.setImageDrawable(ContextCompat.getDrawable(getContext(),
133+
R.drawable.ic_new_txt_doc));
134+
} else {
135+
creatorViewBinding.creatorName.setText(
136+
String.format(fileActivity.getString(R.string.editor_placeholder),
137+
fileActivity.getString(R.string.create_new),
138+
creator.getName()));
139+
140+
creatorViewBinding.creatorThumbnail.setImageDrawable(
141+
MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
142+
creator.getExtension(),
143+
creatorViewBinding.creatorThumbnail.getContext(),
144+
viewThemeUtils));
145+
}
137146

138147
creatorView.setOnClickListener(v -> {
139148
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
@@ -181,6 +181,7 @@
181181
<string name="create">Erstellen</string>
182182
<string name="create_dir_fail_msg">Verzeichnis konnte nicht erstellt werden</string>
183183
<string name="create_new">Neu erstellen</string>
184+
<string name="create_text_document">Neues Textdokument erstellen</string>
184185
<string name="create_new_document">Neues Dokument erstellen</string>
185186
<string name="create_new_folder">Neuen Ordner erstellen</string>
186187
<string name="create_new_presentation">Neue Präsentation erstellen</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@
912912
<string name="upload_list_resolve_conflict">Resolve conflict</string>
913913
<string name="upload_list_delete">Delete</string>
914914
<string name="create_new">Create new</string>
915+
<string name="create_text_document">Create text document</string>
915916
<string name="editor_placeholder" translatable="false">%1$s %2$s</string>
916917

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

0 commit comments

Comments
 (0)