Skip to content

Commit be03c69

Browse files
committed
Open in web editor
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent f1251f0 commit be03c69

7 files changed

Lines changed: 27 additions & 9 deletions

File tree

app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,12 @@ class FileMenuFilterIT : AbstractIT() {
353353
val downloadedToHide = filterFactory
354354
.newInstance(downloadedFile, mockComponentsGetter, true, user)
355355
.getToHide(false)
356-
assertFalse(downloadedToHide.contains(R.id.action_open_with_office))
356+
assertFalse(downloadedToHide.contains(R.id.action_open_in_web_editor))
357357

358358
val onlineToHide = filterFactory
359359
.newInstance(onlineOnlyFile, mockComponentsGetter, true, user)
360360
.getToHide(false)
361-
assertTrue(onlineToHide.contains(R.id.action_open_with_office))
361+
assertTrue(onlineToHide.contains(R.id.action_open_in_web_editor))
362362
}
363363
}
364364
}

app/src/main/java/com/nextcloud/ui/fileactions/FileAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum class FileAction(
4848
SEND_SHARE_FILE(R.id.action_send_share_file, R.string.action_send_share, R.drawable.ic_share),
4949
SEND_FILE(R.id.action_send_file, R.string.common_send, R.drawable.ic_share),
5050
OPEN_FILE_WITH(R.id.action_open_file_with, R.string.actionbar_open_with, R.drawable.ic_external),
51-
OPEN_WITH_OFFICE(R.id.action_open_with_office, R.string.action_open_with_office, R.drawable.file_doc),
51+
OPEN_WITH_OFFICE(R.id.action_open_in_web_editor, R.string.action_open_in_web_editor, R.drawable.file_doc),
5252
STREAM_MEDIA(R.id.action_stream_media, R.string.stream, R.drawable.ic_play_arrow),
5353
SET_AS_WALLPAPER(R.id.action_set_as_wallpaper, R.string.set_picture_as, R.drawable.ic_wallpaper),
5454

app/src/main/java/com/owncloud/android/files/FileMenuFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,14 @@ private void filterOpenWith(Collection<Integer> toHide, boolean synchronizing) {
348348

349349
private void filterOpenWithOffice(Collection<Integer> toHide) {
350350
if (!isSingleFile()) {
351-
toHide.add(R.id.action_open_with_office);
351+
toHide.add(R.id.action_open_in_web_editor);
352352
return;
353353
}
354354

355355
OCFile file = files.iterator().next();
356356
boolean canOpenLocally = file.isDown() && !file.isEncrypted();
357357
if (!canOpenLocally || !editorUtils.isOfficeEditorAvailable(user, file.getMimeType())) {
358-
toHide.add(R.id.action_open_with_office);
358+
toHide.add(R.id.action_open_in_web_editor);
359359
}
360360
}
361361

app/src/main/java/com/owncloud/android/ui/activity/TextEditorWebView.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
package com.owncloud.android.ui.activity
1010

1111
import android.annotation.SuppressLint
12+
import android.content.Context
13+
import android.content.Intent
1214
import androidx.core.net.toUri
1315
import androidx.webkit.WebSettingsCompat
1416
import androidx.webkit.WebViewFeature
1517
import com.nextcloud.android.common.ui.util.PlatformThemeUtil
1618
import com.nextcloud.client.appinfo.AppInfo
1719
import com.nextcloud.client.device.DeviceInfo
1820
import com.owncloud.android.R
21+
import com.owncloud.android.datamodel.OCFile
1922
import com.owncloud.android.ui.asynctasks.TextEditorLoadUrlTask
2023
import com.owncloud.android.utils.DisplayUtils
2124
import javax.inject.Inject
@@ -27,6 +30,21 @@ class TextEditorWebView : EditorWebView() {
2730
@Inject
2831
lateinit var deviceInfo: DeviceInfo
2932

33+
companion object {
34+
fun startTextEditor(file: OCFile?, context: Context?) {
35+
val context = context ?: return
36+
val file = file ?: return
37+
38+
Intent(context, TextEditorWebView::class.java).apply {
39+
putExtra(EXTRA_TITLE, "Text")
40+
putExtra(EXTRA_FILE, file)
41+
putExtra(EXTRA_SHOW_SIDEBAR, false)
42+
}.also {
43+
context.startActivity(it)
44+
}
45+
}
46+
}
47+
3048
@SuppressLint("AddJavascriptInterface") // suppress warning as webview is only used > Lollipop
3149
override fun postOnCreate() {
3250
super.postOnCreate()
@@ -37,7 +55,7 @@ class TextEditorWebView : EditorWebView() {
3755
}
3856

3957
user.ifPresent {
40-
val editor = editorUtils.getEditor(it, file?.mimeType)
58+
val editor = editorUtils.getAvailableEditor(it, file?.mimeType)
4159

4260
if (editorUtils.usesOfficeUserAgent(editor)) {
4361
webView.settings.userAgentString = generateOfficeUserAgent()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ public boolean onFileActionChosen(@IdRes final int itemId, Set<OCFile> checkedFi
13551355
} else if (itemId == R.id.action_open_file_with) {
13561356
mContainerActivity.getFileOperationsHelper().openFile(singleFile);
13571357
return true;
1358-
} else if (itemId == R.id.action_open_with_office) {
1358+
} else if (itemId == R.id.action_open_in_web_editor) {
13591359
TextEditorWebView.Companion.startTextEditor(singleFile, getContext());
13601360
return true;
13611361
} else if (itemId == R.id.action_stream_media) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<item name="action_send_share_file" type="id"/>
2424
<item name="action_send_file" type="id"/>
2525
<item name="action_open_file_with" type="id"/>
26-
<item name="action_open_with_office" type="id"/>
26+
<item name="action_open_in_web_editor" type="id"/>
2727
<item name="action_sync_file" type="id"/>
2828
<item name="action_sync_all_files" type="id"/>
2929
<item name="action_cancel_sync" type="id"/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@
11941194
<string name="share_internal_link_to_file_text">Internal share link only works for users with access to this file</string>
11951195
<string name="share_internal_link">Share internal link</string>
11961196
<string name="action_edit">Edit</string>
1197-
<string name="action_open_with_office">Open with office</string>
1197+
<string name="action_open_in_web_editor">Open in web editor</string>
11981198
<string name="failed_to_start_editor">Failed to start editor</string>
11991199
<string name="create_rich_workspace">Add folder description</string>
12001200
<string name="uploader_file_not_found_on_server_message">We couldnt locate the file on server. Another user may have deleted the file</string>

0 commit comments

Comments
 (0)